public function __construct($level, Compound $nbt = null) { if ($nbt === null) { $this->provider = $level; $this->nbt = new Compound("Level", []); return; } $this->nbt = $nbt; if (isset($this->nbt->Entities) and $this->nbt->Entities instanceof Enum) { $this->nbt->Entities->setTagType(NBT::TAG_Compound); } else { $this->nbt->Entities = new Enum("Entities", []); $this->nbt->Entities->setTagType(NBT::TAG_Compound); } if (isset($this->nbt->TileEntities) and $this->nbt->TileEntities instanceof Enum) { $this->nbt->TileEntities->setTagType(NBT::TAG_Compound); } else { $this->nbt->TileEntities = new Enum("TileEntities", []); $this->nbt->TileEntities->setTagType(NBT::TAG_Compound); } if (isset($this->nbt->TileTicks) and $this->nbt->TileTicks instanceof Enum) { $this->nbt->TileTicks->setTagType(NBT::TAG_Compound); } else { $this->nbt->TileTicks = new Enum("TileTicks", []); $this->nbt->TileTicks->setTagType(NBT::TAG_Compound); } if (!isset($this->nbt->BiomeColors) or !$this->nbt->BiomeColors instanceof IntArray) { $this->nbt->BiomeColors = new IntArray("BiomeColors", array_fill(0, 256, 0)); } if (!isset($this->nbt->HeightMap) or !$this->nbt->HeightMap instanceof IntArray) { $this->nbt->HeightMap = new IntArray("HeightMap", array_fill(0, 256, 0)); } if (!isset($this->nbt->Blocks)) { $this->nbt->Blocks = new ByteArray("Blocks", str_repeat("", 32768)); } if (!isset($this->nbt->Data)) { $this->nbt->Data = new ByteArray("Data", $half = str_repeat("", 16384)); $this->nbt->SkyLight = new ByteArray("SkyLight", $half); $this->nbt->BlockLight = new ByteArray("BlockLight", $half); } 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()); 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); }
public function __construct($level, Compound $nbt = null) { if ($nbt === null) { $this->nbt = new Compound("Level", []); return; } $this->nbt = $nbt; if (isset($this->nbt->Entities) and $this->nbt->Entities instanceof Enum) { $this->nbt->Entities->setTagType(NBT::TAG_Compound); } else { $this->nbt->Entities = new Enum("Entities", []); $this->nbt->Entities->setTagType(NBT::TAG_Compound); } if (isset($this->nbt->TileEntities) and $this->nbt->TileEntities instanceof Enum) { $this->nbt->TileEntities->setTagType(NBT::TAG_Compound); } else { $this->nbt->TileEntities = new Enum("TileEntities", []); $this->nbt->TileEntities->setTagType(NBT::TAG_Compound); } if (isset($this->nbt->TileTicks) and $this->nbt->TileTicks instanceof Enum) { $this->nbt->TileTicks->setTagType(NBT::TAG_Compound); } else { $this->nbt->TileTicks = new Enum("TileTicks", []); $this->nbt->TileTicks->setTagType(NBT::TAG_Compound); } if (!isset($this->nbt->BiomeColors) or !$this->nbt->BiomeColors instanceof IntArray) { $this->nbt->BiomeColors = new IntArray("BiomeColors", \array_fill(0, 256, \PHP_INT_SIZE === 8 ? \unpack("N", "…²J")[1] << 32 >> 32 : \unpack("N", "…²J")[1])); } if (!isset($this->nbt->HeightMap) or !$this->nbt->HeightMap instanceof IntArray) { $this->nbt->HeightMap = new IntArray("HeightMap", \array_fill(0, 256, 127)); } if (!isset($this->nbt->Blocks)) { $this->nbt->Blocks = new ByteArray("Blocks", \str_repeat("", 32768)); } if (!isset($this->nbt->Data)) { $this->nbt->Data = new ByteArray("Data", $half = \str_repeat("", 16384)); $this->nbt->SkyLight = new ByteArray("SkyLight", $half); $this->nbt->BlockLight = new ByteArray("BlockLight", $half); } 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()); 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); }
public function __construct($level, Compound $nbt) { $this->nbt = $nbt; if (isset($this->nbt->Entities) and $this->nbt->Entities instanceof Enum) { $this->nbt->Entities->setTagType(NBT::TAG_Compound); } else { $this->nbt->Entities = new Enum("Entities", []); $this->nbt->Entities->setTagType(NBT::TAG_Compound); } if (isset($this->nbt->TileEntities) and $this->nbt->TileEntities instanceof Enum) { $this->nbt->TileEntities->setTagType(NBT::TAG_Compound); } else { $this->nbt->TileEntities = new Enum("TileEntities", []); $this->nbt->TileEntities->setTagType(NBT::TAG_Compound); } if (isset($this->nbt->TileTicks) and $this->nbt->TileTicks instanceof Enum) { $this->nbt->TileTicks->setTagType(NBT::TAG_Compound); } else { $this->nbt->TileTicks = new Enum("TileTicks", []); $this->nbt->TileTicks->setTagType(NBT::TAG_Compound); } if (!isset($this->nbt->Biomes) or !$this->nbt->Biomes instanceof ByteArray) { $this->nbt->Biomes = new ByteArray("Biomes", str_repeat("", 256)); } if (!isset($this->nbt->BiomeColors) or !$this->nbt->BiomeColors instanceof IntArray) { $this->nbt->BiomeColors = new IntArray("BiomeColors", array_fill(0, 256, Binary::readInt("…²J"))); } if (!isset($this->nbt->HeightMap) or !$this->nbt->HeightMap instanceof IntArray) { $this->nbt->HeightMap = new IntArray("HeightMap", array_fill(0, 256, 127)); } if (!isset($this->nbt->Blocks)) { $this->nbt->Blocks = new ByteArray("Blocks", str_repeat("", 32768)); } if (!isset($this->nbt->Data)) { $this->nbt->Data = new ByteArray("Data", $half = str_repeat("", 16384)); $this->nbt->SkyLight = new ByteArray("SkyLight", $half); $this->nbt->BlockLight = new ByteArray("BlockLight", $half); } 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->Biomes->getValue(), $this->nbt->BiomeColors->getValue(), $this->nbt->HeightMap->getValue(), $this->nbt->Entities->getValue(), $this->nbt->TileEntities->getValue()); unset($this->nbt->Blocks); unset($this->nbt->Data); unset($this->nbt->SkyLight); unset($this->nbt->BlockLight); }
public function __construct($level, $chunkX, $chunkZ, $terrain, array $entityData = null, array $tileData = null) { $heightMap = array_fill(0, 256, 127); $offset = 0; $blocks = substr($terrain, $offset, 32768); $offset += 32768; $data = substr($terrain, $offset, 16384); $offset += 16384; $skyLight = substr($terrain, $offset, 16384); $offset += 16384; $blockLight = substr($terrain, $offset, 16384); $offset += 16384; $biomes = substr($terrain, $offset, 256); $offset += 256; $biomeColors = []; foreach (unpack("N*", substr($terrain, $offset, 1024)) as $c) { $biomeColors[] = $c; } $offset += 1024; parent::__construct($level, $chunkX, $chunkZ, $blocks, $data, $skyLight, $blockLight, $biomes, $biomeColors, $heightMap, $entityData === null ? [] : $entityData, $tileData === null ? [] : $tileData); }
public function __construct($level, Compound $nbt = null) { if ($nbt === null) { $this->provider = $level; $this->nbt = new Compound("Level", []); return; } $this->nbt = $nbt; if (isset($this->nbt->Entities) and $this->nbt->Entities instanceof Enum) { $this->nbt->Entities->setTagType(NBT::TAG_Compound); } else { $this->nbt->Entities = new Enum("Entities", []); $this->nbt->Entities->setTagType(NBT::TAG_Compound); } if (isset($this->nbt->TileEntities) and $this->nbt->TileEntities instanceof Enum) { $this->nbt->TileEntities->setTagType(NBT::TAG_Compound); } else { $this->nbt->TileEntities = new Enum("TileEntities", []); $this->nbt->TileEntities->setTagType(NBT::TAG_Compound); } if (isset($this->nbt->TileTicks) and $this->nbt->TileTicks instanceof Enum) { $this->nbt->TileTicks->setTagType(NBT::TAG_Compound); } else { $this->nbt->TileTicks = new Enum("TileTicks", []); $this->nbt->TileTicks->setTagType(NBT::TAG_Compound); } if (!isset($this->nbt->BiomeColors) or !$this->nbt->BiomeColors instanceof IntArray) { $this->nbt->BiomeColors = new IntArray("BiomeColors", array_fill(0, 256, 0)); } if (!isset($this->nbt->HeightMap) or !$this->nbt->HeightMap instanceof IntArray) { $this->nbt->HeightMap = new IntArray("HeightMap", array_fill(0, 256, 0)); } if (!isset($this->nbt->Blocks)) { $this->nbt->Blocks = new ByteArray("Blocks", str_repeat("", 32768)); } if (!isset($this->nbt->Data)) { $this->nbt->Data = new ByteArray("Data", $half = str_repeat("", 16384)); $this->nbt->SkyLight = new ByteArray("SkyLight", $half); $this->nbt->BlockLight = new ByteArray("BlockLight", $half); } $extraData = []; if (!isset($this->nbt->ExtraData) or !$this->nbt->ExtraData instanceof ByteArray) { $this->nbt->ExtraData = new ByteArray("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()); 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); }