public function generateChunk($x, $z)
 {
     $nbt = new Compound("Level", []);
     $nbt->xPos = new Int("xPos", $this->getX() * 32 + $x);
     $nbt->zPos = new Int("zPos", $this->getZ() * 32 + $z);
     $nbt->LastUpdate = new Long("LastUpdate", 0);
     $nbt->LightPopulated = new Byte("LightPopulated", 0);
     $nbt->TerrainPopulated = new Byte("TerrainPopulated", 0);
     $nbt->V = new Byte("V", self::VERSION);
     $nbt->InhabitedTime = new Long("InhabitedTime", 0);
     $biomes = str_repeat(Binary::writeByte(-1), 256);
     $nbt->Biomes = new ByteArray("Biomes", $biomes);
     $nbt->BiomeColors = new IntArray("BiomeColors", array_fill(0, 156, Binary::readInt("…²J")));
     $nbt->HeightMap = new IntArray("HeightMap", array_fill(0, 256, 127));
     $nbt->Sections = new Enum("Sections", []);
     $nbt->Sections->setTagType(NBT::TAG_Compound);
     $nbt->Entities = new Enum("Entities", []);
     $nbt->Entities->setTagType(NBT::TAG_Compound);
     $nbt->TileEntities = new Enum("TileEntities", []);
     $nbt->TileEntities->setTagType(NBT::TAG_Compound);
     $nbt->TileTicks = new Enum("TileTicks", []);
     $nbt->TileTicks->setTagType(NBT::TAG_Compound);
     $writer = new NBT(NBT::BIG_ENDIAN);
     $nbt->setName("Level");
     $writer->setData(new Compound("", ["Level" => $nbt]));
     $chunkData = $writer->writeCompressed(ZLIB_ENCODING_DEFLATE, RegionLoader::$COMPRESSION_LEVEL);
     $this->saveChunk($x, $z, $chunkData);
 }
Example #2
0
 public function setNamedTag(Compound $tag)
 {
     if ($tag->getCount() === 0) {
         return $this->clearNamedTag();
     }
     $this->cachedNBT = $tag;
     $this->tags = self::writeCompoundTag($tag);
     return $this;
 }
Example #3
0
 public function read(NBT $nbt)
 {
     $this->value = [];
     $this->tagType = \ord($nbt->get(1));
     $size = $nbt->endianness === 1 ? \PHP_INT_SIZE === 8 ? \unpack("N", $nbt->get(4))[1] << 32 >> 32 : \unpack("N", $nbt->get(4))[1] : (\PHP_INT_SIZE === 8 ? \unpack("V", $nbt->get(4))[1] << 32 >> 32 : \unpack("V", $nbt->get(4))[1]);
     for ($i = 0; $i < $size and !$nbt->feof(); ++$i) {
         switch ($this->tagType) {
             case NBT::TAG_Byte:
                 $tag = new Byte("");
                 $tag->read($nbt);
                 $this->{$i} = $tag;
                 break;
             case NBT::TAG_Short:
                 $tag = new Short("");
                 $tag->read($nbt);
                 $this->{$i} = $tag;
                 break;
             case NBT::TAG_Int:
                 $tag = new Int("");
                 $tag->read($nbt);
                 $this->{$i} = $tag;
                 break;
             case NBT::TAG_Long:
                 $tag = new Long("");
                 $tag->read($nbt);
                 $this->{$i} = $tag;
                 break;
             case NBT::TAG_Float:
                 $tag = new Float("");
                 $tag->read($nbt);
                 $this->{$i} = $tag;
                 break;
             case NBT::TAG_Double:
                 $tag = new Double("");
                 $tag->read($nbt);
                 $this->{$i} = $tag;
                 break;
             case NBT::TAG_ByteArray:
                 $tag = new ByteArray("");
                 $tag->read($nbt);
                 $this->{$i} = $tag;
                 break;
             case NBT::TAG_String:
                 $tag = new String("");
                 $tag->read($nbt);
                 $this->{$i} = $tag;
                 break;
             case NBT::TAG_Enum:
                 $tag = new TagEnum("");
                 $tag->read($nbt);
                 $this->{$i} = $tag;
                 break;
             case NBT::TAG_Compound:
                 $tag = new Compound("");
                 $tag->read($nbt);
                 $this->{$i} = $tag;
                 break;
             case NBT::TAG_IntArray:
                 $tag = new IntArray("");
                 $tag->read($nbt);
                 $this->{$i} = $tag;
                 break;
         }
     }
 }
Example #4
0
 public function read(NBT $nbt)
 {
     $this->value = [];
     $this->tagType = $nbt->getByte();
     $size = $nbt->getInt();
     for ($i = 0; $i < $size and !$nbt->feof(); ++$i) {
         switch ($this->tagType) {
             case NBT::TAG_Byte:
                 $tag = new Byte("");
                 $tag->read($nbt);
                 $this->{$i} = $tag;
                 break;
             case NBT::TAG_Short:
                 $tag = new Short("");
                 $tag->read($nbt);
                 $this->{$i} = $tag;
                 break;
             case NBT::TAG_Int:
                 $tag = new Int("");
                 $tag->read($nbt);
                 $this->{$i} = $tag;
                 break;
             case NBT::TAG_Long:
                 $tag = new Long("");
                 $tag->read($nbt);
                 $this->{$i} = $tag;
                 break;
             case NBT::TAG_Float:
                 $tag = new Float("");
                 $tag->read($nbt);
                 $this->{$i} = $tag;
                 break;
             case NBT::TAG_Double:
                 $tag = new Double("");
                 $tag->read($nbt);
                 $this->{$i} = $tag;
                 break;
             case NBT::TAG_ByteArray:
                 $tag = new ByteArray("");
                 $tag->read($nbt);
                 $this->{$i} = $tag;
                 break;
             case NBT::TAG_String:
                 $tag = new String("");
                 $tag->read($nbt);
                 $this->{$i} = $tag;
                 break;
             case NBT::TAG_Enum:
                 $tag = new TagEnum("");
                 $tag->read($nbt);
                 $this->{$i} = $tag;
                 break;
             case NBT::TAG_Compound:
                 $tag = new Compound("");
                 $tag->read($nbt);
                 $this->{$i} = $tag;
                 break;
             case NBT::TAG_IntArray:
                 $tag = new IntArray("");
                 $tag->read($nbt);
                 $this->{$i} = $tag;
                 break;
         }
     }
 }
Example #5
0
 public function readTag()
 {
     switch ($this->getByte()) {
         case NBT::TAG_Byte:
             $tag = new Byte($this->getString());
             $tag->read($this);
             break;
         case NBT::TAG_Short:
             $tag = new Short($this->getString());
             $tag->read($this);
             break;
         case NBT::TAG_Int:
             $tag = new Int($this->getString());
             $tag->read($this);
             break;
         case NBT::TAG_Long:
             $tag = new Long($this->getString());
             $tag->read($this);
             break;
         case NBT::TAG_Float:
             $tag = new Float($this->getString());
             $tag->read($this);
             break;
         case NBT::TAG_Double:
             $tag = new Double($this->getString());
             $tag->read($this);
             break;
         case NBT::TAG_ByteArray:
             $tag = new ByteArray($this->getString());
             $tag->read($this);
             break;
         case NBT::TAG_String:
             $tag = new String($this->getString());
             $tag->read($this);
             break;
         case NBT::TAG_Enum:
             $tag = new Enum($this->getString());
             $tag->read($this);
             break;
         case NBT::TAG_Compound:
             $tag = new Compound($this->getString());
             $tag->read($this);
             break;
         case NBT::TAG_IntArray:
             $tag = new IntArray($this->getString());
             $tag->read($this);
             break;
         case NBT::TAG_End:
             //No named tag
         //No named tag
         default:
             $tag = new End();
             break;
     }
     return $tag;
 }
 public function generateChunk($x, $z)
 {
     $nbt = new Compound("Level", []);
     $nbt->xPos = new Int("xPos", $this->getX() * 32 + $x);
     $nbt->zPos = new Int("zPos", $this->getZ() * 32 + $z);
     $nbt->LastUpdate = new Long("LastUpdate", 0);
     $nbt->LightPopulated = new Byte("LightPopulated", 0);
     $nbt->TerrainPopulated = new Byte("TerrainPopulated", 0);
     $nbt->V = new Byte("V", self::VERSION);
     $nbt->InhabitedTime = new Long("InhabitedTime", 0);
     $nbt->Biomes = new ByteArray("Biomes", \str_repeat(\chr(-1), 256));
     $nbt->HeightMap = new IntArray("HeightMap", \array_fill(0, 256, 127));
     $nbt->BiomeColors = new IntArray("BiomeColors", \array_fill(0, 256, \PHP_INT_SIZE === 8 ? \unpack("N", "…²J")[1] << 32 >> 32 : \unpack("N", "…²J")[1]));
     $nbt->Blocks = new ByteArray("Blocks", \str_repeat("", 32768));
     $nbt->Data = new ByteArray("Data", $half = \str_repeat("", 16384));
     $nbt->SkyLight = new ByteArray("SkyLight", $half);
     $nbt->BlockLight = new ByteArray("BlockLight", $half);
     $nbt->Entities = new Enum("Entities", []);
     $nbt->Entities->setTagType(NBT::TAG_Compound);
     $nbt->TileEntities = new Enum("TileEntities", []);
     $nbt->TileEntities->setTagType(NBT::TAG_Compound);
     $nbt->TileTicks = new Enum("TileTicks", []);
     $nbt->TileTicks->setTagType(NBT::TAG_Compound);
     $writer = new NBT(NBT::BIG_ENDIAN);
     $nbt->setName("Level");
     $writer->setData(new Compound("", ["Level" => $nbt]));
     $chunkData = $writer->writeCompressed(ZLIB_ENCODING_DEFLATE, self::$COMPRESSION_LEVEL);
     if ($chunkData !== \false) {
         $this->saveChunk($x, $z, $chunkData);
     }
 }
Example #7
0
 /**
  * @param Compound $nbt
  * @return NBT
  */
 protected function prepareChunkBinaryWriter(Compound $nbt)
 {
     $entities = [];
     foreach ($this->getEntities() as $entity) {
         if (!$entity instanceof Player and !$entity->closed) {
             $entity->saveNBT();
             $entities[] = $entity->namedtag;
         }
     }
     $nbt->Entities = new Enum("Entities", $entities);
     $nbt->Entities->setTagType(NBT::TAG_Compound);
     $tiles = [];
     foreach ($this->getTiles() as $tile) {
         $tile->saveNBT();
         $tiles[] = $tile->namedtag;
     }
     $nbt->TileEntities = new Enum("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 ByteArray("ExtraData", $extraData->getBuffer());
     $writer = new NBT(NBT::BIG_ENDIAN);
     $nbt->setName("Level");
     $writer->setData(new Compound("", ["Level" => $nbt]));
     return $writer;
 }