public function requestChunkTask($x, $z) { $chunk = $this->getChunk($x, $z, false); if (!$chunk instanceof Chunk) { throw new ChunkException("Invalid Chunk sent"); } $tiles = ""; if (count($chunk->getTiles()) > 0) { $nbt = new NBT(NBT::LITTLE_ENDIAN); $list = []; foreach ($chunk->getTiles() as $tile) { if ($tile instanceof Spawnable) { $list[] = $tile->getSpawnCompound(); } } $nbt->setData($list); $tiles = $nbt->write(true); } $extraData = new BinaryStream(); $extraData->putLInt(count($chunk->getBlockExtraDataArray())); foreach ($chunk->getBlockExtraDataArray() as $key => $value) { $extraData->putLInt($key); $extraData->putLShort($value); } $ordered = $chunk->getBlockIdArray() . $chunk->getBlockDataArray() . $chunk->getBlockSkyLightArray() . $chunk->getBlockLightArray() . pack("C*", ...$chunk->getHeightMapArray()) . pack("N*", ...$chunk->getBiomeColorArray()) . $extraData->getBuffer() . $tiles; $this->getLevel()->chunkRequestCallback($x, $z, $ordered, FullChunkDataPacket::ORDER_LAYERED); return null; }
public function onRun() { $chunk = Chunk::fromFastBinary($this->chunk); $extraData = new BinaryStream(); $extraData->putLInt(count($chunk->getBlockExtraDataArray())); foreach ($chunk->getBlockExtraDataArray() as $key => $value) { $extraData->putLInt($key); $extraData->putLShort($value); } $ordered = $chunk->getBlockIdArray() . $chunk->getBlockDataArray() . $chunk->getBlockSkyLightArray() . $chunk->getBlockLightArray() . pack("C*", ...$chunk->getHeightMapArray()) . pack("N*", ...$chunk->getBiomeColorArray()) . $extraData->getBuffer() . $this->tiles; $this->setResult($ordered, false); }
/** * Writes a coded metadata string * * @param array $data * * @return string */ public static function writeMetadata(array $data) { $stream = new BinaryStream(); $stream->putUnsignedVarInt(count($data)); foreach ($data as $key => $d) { $stream->putUnsignedVarInt($key); //data key $stream->putUnsignedVarInt($d[0]); //data type switch ($d[0]) { case Entity::DATA_TYPE_BYTE: $stream->putByte($d[1]); break; case Entity::DATA_TYPE_SHORT: $stream->putLShort($d[1]); //SIGNED short! break; case Entity::DATA_TYPE_INT: $stream->putVarInt($d[1]); break; case Entity::DATA_TYPE_FLOAT: $stream->putLFloat($d[1]); break; case Entity::DATA_TYPE_STRING: $stream->putString($d[1]); break; case Entity::DATA_TYPE_SLOT: //TODO: change this implementation (use objects) $stream->putSlot(Item::get($d[1][0], $d[1][2], $d[1][1])); //ID, damage, count break; case Entity::DATA_TYPE_POS: //TODO: change this implementation (use objects) $stream->putBlockCoords($d[1][0], $d[1][1], $d[1][2]); //x, y, z break; case Entity::DATA_TYPE_LONG: $stream->putVarInt($d[1]); //TODO: varint64 support break; case Entity::DATA_TYPE_VECTOR3F: //TODO: change this implementation (use objects) $stream->putVector3f($d[1][0], $d[1][1], $d[1][2]); //x, y, z } } return $stream->getBuffer(); }
public function requestChunkTask($x, $z) { $chunk = $this->getChunk($x, $z, \false); if (!$chunk instanceof Chunk) { throw new ChunkException("Invalid Chunk sent"); } $tiles = ""; $nbt = new NBT(NBT::LITTLE_ENDIAN); foreach ($chunk->getTiles() as $tile) { if ($tile instanceof Spawnable) { $nbt->setData($tile->getSpawnCompound()); $tiles .= $nbt->write(); } } $heightmap = \pack("C*", ...$chunk->getHeightMapArray()); $biomeColors = \pack("N*", ...$chunk->getBiomeColorArray()); $extraData = new BinaryStream(); $extraData->putLInt(\count($chunk->getBlockExtraDataArray())); foreach ($chunk->getBlockExtraDataArray() as $key => $value) { $extraData->putLInt($key); $extraData->putLShort($value); } $ordered = $chunk->getBlockIdArray() . $chunk->getBlockDataArray() . $chunk->getBlockSkyLightArray() . $chunk->getBlockLightArray() . $heightmap . $biomeColors . $extraData->getBuffer() . $tiles; $this->getLevel()->chunkRequestCallback($x, $z, $ordered); return \null; }
public function requestChunkTask($x, $z) { $chunk = $this->getChunk($x, $z, false); if (!$chunk instanceof Chunk) { throw new ChunkException("Invalid Chunk sent"); } $tiles = ""; $nbt = new NBT(NBT::LITTLE_ENDIAN); foreach ($chunk->getTiles() as $tile) { if ($tile instanceof Spawnable) { $nbt->setData($tile->getSpawnCompound()); $tiles .= $nbt->write(); } } $extraData = new BinaryStream(); $extraData->putLInt(count($chunk->getBlockExtraDataArray())); foreach ($chunk->getBlockExtraDataArray() as $key => $value) { $extraData->putLInt($key); $extraData->putLShort($value); } $ordered = $chunk->getBlockIdArray() . $chunk->getBlockDataArray() . $chunk->getBlockSkyLightArray() . $chunk->getBlockLightArray() . pack("C*", ...$chunk->getHeightMapArray()) . pack("N*", ...$chunk->getBiomeColorArray()) . $extraData->getBuffer() . $tiles; $pk = new FullChunkDataPacket(); $pk->chunkX = $x; $pk->chunkZ = $z; $pk->order = FullChunkDataPacket::ORDER_COLUMNS; $pk->data = $ordered; $pk->encode(); $str = ""; $str .= Binary::writeInt(strlen($pk->buffer)) . $pk->buffer; $this->getLevel()->chunkRequestCallback($x, $z, zlib_encode($str, ZLIB_ENCODING_DEFLATE, 7)); return null; }