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) and $this->nbt->Entities instanceof ListTag) {
$this->nbt->Entities->setTagType(NBT::TAG_Compound);
} else {
$this->nbt->Entities = new ListTag("Entities", []);
// $this->nbt->Entities->setTagType(NBT::TAG_Compound);
}
if (isset($this->nbt->TileEntities) and $this->nbt->TileEntities instanceof ListTag) {
$this->nbt->TileEntities->setTagType(NBT::TAG_Compound);
} else {
$this->nbt->TileEntities = new ListTag("TileEntities", []);
$this->nbt->TileEntities->setTagType(NBT::TAG_Compound);
}
if (isset($this->nbt->TileTicks) and $this->nbt->TileTicks instanceof ListTag) {
$this->nbt->TileTicks->setTagType(NBT::TAG_Compound);
} else {
$this->nbt->TileTicks = new ListTag("TileTicks", []);
$this->nbt->TileTicks->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));
}
if (!isset($this->nbt->Blocks)) {
$this->nbt->Blocks = new ByteArrayTag("Blocks", str_repeat("", 32768));
}
if (!isset($this->nbt->Data)) {
$this->nbt->Data = new ByteArrayTag("Data", $half = str_repeat("", 16384));
$this->nbt->SkyLight = new ByteArrayTag("SkyLight", $half);
$this->nbt->BlockLight = new ByteArrayTag("BlockLight", $half);
}
$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(false);
}
}
parent::__construct($level, $this->nbt["xPos"], $this->nbt["zPos"], $this->nbt->Blocks->getValue(), $this->nbt->Data->getValue(), $this->nbt->SkyLight->getValue(), $this->nbt->BlockLight->getValue(), $this->nbt->BiomeColors->getValue(), $this->nbt->HeightMap->getValue(), $this->nbt->Entities->getValue(), $this->nbt->TileEntities->getValue(), $extraData);
if (isset($this->nbt->Biomes)) {
$this->checkOldBiomes($this->nbt->Biomes->getValue());
unset($this->nbt->Biomes);
}
unset($this->nbt->Blocks);
unset($this->nbt->Data);
unset($this->nbt->SkyLight);
unset($this->nbt->BlockLight);
unset($this->nbt->BiomeColors);
unset($this->nbt->HeightMap);
unset($this->nbt->Biomes);
}