154 lines
5.0 KiB
Java
154 lines
5.0 KiB
Java
package net.minecraft.world.level.chunk;
|
|
|
|
import net.minecraft.network.FriendlyByteBuf;
|
|
import javax.annotation.Nullable;
|
|
import net.minecraft.world.level.material.FluidState;
|
|
import net.minecraft.world.level.block.Blocks;
|
|
import net.minecraft.nbt.NbtUtils;
|
|
import net.minecraft.world.level.block.Block;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
|
|
public class LevelChunkSection {
|
|
private static final Palette<BlockState> GLOBAL_BLOCKSTATE_PALETTE;
|
|
private final int bottomBlockY;
|
|
private short nonEmptyBlockCount;
|
|
private short tickingBlockCount;
|
|
private short tickingFluidCount;
|
|
private final PalettedContainer<BlockState> states;
|
|
|
|
public LevelChunkSection(final int integer) {
|
|
this(integer, (short)0, (short)0, (short)0);
|
|
}
|
|
|
|
public LevelChunkSection(final int integer, final short short2, final short short3, final short short4) {
|
|
this.bottomBlockY = integer;
|
|
this.nonEmptyBlockCount = short2;
|
|
this.tickingBlockCount = short3;
|
|
this.tickingFluidCount = short4;
|
|
this.states = new PalettedContainer<BlockState>(LevelChunkSection.GLOBAL_BLOCKSTATE_PALETTE, Block.BLOCK_STATE_REGISTRY, NbtUtils::readBlockState, NbtUtils::writeBlockState, Blocks.AIR.defaultBlockState());
|
|
}
|
|
|
|
public BlockState getBlockState(final int integer1, final int integer2, final int integer3) {
|
|
return this.states.get(integer1, integer2, integer3);
|
|
}
|
|
|
|
public FluidState getFluidState(final int integer1, final int integer2, final int integer3) {
|
|
return this.states.get(integer1, integer2, integer3).getFluidState();
|
|
}
|
|
|
|
public void acquire() {
|
|
this.states.acquire();
|
|
}
|
|
|
|
public void release() {
|
|
this.states.release();
|
|
}
|
|
|
|
public BlockState setBlockState(final int integer1, final int integer2, final int integer3, final BlockState byg) {
|
|
return this.setBlockState(integer1, integer2, integer3, byg, true);
|
|
}
|
|
|
|
public BlockState setBlockState(final int integer1, final int integer2, final int integer3, final BlockState byg, final boolean boolean5) {
|
|
BlockState byg2;
|
|
if (boolean5) {
|
|
byg2 = this.states.getAndSet(integer1, integer2, integer3, byg);
|
|
}
|
|
else {
|
|
byg2 = this.states.getAndSetUnchecked(integer1, integer2, integer3, byg);
|
|
}
|
|
final FluidState cog8 = byg2.getFluidState();
|
|
final FluidState cog9 = byg.getFluidState();
|
|
if (!byg2.isAir()) {
|
|
--this.nonEmptyBlockCount;
|
|
if (byg2.isRandomlyTicking()) {
|
|
--this.tickingBlockCount;
|
|
}
|
|
}
|
|
if (!cog8.isEmpty()) {
|
|
--this.tickingFluidCount;
|
|
}
|
|
if (!byg.isAir()) {
|
|
++this.nonEmptyBlockCount;
|
|
if (byg.isRandomlyTicking()) {
|
|
++this.tickingBlockCount;
|
|
}
|
|
}
|
|
if (!cog9.isEmpty()) {
|
|
++this.tickingFluidCount;
|
|
}
|
|
return byg2;
|
|
}
|
|
|
|
public boolean isEmpty() {
|
|
return this.nonEmptyBlockCount == 0;
|
|
}
|
|
|
|
public static boolean isEmpty(@Nullable final LevelChunkSection caj) {
|
|
return caj == LevelChunk.EMPTY_SECTION || caj.isEmpty();
|
|
}
|
|
|
|
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;
|
|
final FluidState cog4;
|
|
this.states.count((byg, integer) -> {
|
|
cog4 = byg.getFluidState();
|
|
if (!byg.isAir()) {
|
|
this.nonEmptyBlockCount += integer;
|
|
if (byg.isRandomlyTicking()) {
|
|
this.tickingBlockCount += integer;
|
|
}
|
|
}
|
|
if (!cog4.isEmpty()) {
|
|
this.nonEmptyBlockCount += integer;
|
|
if (cog4.isRandomlyTicking()) {
|
|
this.tickingFluidCount += integer;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
public PalettedContainer<BlockState> getStates() {
|
|
return this.states;
|
|
}
|
|
|
|
public void read(final FriendlyByteBuf kv) {
|
|
this.nonEmptyBlockCount = kv.readShort();
|
|
this.states.read(kv);
|
|
}
|
|
|
|
public void write(final FriendlyByteBuf kv) {
|
|
kv.writeShort(this.nonEmptyBlockCount);
|
|
this.states.write(kv);
|
|
}
|
|
|
|
public int getSerializedSize() {
|
|
return 2 + this.states.getSerializedSize();
|
|
}
|
|
|
|
public boolean maybeHas(final BlockState byg) {
|
|
return this.states.maybeHas(byg);
|
|
}
|
|
|
|
static {
|
|
GLOBAL_BLOCKSTATE_PALETTE = new GlobalPalette<BlockState>(Block.BLOCK_STATE_REGISTRY, Blocks.AIR.defaultBlockState());
|
|
}
|
|
}
|