From b6c0eb8c962d8e9f6a443d25176a627f7680f2ab Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 22 Dec 2014 16:25:12 +0100 Subject: [PATCH] Added optional parameter for multiple NBT read --- src/pocketmine/level/format/leveldb/Chunk.php | 4 ++-- src/pocketmine/nbt/NBT.php | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/pocketmine/level/format/leveldb/Chunk.php b/src/pocketmine/level/format/leveldb/Chunk.php index b5c1cd8c1..c469e698f 100644 --- a/src/pocketmine/level/format/leveldb/Chunk.php +++ b/src/pocketmine/level/format/leveldb/Chunk.php @@ -243,7 +243,7 @@ class Chunk extends BaseFullChunk{ $entityData = $provider->getDatabase()->get(substr($data, 0, 8) . "\x32"); if($entityData !== false and strlen($entityData) > 0){ - $nbt->read($entityData); + $nbt->read($entityData, true); $entities = $nbt->getData(); if(!is_array($entities)){ $entities = [$entities]; @@ -251,7 +251,7 @@ class Chunk extends BaseFullChunk{ } $tileData = $provider->getDatabase()->get(substr($data, 0, 8) . "\x31"); if($tileData !== false and strlen($tileData) > 0){ - $nbt->read($tileData); + $nbt->read($tileData, true); $tiles = $nbt->getData(); if(!is_array($tiles)){ $tiles = [$tiles]; diff --git a/src/pocketmine/nbt/NBT.php b/src/pocketmine/nbt/NBT.php index 09fc3a7d6..09beaed99 100644 --- a/src/pocketmine/nbt/NBT.php +++ b/src/pocketmine/nbt/NBT.php @@ -97,11 +97,11 @@ class NBT{ $this->endianness = $endianness & 0x01; } - public function read($buffer){ + public function read($buffer, $doMultiple = false){ $this->offset = 0; $this->buffer = $buffer; $this->data = $this->readTag(); - if($this->offset < strlen($this->buffer)){ + if($doMultiple and $this->offset < strlen($this->buffer)){ $this->data = [$this->data]; do{ $this->data[] = $this->readTag(); @@ -120,9 +120,14 @@ class NBT{ $this->writeTag($this->data); return $this->buffer; - }else{ - return false; + }elseif(is_array($this->data)){ + foreach($this->data as $tag){ + $this->writeTag($tag); + } + return $this->buffer; } + + return false; } public function writeCompressed($compression = ZLIB_ENCODING_GZIP, $level = 7){