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

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

public __construct ( $level, CompoundTag $nbt = null )
$nbt pocketmine\nbt\tag\CompoundTag
    public function __construct($level, CompoundTag $nbt = null)
    {
        if ($nbt === null) {
            $this->provider = $level;
            $this->nbt = new CompoundTag("Level", []);
            return;
        }
        $this->nbt = $nbt;
        if (!isset($this->nbt->Entities) or !$this->nbt->Entities instanceof ListTag) {
            $this->nbt->Entities = new ListTag("Entities", []);
            $this->nbt->Entities->setTagType(NBT::TAG_Compound);
        }
        if (!isset($this->nbt->TileEntities) or !$this->nbt->TileEntities instanceof ListTag) {
            $this->nbt->TileEntities = new ListTag("TileEntities", []);
            $this->nbt->TileEntities->setTagType(NBT::TAG_Compound);
        }
        if (!isset($this->nbt->TileTicks) or !$this->nbt->TileTicks instanceof ListTag) {
            $this->nbt->TileTicks = new ListTag("TileTicks", []);
            $this->nbt->TileTicks->setTagType(NBT::TAG_Compound);
        }
        if (!isset($this->nbt->Sections) or !$this->nbt->Sections instanceof ListTag) {
            $this->nbt->Sections = new ListTag("Sections", []);
            $this->nbt->Sections->setTagType(NBT::TAG_Compound);
        }
        if (!isset($this->nbt->BiomeColors) or !$this->nbt->BiomeColors instanceof IntArrayTag) {
            $this->nbt->BiomeColors = new IntArrayTag("BiomeColors", array_fill(0, 256, 0));
        }
        if (!isset($this->nbt->HeightMap) or !$this->nbt->HeightMap instanceof IntArrayTag) {
            $this->nbt->HeightMap = new IntArrayTag("HeightMap", array_fill(0, 256, 0));
        }
        $sections = [];
        foreach ($this->nbt->Sections as $section) {
            if ($section instanceof CompoundTag) {
                $y = (int) $section["Y"];
                if ($y < 8) {
                    $sections[$y] = new ChunkSection($section);
                }
            }
        }
        for ($y = 0; $y < 8; ++$y) {
            if (!isset($sections[$y])) {
                $sections[$y] = new EmptyChunkSection($y);
            }
        }
        $extraData = [];
        if (!isset($this->nbt->ExtraData) or !$this->nbt->ExtraData instanceof ByteArrayTag) {
            $this->nbt->ExtraData = new ByteArrayTag("ExtraData", Binary::writeInt(0));
        } else {
            $stream = new BinaryStream($this->nbt->ExtraData->getValue());
            $count = $stream->getInt();
            for ($i = 0; $i < $count; ++$i) {
                $key = $stream->getInt();
                $extraData[$key] = $stream->getShort();
            }
        }
        parent::__construct($level, (int) $this->nbt["xPos"], (int) $this->nbt["zPos"], $sections, $this->nbt->BiomeColors->getValue(), $this->nbt->HeightMap->getValue(), $this->nbt->Entities->getValue(), $this->nbt->TileEntities->getValue());
        if (isset($this->nbt->Biomes)) {
            $this->checkOldBiomes($this->nbt->Biomes->getValue());
            unset($this->nbt->Biomes);
        }
        unset($this->nbt->Sections, $this->nbt->ExtraData);
    }