From 8c161a79379a4e8efbc5b0e54912e358471c1b67 Mon Sep 17 00:00:00 2001 From: ColinHDev Date: Mon, 1 Aug 2022 11:12:25 +0200 Subject: [PATCH] ChunkRequestTask: No longer serializing the diagonal chunks, as we only need the direct neighbours of our chunk --- .../ActualAntiXRay/tasks/ChunkRequestTask.php | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/ColinHDev/ActualAntiXRay/tasks/ChunkRequestTask.php b/src/ColinHDev/ActualAntiXRay/tasks/ChunkRequestTask.php index 4f50fc0..882af04 100644 --- a/src/ColinHDev/ActualAntiXRay/tasks/ChunkRequestTask.php +++ b/src/ColinHDev/ActualAntiXRay/tasks/ChunkRequestTask.php @@ -16,6 +16,7 @@ use pocketmine\network\mcpe\protocol\serializer\PacketSerializerContext; use pocketmine\network\mcpe\serializer\ChunkSerializer; use pocketmine\utils\AssumptionFailedError; +use pocketmine\world\ChunkLoader; use pocketmine\world\format\Chunk; use pocketmine\world\format\io\FastChunkSerializer; use pocketmine\world\format\SubChunk; @@ -68,10 +69,26 @@ public function __construct(World $world, int $chunkX, int $chunkZ, Chunk $chunk $this->subChunkCount = ChunkSerializer::getSubChunkCount($chunk); $this->tiles = ChunkSerializer::serializeTiles($chunk); + $adjacentChunks = []; + for ($x = -1; $x <= 1; $x++) { + for ($z = -1; $z <= 1; $z++) { + if ($x === 0 || $z === 0) { + if ($x === 0 && $z === 0) { + continue; + } + $cx = $chunkX + $x; + $cz = $chunkZ + $z; + $temporaryChunkLoader = new class implements ChunkLoader{}; + $world->registerChunkLoader($temporaryChunkLoader, $cx, $cz); + $adjacentChunks[World::chunkHash($x, $z)] = $world->loadChunk($cx, $cz); + $world->unregisterChunkLoader($temporaryChunkLoader, $cx, $cz); + } + } + } $this->adjacentChunks = igbinary_serialize( array_map( - fn (?Chunk $c) => $c !== null ? FastChunkSerializer::serializeTerrain($c) : null, - $world->getAdjacentChunks($chunkX, $chunkZ) + static fn(?Chunk $c) => $c !== null ? FastChunkSerializer::serializeTerrain($c) : null, + $adjacentChunks )) ?? throw new AssumptionFailedError("igbinary_serialize() returned null"); }