Added optional parameter for multiple NBT read

This commit is contained in:
Shoghi Cervantes 2014-12-22 16:25:12 +01:00
parent afa8496767
commit b6c0eb8c96
2 changed files with 11 additions and 6 deletions

View File

@ -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];

View File

@ -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){