Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Source code recreated from a .class file by IntelliJ IDEA
- // (powered by FernFlower decompiler)
- //
- package net.minecraft.world.level.chunk;
- import java.util.function.Predicate;
- import net.minecraft.core.QuartPos;
- import net.minecraft.core.Registry;
- import net.minecraft.network.FriendlyByteBuf;
- import net.minecraft.world.level.biome.Biome;
- import net.minecraft.world.level.biome.BiomeResolver;
- import net.minecraft.world.level.biome.Biomes;
- import net.minecraft.world.level.biome.Climate.Sampler;
- import net.minecraft.world.level.block.Block;
- import net.minecraft.world.level.block.Blocks;
- import net.minecraft.world.level.block.state.BlockState;
- import net.minecraft.world.level.chunk.PalettedContainer.Strategy;
- import net.minecraft.world.level.material.FluidState;
- public class LevelChunkSection {
- public static final int SECTION_WIDTH = 16;
- public static final int SECTION_HEIGHT = 16;
- public static final int SECTION_SIZE = 4096;
- public static final int BIOME_CONTAINER_BITS = 2;
- private final int bottomBlockY;
- private short nonEmptyBlockCount;
- private short tickingBlockCount;
- private short tickingFluidCount;
- private final PalettedContainer<BlockState> states;
- private final PalettedContainer<Biome> biomes;
- public LevelChunkSection(int i, PalettedContainer<BlockState> datapaletteblock, PalettedContainer<Biome> datapaletteblock1) {
- this.bottomBlockY = getBottomBlockY(i);
- this.states = datapaletteblock;
- this.biomes = datapaletteblock1;
- this.recalcBlockCounts();
- }
- public LevelChunkSection(int i, Registry<Biome> iregistry) {
- this.bottomBlockY = getBottomBlockY(i);
- this.states = new PalettedContainer(Block.BLOCK_STATE_REGISTRY, Blocks.AIR.defaultBlockState(), Strategy.SECTION_STATES);
- this.biomes = new PalettedContainer(iregistry, (Biome)iregistry.getOrThrow(Biomes.PLAINS), Strategy.SECTION_BIOMES);
- }
- public static int getBottomBlockY(int i) {
- return i << 4;
- }
- public BlockState getBlockState(int i, int j, int k) {
- return (BlockState)this.states.get(i, j, k);
- }
- public FluidState getFluidState(int i, int j, int k) {
- return ((BlockState)this.states.get(i, j, k)).getFluidState();
- }
- public void acquire() {
- this.states.acquire();
- }
- public void release() {
- this.states.release();
- }
- public BlockState setBlockState(int i, int j, int k, BlockState iblockdata) {
- return this.setBlockState(i, j, k, iblockdata, true);
- }
- public BlockState setBlockState(int i, int j, int k, BlockState iblockdata, boolean flag) {
- BlockState iblockdata1;
- if (flag) {
- iblockdata1 = (BlockState)this.states.getAndSet(i, j, k, iblockdata);
- } else {
- iblockdata1 = (BlockState)this.states.getAndSetUnchecked(i, j, k, iblockdata);
- }
- FluidState fluid = iblockdata1.getFluidState();
- FluidState fluid1 = iblockdata.getFluidState();
- if (!iblockdata1.isAir()) {
- --this.nonEmptyBlockCount;
- if (iblockdata1.isRandomlyTicking()) {
- --this.tickingBlockCount;
- }
- }
- if (!fluid.isEmpty()) {
- --this.tickingFluidCount;
- }
- if (!iblockdata.isAir()) {
- ++this.nonEmptyBlockCount;
- if (iblockdata.isRandomlyTicking()) {
- ++this.tickingBlockCount;
- }
- }
- if (!fluid1.isEmpty()) {
- ++this.tickingFluidCount;
- }
- return iblockdata1;
- }
- public boolean hasOnlyAir() {
- return this.nonEmptyBlockCount == 0;
- }
- public boolean isRandomlyTicking() {
- return this.isRandomlyTickingBlocks() || this.isRandomlyTickingFluids();
- }
- public boolean isRandomlyTickingBlocks() {
- return this.tickingBlockCount > 0;
- }
- public boolean isRandomlyTickingFluids() {
- return this.tickingFluidCount > 0;
- }
- public int bottomBlockY() {
- return this.bottomBlockY;
- }
- public void recalcBlockCounts() {
- this.nonEmptyBlockCount = 0;
- this.tickingBlockCount = 0;
- this.tickingFluidCount = 0;
- this.states.count((iblockdata, i) -> {
- FluidState fluid = iblockdata.getFluidState();
- if (!iblockdata.isAir()) {
- this.nonEmptyBlockCount = (short)(this.nonEmptyBlockCount + i);
- if (iblockdata.isRandomlyTicking()) {
- this.tickingBlockCount = (short)(this.tickingBlockCount + i);
- }
- }
- if (!fluid.isEmpty()) {
- this.nonEmptyBlockCount = (short)(this.nonEmptyBlockCount + i);
- if (fluid.isRandomlyTicking()) {
- this.tickingFluidCount = (short)(this.tickingFluidCount + i);
- }
- }
- });
- }
- public PalettedContainer<BlockState> getStates() {
- return this.states;
- }
- public PalettedContainer<Biome> getBiomes() {
- return this.biomes;
- }
- public void read(FriendlyByteBuf packetdataserializer) {
- this.nonEmptyBlockCount = packetdataserializer.readShort();
- this.states.read(packetdataserializer);
- this.biomes.read(packetdataserializer);
- }
- public void write(FriendlyByteBuf packetdataserializer) {
- packetdataserializer.writeShort(this.nonEmptyBlockCount);
- this.states.write(packetdataserializer);
- this.biomes.write(packetdataserializer);
- }
- public int getSerializedSize() {
- return 2 + this.states.getSerializedSize() + this.biomes.getSerializedSize();
- }
- public boolean maybeHas(Predicate<BlockState> predicate) {
- return this.states.maybeHas(predicate);
- }
- public Biome getNoiseBiome(int i, int j, int k) {
- return (Biome)this.biomes.get(i, j, k);
- }
- public void setBiome(int i, int j, int k, Biome biome) {
- this.biomes.set(i, j, k, biome);
- }
- public void fillBiomesFromNoise(BiomeResolver biomeresolver, Sampler climate_sampler, int i, int j) {
- PalettedContainer<Biome> datapaletteblock = this.getBiomes();
- datapaletteblock.acquire();
- try {
- int k = QuartPos.fromBlock(this.bottomBlockY());
- boolean flag = true;
- for(int l = 0; l < 4; ++l) {
- for(int i1 = 0; i1 < 4; ++i1) {
- for(int j1 = 0; j1 < 4; ++j1) {
- datapaletteblock.getAndSetUnchecked(l, i1, j1, biomeresolver.getNoiseBiome(i + l, k + i1, j + j1, climate_sampler));
- }
- }
- }
- } finally {
- datapaletteblock.release();
- }
- }
- }
Add Comment
Please, Sign In to add comment