[Network]ChunkSerializer: allow injecting RuntimeBlockMapping

this will allow the same serializer to be reused with different mapping tables (will be needed for multi version).
This commit is contained in:
Dylan K. Taylor 2020-05-04 12:14:27 +01:00
parent 53a33e8c20
commit c2857a91bd
2 changed files with 3 additions and 3 deletions

View File

@ -25,6 +25,7 @@ namespace pocketmine\network\mcpe;
use pocketmine\network\mcpe\compression\CompressBatchPromise;
use pocketmine\network\mcpe\compression\Compressor;
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
use pocketmine\network\mcpe\protocol\LevelChunkPacket;
use pocketmine\network\mcpe\protocol\serializer\PacketBatch;
use pocketmine\network\mcpe\serializer\ChunkSerializer;
@ -67,7 +68,7 @@ class ChunkRequestTask extends AsyncTask{
public function onRun() : void{
$chunk = FastChunkSerializer::deserialize($this->chunk);
$subCount = ChunkSerializer::getSubChunkCount($chunk);
$payload = ChunkSerializer::serialize($chunk, $this->tiles);
$payload = ChunkSerializer::serialize($chunk, RuntimeBlockMapping::getInstance(), $this->tiles);
$this->setResult($this->compressor->compress(PacketBatch::fromPackets(LevelChunkPacket::withoutCache($this->chunkX, $this->chunkZ, $subCount, $payload))->getBuffer()));
}

View File

@ -51,10 +51,9 @@ final class ChunkSerializer{
return 0;
}
public static function serialize(Chunk $chunk, ?string $tiles = null) : string{
public static function serialize(Chunk $chunk, RuntimeBlockMapping $blockMapper, ?string $tiles = null) : string{
$stream = new NetworkBinaryStream();
$subChunkCount = self::getSubChunkCount($chunk);
$blockMapper = RuntimeBlockMapping::getInstance();
for($y = 0; $y < $subChunkCount; ++$y){
$layers = $chunk->getSubChunk($y)->getBlockLayers();
$stream->putByte(8); //version