levelId = $levelId; $this->chunkX = $chunkX; $this->chunkZ = $chunkZ; $chunk = $level->getChunk($chunkX, $chunkZ, true); $this->blocks = $chunk->getBlockIdArray(); $this->data = $chunk->getBlockDataArray(); $this->skyLight = $chunk->getBlockSkyLightArray(); $this->blockLight = $chunk->getBlockLightArray(); $this->biomeIds = $chunk->getBiomeIdArray(); $this->biomeColors = $chunk->getBiomeColorArray(); $tiles = ""; $nbt = new NBT(NBT::LITTLE_ENDIAN); foreach($chunk->getTiles() as $tile){ if($tile instanceof Spawnable){ $nbt->setData($tile->getSpawnCompound()); $tiles .= $nbt->write(); } } $this->tiles = $tiles; $this->compressionLevel = Level::$COMPRESSION_LEVEL; } public function onRun(){ $biomeColors = ""; foreach($this->biomeColors as $color){ $biomeColors .= Binary::writeInt($color); } $ordered = zlib_encode(Binary::writeLInt($this->chunkX) . Binary::writeLInt($this->chunkZ) . $this->blocks . $this->data . $this->skyLight . $this->blockLight . $this->biomeIds . $biomeColors . $this->tiles, ZLIB_ENCODING_DEFLATE, $this->compressionLevel); $this->setResult($ordered); } public function getColumn(&$data, $x, $z){ $i = ($z << 4) + $x; $column = ""; for($y = 0; $y < 128; ++$y){ $column .= $data{($y << 8) + $i}; } return $column; } public function getHalfColumn(&$data, $x, $z){ $i = ($z << 3) + ($x >> 1); $column = ""; if(($x & 1) === 0){ for($y = 0; $y < 128; $y += 2){ $column .= ($data{($y << 7) + $i} & "\x0f") | chr((ord($data{(($y + 1) << 7) + $i}) & 0x0f) << 4); } }else{ for($y = 0; $y < 128; $y += 2){ $column .= chr((ord($data{($y << 7) + $i}) & 0xf0) >> 4) | ($data{(($y + 1) << 7) + $i} & "\xf0"); } } return $column; } public function onCompletion(Server $server){ $level = $server->getLevel($this->levelId); if($level instanceof Level and $this->hasResult()){ $level->chunkRequestCallback($this->chunkX, $this->chunkZ, $this->getResult()); } } }