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

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

public toBinary ( )
    public function toBinary()
    {
        $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->writeCompressed(ZLIB_ENCODING_DEFLATE, RegionLoader::$COMPRESSION_LEVEL);
    }