compressor = $compressor; $this->chunk = FastChunkSerializer::serializeTerrain($chunk); $this->chunkX = $chunkX; $this->chunkZ = $chunkZ; $this->tiles = ChunkSerializer::serializeTiles($chunk); $this->storeLocal(self::TLS_KEY_PROMISE, $promise); $this->storeLocal(self::TLS_KEY_ERROR_HOOK, $onError); } public function onRun() : void{ $chunk = FastChunkSerializer::deserializeTerrain($this->chunk); $subCount = ChunkSerializer::getSubChunkCount($chunk) + ChunkSerializer::LOWER_PADDING_SIZE; $encoderContext = new PacketSerializerContext(GlobalItemTypeDictionary::getInstance()->getDictionary()); $payload = ChunkSerializer::serializeFullChunk($chunk, RuntimeBlockMapping::getInstance(), $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->compress($stream->getBuffer())); } public function onError() : void{ /** * @var \Closure|null $hook * @phpstan-var (\Closure() : void)|null $hook */ $hook = $this->fetchLocal(self::TLS_KEY_ERROR_HOOK); if($hook !== null){ $hook(); } } public function onCompletion() : void{ /** @var CompressBatchPromise $promise */ $promise = $this->fetchLocal(self::TLS_KEY_PROMISE); $promise->resolve($this->getResult()); } }