diff --git a/src/network/mcpe/serializer/ChunkSerializer.php b/src/network/mcpe/serializer/ChunkSerializer.php index 855bcd24e..62b50eab2 100644 --- a/src/network/mcpe/serializer/ChunkSerializer.php +++ b/src/network/mcpe/serializer/ChunkSerializer.php @@ -112,13 +112,13 @@ final class ChunkSerializer{ } public static function serializeSubChunk(SubChunk $subChunk, BlockTranslator $blockTranslator, PacketSerializer $stream, bool $persistentBlockStates) : void{ - // Create array from the new methods to minimize code changes + // Create array from non-empty layers $layers = []; - if(($blockLayer = $subChunk->getBlockLayer()) !== null){ - $layers[] = $blockLayer; + if(!$subChunk->isBlockLayerEmpty()){ + $layers[] = $subChunk->getBlockLayer(); } - if(($liquidLayer = $subChunk->getLiquidLayer()) !== null){ - $layers[] = $liquidLayer; + if(!$subChunk->isLiquidLayerEmpty()){ + $layers[] = $subChunk->getLiquidLayer(); } $stream->putByte(8); //version diff --git a/src/world/format/SubChunk.php b/src/world/format/SubChunk.php index 510d34487..dbcf3fdd7 100644 --- a/src/world/format/SubChunk.php +++ b/src/world/format/SubChunk.php @@ -76,6 +76,20 @@ class SubChunk{ $this->liquidLayer->getBitsPerBlock() === 0 && $this->liquidLayer->get(0, 0, 0) === $this->emptyBlockId; } + /** + * Returns whether the block layer is empty (contains only empty blocks). + */ + public function isBlockLayerEmpty() : bool{ + return $this->blockLayer->getBitsPerBlock() === 0 && $this->blockLayer->get(0, 0, 0) === $this->emptyBlockId; + } + + /** + * Returns whether the liquid layer is empty (contains only empty blocks). + */ + public function isLiquidLayerEmpty() : bool{ + return $this->liquidLayer->getBitsPerBlock() === 0 && $this->liquidLayer->get(0, 0, 0) === $this->emptyBlockId; + } + /** * Returns the block used as the default. This is assumed to refer to air. * If all the blocks in a subchunk layer are equal to this block, the layer is assumed to be empty. diff --git a/src/world/format/io/leveldb/LevelDB.php b/src/world/format/io/leveldb/LevelDB.php index 86cd8594d..a82d34c28 100644 --- a/src/world/format/io/leveldb/LevelDB.php +++ b/src/world/format/io/leveldb/LevelDB.php @@ -778,8 +778,8 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{ $blockLayer = $subChunk->getBlockLayer(); $liquidLayer = $subChunk->getLiquidLayer(); - $isBlockLayerEmpty = $blockLayer->getBitsPerBlock() === 0 && $blockLayer->get(0, 0, 0) === $subChunk->getEmptyBlockId(); - $isLiquidLayerEmpty = $liquidLayer->getBitsPerBlock() === 0 && $liquidLayer->get(0, 0, 0) === $subChunk->getEmptyBlockId(); + $isBlockLayerEmpty = $subChunk->isBlockLayerEmpty(); + $isLiquidLayerEmpty = $subChunk->isLiquidLayerEmpty(); $layerCount = 0; if(!$isBlockLayerEmpty) $layerCount++;