Skip to content

Commit

Permalink
ChunkRequestTask: No longer serializing the diagonal chunks, as we on…
Browse files Browse the repository at this point in the history
…ly need the direct neighbours of our chunk
  • Loading branch information
ColinHDev committed Aug 1, 2022
1 parent ac4f52e commit 8c161a7
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/ColinHDev/ActualAntiXRay/tasks/ChunkRequestTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}

Expand Down

0 comments on commit 8c161a7

Please sign in to comment.