From 3c3b346fd3d5692723c07c824baf65b3c867ffce Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 12 Mar 2014 22:54:32 +0100 Subject: [PATCH] Use NBT Compounds instead of a NBT codec in PMF level data --- src/PocketMine/level/Level.php | 5 ++--- src/PocketMine/pmf/LevelFormat.php | 22 ++++++++++++---------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/PocketMine/level/Level.php b/src/PocketMine/level/Level.php index 25d54826c..25e8a7734 100644 --- a/src/PocketMine/level/Level.php +++ b/src/PocketMine/level/Level.php @@ -554,11 +554,10 @@ class Level{ protected function doSaveRoundExtra(){ foreach($this->usedChunks as $index => $d){ LevelFormat::getXZ($index, $X, $Z); - $nbt = new NBT(NBT::BIG_ENDIAN); - $nbt->setData(new Compound("", array( + $nbt = new Compound("", array( new Enum("Entities", array()), new Enum("TileEntities", array()), - ))); + )); $nbt->Entities->setTagType(NBT::TAG_Compound); $nbt->TileEntities->setTagType(NBT::TAG_Compound); diff --git a/src/PocketMine/pmf/LevelFormat.php b/src/PocketMine/pmf/LevelFormat.php index 4e6ce1ac4..c35b76dab 100644 --- a/src/PocketMine/pmf/LevelFormat.php +++ b/src/PocketMine/pmf/LevelFormat.php @@ -188,14 +188,15 @@ class LevelFormat extends PMF{ private function upgrade_From1_To2(){ console("[NOTICE] Old PMF Level format version #1 detected, upgrading to version #2"); - $nbt = new NBT(NBT::BIG_ENDIAN); - $nbt->setData(new Compound("", array( + $nbt = new Compound("", array( new Enum("Entities", array()), new Enum("TileEntities", array()) - ))); + )); $nbt->Entities->setTagType(NBT::TAG_Compound); $nbt->TileEntities->setTagType(NBT::TAG_Compound); - $namedtag = $nbt->write(); + $nbtCodec = new NBT(NBT::BIG_ENDIAN); + $nbtCodec->setData($nbt); + $namedtag = $nbtCodec->write(); $namedtag = Utils::writeInt(strlen($namedtag)) . $namedtag; foreach(glob(dirname($this->file) . "/chunks/*/*.*.pmc") as $chunkFile){ $oldChunk = zlib_decode(file_get_contents($chunkFile)); @@ -298,7 +299,7 @@ class LevelFormat extends PMF{ $offset += 4; $nbt = new NBT(NBT::BIG_ENDIAN); $nbt->read(substr($chunk, $offset, $len)); - $this->chunkInfo[$index][2] = $nbt; + $this->chunkInfo[$index][2] = $nbt->getData(); $offset += $len; $this->chunks[$index] = array(); $this->chunkChange[$index] = array(-1 => false); @@ -419,11 +420,10 @@ class LevelFormat extends PMF{ 6 => 8192, 7 => 8192, ); - $nbt = new NBT(NBT::BIG_ENDIAN); - $nbt->setData(new Compound("", array( + $nbt = new Compound("", array( new Enum("Entities", array()), new Enum("TileEntities", array()) - ))); + )); $nbt->Entities->setTagType(NBT::TAG_Compound); $nbt->TileEntities->setTagType(NBT::TAG_Compound); $this->chunkInfo[$index] = array( @@ -668,7 +668,7 @@ class LevelFormat extends PMF{ return $this->chunkInfo[$index][2]; } - public function setChunkNBT($X, $Z, NBT $nbt){ + public function setChunkNBT($X, $Z, Compound $nbt){ if(!$this->isChunkLoaded($X, $Z) and $this->loadChunk($X, $Z) === false){ return false; } @@ -707,7 +707,9 @@ class LevelFormat extends PMF{ $chunk = ""; $chunk .= chr($bitmap); $chunk .= Utils::writeInt($this->chunkInfo[$index][1]); - $namedtag = $this->chunkInfo[$index][2]->write(); + $namedtag = new NBT(NBT::BIG_ENDIAN); + $namedtag->setData($this->chunkInfo[$index][2]); + $namedtag = $namedtag->write(); $chunk .= Utils::writeInt(strlen($namedtag)) . $namedtag; $chunk .= $this->chunkInfo[$index][3]; //biomes for($Y = 0; $Y < 8; ++$Y){