Fixed NBT parsing on false properties

This commit is contained in:
Shoghi Cervantes 2015-04-20 13:57:16 +02:00
parent 6ed63edd89
commit f88aed1208
14 changed files with 37 additions and 39 deletions

View File

@ -706,7 +706,7 @@ class Server{
$this->logger->notice($this->getLanguage()->translateString("pocketmine.data.playerNotFound", [$name]));
}
$spawn = $this->getDefaultLevel()->getSafeSpawn();
$nbt = new Compound(false, [
$nbt = new Compound("", [
new Long("firstPlayed", floor(microtime(true) * 1000)),
new Long("lastPlayed", floor(microtime(true) * 1000)),
new Enum("Pos", [
@ -758,7 +758,7 @@ class Server{
$this->logger->notice($this->getLanguage()->translateString("pocketmine.data.playerOld", [$name]));
foreach($data->get("inventory") as $slot => $item){
if(count($item) === 3){
$nbt->Inventory[$slot + 9] = new Compound(false, [
$nbt->Inventory[$slot + 9] = new Compound("", [
new Short("id", $item[0]),
new Short("Damage", $item[1]),
new Byte("Count", $item[2]),
@ -770,7 +770,7 @@ class Server{
foreach($data->get("hotbar") as $slot => $itemSlot){
if(isset($nbt->Inventory[$itemSlot + 9])){
$item = $nbt->Inventory[$itemSlot + 9];
$nbt->Inventory[$slot] = new Compound(false, [
$nbt->Inventory[$slot] = new Compound("", [
new Short("id", $item["id"]),
new Short("Damage", $item["Damage"]),
new Byte("Count", $item["Count"]),
@ -781,7 +781,7 @@ class Server{
}
foreach($data->get("armor") as $slot => $item){
if(count($item) === 2){
$nbt->Inventory[$slot + 100] = new Compound(false, [
$nbt->Inventory[$slot + 100] = new Compound("", [
new Short("id", $item[0]),
new Short("Damage", $item[1]),
new Byte("Count", 1),

View File

@ -64,7 +64,7 @@ class BurningFurnace extends Solid{
];
$this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0];
$this->getLevel()->setBlock($block, $this, true, true);
$nbt = new Compound(false, [
$nbt = new Compound("", [
new Enum("Items", []),
new String("id", Tile::FURNACE),
new Int("x", $this->x),
@ -90,7 +90,7 @@ class BurningFurnace extends Solid{
if($t instanceof Furnace){
$furnace = $t;
}else{
$nbt = new Compound(false, [
$nbt = new Compound("", [
new Enum("Items", []),
new String("id", Tile::FURNACE),
new Int("x", $this->x),

View File

@ -91,7 +91,7 @@ class Chest extends Transparent{
}
$this->getLevel()->setBlock($block, $this, true, true);
$nbt = new Compound(false, [
$nbt = new Compound("", [
new Enum("Items", []),
new String("id", Tile::CHEST),
new Int("x", $this->x),
@ -131,7 +131,7 @@ class Chest extends Transparent{
if($t instanceof TileChest){
$chest = $t;
}else{
$nbt = new Compound(false, [
$nbt = new Compound("", [
new Enum("Items", []),
new String("id", Tile::CHEST),
new Int("x", $this->x),

View File

@ -142,7 +142,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
if($hotbarSlot !== -1){
$item = $this->inventory->getItem($hotbarSlot);
if($item->getId() !== 0 and $item->getCount() > 0){
$this->namedtag->Inventory[$slot] = new Compound(false, [
$this->namedtag->Inventory[$slot] = new Compound("", [
new Byte("Count", $item->getCount()),
new Short("Damage", $item->getDamage()),
new Byte("Slot", $slot),
@ -152,7 +152,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
continue;
}
}
$this->namedtag->Inventory[$slot] = new Compound(false, [
$this->namedtag->Inventory[$slot] = new Compound("", [
new Byte("Count", 0),
new Short("Damage", 0),
new Byte("Slot", $slot),
@ -166,7 +166,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
//$slotCount = (($this instanceof Player and ($this->gamemode & 0x01) === 1) ? Player::CREATIVE_SLOTS : Player::SURVIVAL_SLOTS) + 9;
for($slot = 9; $slot < $slotCount; ++$slot){
$item = $this->inventory->getItem($slot - 9);
$this->namedtag->Inventory[$slot] = new Compound(false, [
$this->namedtag->Inventory[$slot] = new Compound("", [
new Byte("Count", $item->getCount()),
new Short("Damage", $item->getDamage()),
new Byte("Slot", $slot),
@ -178,7 +178,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
for($slot = 100; $slot < 104; ++$slot){
$item = $this->inventory->getItem($this->inventory->getSize() + $slot - 100);
if($item instanceof ItemItem and $item->getId() !== ItemItem::AIR){
$this->namedtag->Inventory[$slot] = new Compound(false, [
$this->namedtag->Inventory[$slot] = new Compound("", [
new Byte("Count", $item->getCount()),
new Short("Damage", $item->getDamage()),
new Byte("Slot", $slot),

View File

@ -1469,7 +1469,7 @@ class Level implements ChunkManager, Metadatable{
}
if($hand->getId() === Item::SIGN_POST or $hand->getId() === Item::WALL_SIGN){
$tile = Tile::createTile("Sign", $this->getChunk($block->x >> 4, $block->z >> 4), new Compound(false, [
$tile = Tile::createTile("Sign", $this->getChunk($block->x >> 4, $block->z >> 4), new Compound("", [
"id" => new String("id", Tile::SIGN),
"x" => new Int("x", $block->x),
"y" => new Int("y", $block->y),

View File

@ -106,7 +106,7 @@ class Anvil extends McRegion{
}
public static function createChunkSection($Y){
return new ChunkSection(new Compound(null, [
return new ChunkSection(new Compound("", [
"Y" => new Byte("Y", $Y),
"Blocks" => new ByteArray("Blocks", str_repeat("\x00", 4096)),
"Data" => new ByteArray("Data", str_repeat("\x00", 2048)),

View File

@ -118,7 +118,7 @@ abstract class BaseLevelProvider implements LevelProvider{
public function saveLevelData(){
$nbt = new NBT(NBT::BIG_ENDIAN);
$nbt->setData(new Compound(null, [
$nbt->setData(new Compound("", [
"Data" => $this->levelData
]));
$buffer = $nbt->writeCompressed();

View File

@ -96,7 +96,7 @@ class LevelDB extends BaseLevelProvider{
mkdir($path . "/db", 0777, true);
}
//TODO, add extra details
$levelData = new Compound(null, [
$levelData = new Compound("", [
"hardcore" => new Byte("hardcore", 0),
"initialized" => new Byte("initialized", 1),
"GameType" => new Int("GameType", 0),

View File

@ -100,7 +100,7 @@ class McRegion extends BaseLevelProvider{
"GameRules" => new Compound("GameRules", [])
]);
$nbt = new NBT(NBT::BIG_ENDIAN);
$nbt->setData(new Compound(null, [
$nbt->setData(new Compound("", [
"Data" => $levelData
]));
$buffer = $nbt->writeCompressed();

View File

@ -119,28 +119,26 @@ class NBT{
*/
public function write(){
$this->offset = 0;
$data = false;
if($this->data instanceof Compound){
$this->writeTag($this->data);
$data = $this->buffer;
return $this->buffer;
}elseif(is_array($this->data)){
foreach($this->data as $tag){
$this->writeTag($tag);
}
$data = $this->buffer;
return $this->buffer;
}
return $data;
return false;
}
public function writeCompressed($compression = ZLIB_ENCODING_GZIP, $level = 7){
$data = false;
if(($write = $this->write()) !== false){
$data = zlib_encode($write, $compression, $level);
return zlib_encode($write, $compression, $level);
}
return $data;
return false;
}
public function readTag(){
@ -312,7 +310,7 @@ class NBT{
}
public function setArray(array $data){
$this->data = new Compound(null, []);
$this->data = new Compound("", []);
$this->fromArray($this->data, $data);
}

View File

@ -110,57 +110,57 @@ class Enum extends NamedTag implements \ArrayAccess, \Countable{
for($i = 0; $i < $size and !$nbt->feof(); ++$i){
switch($this->tagType){
case NBT::TAG_Byte:
$tag = new Byte(false);
$tag = new Byte("");
$tag->read($nbt);
$this->{$i} = $tag;
break;
case NBT::TAG_Short:
$tag = new Short(false);
$tag = new Short("");
$tag->read($nbt);
$this->{$i} = $tag;
break;
case NBT::TAG_Int:
$tag = new Int(false);
$tag = new Int("");
$tag->read($nbt);
$this->{$i} = $tag;
break;
case NBT::TAG_Long:
$tag = new Long(false);
$tag = new Long("");
$tag->read($nbt);
$this->{$i} = $tag;
break;
case NBT::TAG_Float:
$tag = new Float(false);
$tag = new Float("");
$tag->read($nbt);
$this->{$i} = $tag;
break;
case NBT::TAG_Double:
$tag = new Double(false);
$tag = new Double("");
$tag->read($nbt);
$this->{$i} = $tag;
break;
case NBT::TAG_ByteArray:
$tag = new ByteArray(false);
$tag = new ByteArray("");
$tag->read($nbt);
$this->{$i} = $tag;
break;
case NBT::TAG_String:
$tag = new String(false);
$tag = new String("");
$tag->read($nbt);
$this->{$i} = $tag;
break;
case NBT::TAG_Enum:
$tag = new TagEnum(false);
$tag = new TagEnum("");
$tag->read($nbt);
$this->{$i} = $tag;
break;
case NBT::TAG_Compound:
$tag = new Compound(false);
$tag = new Compound("");
$tag->read($nbt);
$this->{$i} = $tag;
break;
case NBT::TAG_IntArray:
$tag = new IntArray(false);
$tag = new IntArray("");
$tag->read($nbt);
$this->{$i} = $tag;
break;

View File

@ -31,7 +31,7 @@ abstract class NamedTag extends Tag{
* @param bool|float|double|int|byte|short|array|Compound|Enum|string $value
*/
public function __construct($name = "", $value = null){
$this->name = $name;
$this->name = ($name === null or $name === false) ? "" : $name;
if($value !== null){
$this->value = $value;
}

View File

@ -126,7 +126,7 @@ class Chest extends Spawnable implements InventoryHolder, Container{
public function setItem($index, Item $item){
$i = $this->getSlotIndex($index);
$d = new Compound(false, [
$d = new Compound("", [
new Byte("Count", $item->getCount()),
new Byte("Slot", $index),
new Short("id", $item->getId()),

View File

@ -135,7 +135,7 @@ class Furnace extends Tile implements InventoryHolder, Container{
public function setItem($index, Item $item){
$i = $this->getSlotIndex($index);
$d = new Compound(false, [
$d = new Compound("", [
new Byte("Count", $item->getCount()),
new Byte("Slot", $index),
new Short("id", $item->getId()),