pocketmine\level\format\anvil\Chunk::toFastBinary PHP Метод

toFastBinary() публичный Метод

public toFastBinary ( )
    public function toFastBinary()
    {
        $nbt = clone $this->getNBT();
        $nbt->xPos = new IntTag("xPos", $this->x);
        $nbt->zPos = new IntTag("zPos", $this->z);
        $nbt->Sections = new ListTag("Sections", []);
        $nbt->Sections->setTagType(NBT::TAG_Compound);
        foreach ($this->getSections() as $section) {
            if ($section instanceof EmptyChunkSection) {
                continue;
            }
            $nbt->Sections[$section->getY()] = new CompoundTag(null, ["Y" => new ByteTag("Y", $section->getY()), "Blocks" => new ByteArrayTag("Blocks", $section->getIdArray()), "Data" => new ByteArrayTag("Data", $section->getDataArray()), "BlockLight" => new ByteArrayTag("BlockLight", $section->getLightArray()), "SkyLight" => new ByteArrayTag("SkyLight", $section->getSkyLightArray())]);
        }
        $nbt->BiomeColors = new IntArrayTag("BiomeColors", $this->getBiomeColorArray());
        $nbt->HeightMap = new IntArrayTag("HeightMap", $this->getHeightMapArray());
        $entities = [];
        foreach ($this->getEntities() as $entity) {
            if (!$entity instanceof Player and !$entity->closed) {
                $entity->saveNBT();
                $entities[] = $entity->namedtag;
            }
        }
        $nbt->Entities = new ListTag("Entities", $entities);
        $nbt->Entities->setTagType(NBT::TAG_Compound);
        $tiles = [];
        foreach ($this->getTiles() as $tile) {
            $tile->saveNBT();
            $tiles[] = $tile->namedtag;
        }
        $nbt->TileEntities = new ListTag("TileEntities", $tiles);
        $nbt->TileEntities->setTagType(NBT::TAG_Compound);
        $extraData = new BinaryStream();
        $extraData->putInt(count($this->getBlockExtraDataArray()));
        foreach ($this->getBlockExtraDataArray() as $key => $value) {
            $extraData->putInt($key);
            $extraData->putShort($value);
        }
        $nbt->ExtraData = new ByteArrayTag("ExtraData", $extraData->getBuffer());
        $writer = new NBT(NBT::BIG_ENDIAN);
        $nbt->setName("Level");
        $writer->setData(new CompoundTag("", ["Level" => $nbt]));
        return $writer->write();
    }

Usage Example

Пример #1
0
 public function __construct(Level $level, Chunk $chunk)
 {
     $this->levelId = $level->getId();
     $this->chunk = $chunk->toFastBinary();
     $this->chunkX = $chunk->getX();
     $this->chunkZ = $chunk->getZ();
     $tiles = "";
     $nbt = new NBT(NBT::LITTLE_ENDIAN);
     foreach ($chunk->getTiles() as $tile) {
         if ($tile instanceof Spawnable) {
             $nbt->setData($tile->getSpawnCompound());
             $tiles .= $nbt->write(true);
         }
     }
     $this->tiles = $tiles;
 }