*/ protected NonThreadSafeValue $compressor; private string $tiles; public function __construct(int $chunkX, int $chunkZ, Chunk $chunk, CompressBatchPromise $promise, Compressor $compressor){ $this->compressor = new NonThreadSafeValue($compressor); $this->chunk = FastChunkSerializer::serializeTerrain($chunk); $this->chunkX = $chunkX; $this->chunkZ = $chunkZ; $this->tiles = ChunkSerializer::serializeTiles($chunk); $this->storeLocal(self::TLS_KEY_PROMISE, $promise); } public function onRun() : void{ $chunk = FastChunkSerializer::deserializeTerrain($this->chunk); $subCount = ChunkSerializer::getSubChunkCount($chunk); $converter = TypeConverter::getInstance(); $encoderContext = new PacketSerializerContext($converter->getItemTypeDictionary()); $payload = ChunkSerializer::serializeFullChunk($chunk, $converter->getBlockTranslator(), $encoderContext, $this->tiles); $stream = new BinaryStream(); PacketBatch::encodePackets($stream, $encoderContext, [LevelChunkPacket::create(new ChunkPosition($this->chunkX, $this->chunkZ), $subCount, false, null, $payload)]); $this->setResult($this->compressor->deserialize()->compress($stream->getBuffer())); } public function onCompletion() : void{ /** @var CompressBatchPromise $promise */ $promise = $this->fetchLocal(self::TLS_KEY_PROMISE); $promise->resolve($this->getResult()); } }