From 0a7d81a2b0e01dfe8507c471d8810d5bb8065611 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 27 Nov 2020 13:41:35 +0000 Subject: [PATCH] FastChunkSerializer: retain emptyBlock on subchunks I think we should probably get rid of this considering the potential for inconsistencies within a chunk, but not retaining this is a bug nonetheless, even though it doesn't have any effect in PM itself since we always use BlockLegacyIds << 4 as the empty block ID. so, this is only really aiding (ab)use cases which weren't intended anyway ... --- src/world/format/SubChunk.php | 6 ++++++ src/world/format/io/FastChunkSerializer.php | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/world/format/SubChunk.php b/src/world/format/SubChunk.php index c461f1b70..e784aa650 100644 --- a/src/world/format/SubChunk.php +++ b/src/world/format/SubChunk.php @@ -69,6 +69,12 @@ class SubChunk{ return count($this->blockLayers) === 0; } + /** + * 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. + */ + public function getEmptyBlockId() : int{ return $this->emptyBlockId; } + public function getFullBlock(int $x, int $y, int $z) : int{ if(count($this->blockLayers) === 0){ return $this->emptyBlockId; diff --git a/src/world/format/io/FastChunkSerializer.php b/src/world/format/io/FastChunkSerializer.php index 16883a40e..b180c75bb 100644 --- a/src/world/format/io/FastChunkSerializer.php +++ b/src/world/format/io/FastChunkSerializer.php @@ -23,7 +23,6 @@ declare(strict_types=1); namespace pocketmine\world\format\io; -use pocketmine\block\BlockLegacyIds; use pocketmine\utils\BinaryStream; use pocketmine\world\format\BiomeArray; use pocketmine\world\format\Chunk; @@ -77,6 +76,7 @@ final class FastChunkSerializer{ foreach($subChunks as $y => $subChunk){ $stream->putByte($y); + $stream->putInt($subChunk->getEmptyBlockId()); $layers = $subChunk->getBlockLayers(); $stream->putByte(count($layers)); foreach($layers as $blocks){ @@ -126,6 +126,7 @@ final class FastChunkSerializer{ $count = $stream->getByte(); for($subCount = 0; $subCount < $count; ++$subCount){ $y = $stream->getByte(); + $airBlockId = $stream->getInt(); /** @var PalettedBlockArray[] $layers */ $layers = []; @@ -137,7 +138,7 @@ final class FastChunkSerializer{ $layers[] = PalettedBlockArray::fromData($bitsPerBlock, $words, $palette); } $subChunks[$y] = new SubChunk( - BlockLegacyIds::AIR << 4, $layers, $lightPopulated ? new LightArray($stream->get(2048)) : null, $lightPopulated ? new LightArray($stream->get(2048)) : null + $airBlockId, $layers, $lightPopulated ? new LightArray($stream->get(2048)) : null, $lightPopulated ? new LightArray($stream->get(2048)) : null ); }