From baeac2eb07f60c1917d9bb3effb9fdf51690afe4 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 30 Nov 2021 22:19:28 +0000 Subject: [PATCH] Fixed tiles not being sent with chunks --- src/pocketmine/level/format/Chunk.php | 13 ++++++++++++- src/pocketmine/level/format/io/ChunkRequestTask.php | 5 ++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/level/format/Chunk.php b/src/pocketmine/level/format/Chunk.php index 2055862c6b..d20f08725c 100644 --- a/src/pocketmine/level/format/Chunk.php +++ b/src/pocketmine/level/format/Chunk.php @@ -846,7 +846,7 @@ class Chunk{ /** * Serializes the chunk for sending to players */ - public function networkSerialize() : string{ + public function networkSerialize(?string $networkSerializedTiles) : string{ $result = ""; $subChunkCount = $this->getSubChunkSendCount(); @@ -866,6 +866,17 @@ class Chunk{ $result .= chr(0); //border block array count //Border block entry format: 1 byte (4 bits X, 4 bits Z). These are however useless since they crash the regular client. + $result .= $networkSerializedTiles ?? $this->networkSerializeTiles(); + + return $result; + } + + /** + * Serializes all tiles in network format for chunk sending. This is necessary because fastSerialize() doesn't + * include tiles; they have to be encoded on the main thread. + */ + public function networkSerializeTiles() : string{ + $result = ""; foreach($this->tiles as $tile){ if($tile instanceof Spawnable){ $result .= $tile->getSerializedSpawnCompound(); diff --git a/src/pocketmine/level/format/io/ChunkRequestTask.php b/src/pocketmine/level/format/io/ChunkRequestTask.php index 9cf66ce2b1..1d54a2454d 100644 --- a/src/pocketmine/level/format/io/ChunkRequestTask.php +++ b/src/pocketmine/level/format/io/ChunkRequestTask.php @@ -39,6 +39,7 @@ class ChunkRequestTask extends AsyncTask{ /** @var string */ protected $chunk; + private string $tiles; /** @var int */ protected $chunkX; /** @var int */ @@ -52,13 +53,15 @@ class ChunkRequestTask extends AsyncTask{ $this->compressionLevel = $level->getServer()->networkCompressionLevel; $this->chunk = $chunk->fastSerialize(); + $this->tiles = $chunk->networkSerializeTiles(); + $this->chunkX = $chunkX; $this->chunkZ = $chunkZ; } public function onRun(){ $chunk = Chunk::fastDeserialize($this->chunk); - $pk = LevelChunkPacket::withoutCache($this->chunkX, $this->chunkZ, $chunk->getSubChunkSendCount() + 4, $chunk->networkSerialize()); + $pk = LevelChunkPacket::withoutCache($this->chunkX, $this->chunkZ, $chunk->getSubChunkSendCount() + 4, $chunk->networkSerialize($this->tiles)); $batch = new BatchPacket(); $batch->addPacket($pk);