From cba9ff393c2ec611939a18dd24b079bafc6d7165 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 6 Aug 2015 21:51:39 +0200 Subject: [PATCH] Fixed properties for NBT, fixed dropping items removing extra data set --- src/pocketmine/Server.php | 93 ----------------------------- src/pocketmine/level/Level.php | 10 ++-- src/pocketmine/nbt/tag/Compound.php | 2 +- src/pocketmine/nbt/tag/NamedTag.php | 2 +- 4 files changed, 7 insertions(+), 100 deletions(-) diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 7feba74c5..9975a8937 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -1093,99 +1093,6 @@ class Server{ $level->setTickRate($this->baseTickRate); - /*foreach($entities->getAll() as $entity){ - if(!isset($entity["id"])){ - break; - } - if($entity["id"] === 64){ //Item Drop - $e = $this->server->api->entity->add($this->levels[$name], ENTITY_ITEM, $entity["Item"]["id"], array( - "meta" => $entity["Item"]["Damage"], - "stack" => $entity["Item"]["Count"], - "x" => $entity["Pos"][0], - "y" => $entity["Pos"][1], - "z" => $entity["Pos"][2], - "yaw" => $entity["Rotation"][0], - "pitch" => $entity["Rotation"][1], - )); - }elseif($entity["id"] === FALLING_SAND){ - $e = $this->server->api->entity->add($this->levels[$name], ENTITY_FALLING, $entity["id"], $entity); - $e->setPosition(new Vector3($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2]), $entity["Rotation"][0], $entity["Rotation"][1]); - $e->setHealth($entity["Health"]); - }elseif($entity["id"] === OBJECT_PAINTING or $entity["id"] === OBJECT_ARROW){ //Painting - $e = $this->server->api->entity->add($this->levels[$name], ENTITY_OBJECT, $entity["id"], $entity); - $e->setPosition(new Vector3($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2]), $entity["Rotation"][0], $entity["Rotation"][1]); - $e->setHealth(1); - }else{ - $e = $this->server->api->entity->add($this->levels[$name], ENTITY_MOB, $entity["id"], $entity); - $e->setPosition(new Vector3($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2]), $entity["Rotation"][0], $entity["Rotation"][1]); - $e->setHealth($entity["Health"]); - } - }*/ - - /*if(file_exists($path . "tiles.yml")){ - $tiles = new Config($path . "tiles.yml", Config::YAML); - foreach($tiles->getAll() as $tile){ - if(!isset($tile["id"])){ - continue; - } - $level->loadChunk($tile["x"] >> 4, $tile["z"] >> 4); - - $nbt = new Compound(false, []); - foreach($tile as $index => $data){ - switch($index){ - case "Items": - $tag = new Enum("Items", []); - $tag->setTagType(NBT::TAG_Compound); - foreach($data as $slot => $fields){ - $tag[(int) $slot] = new Compound(false, array( - "Count" => new Byte("Count", $fields["Count"]), - "Slot" => new Short("Slot", $fields["Slot"]), - "Damage" => new Short("Damage", $fields["Damage"]), - "id" => new String("id", $fields["id"]) - )); - } - $nbt["Items"] = $tag; - break; - - case "id": - case "Text1": - case "Text2": - case "Text3": - case "Text4": - $nbt[$index] = new String($index, $data); - break; - - case "x": - case "y": - case "z": - case "pairx": - case "pairz": - $nbt[$index] = new Int($index, $data); - break; - - case "BurnTime": - case "CookTime": - case "MaxTime": - $nbt[$index] = new Short($index, $data); - break; - } - } - switch($tile["id"]){ - case Tile::FURNACE: - new Furnace($level, $nbt); - break; - case Tile::CHEST: - new Chest($level, $nbt); - break; - case Tile::SIGN: - new Sign($level, $nbt); - break; - } - } - unlink($path . "tiles.yml"); - $level->save(true, true); - }*/ - return true; } diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index cfa5e360f..6492d0e63 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -79,6 +79,7 @@ use pocketmine\math\Vector3; use pocketmine\metadata\BlockMetadataStore; use pocketmine\metadata\Metadatable; use pocketmine\metadata\MetadataValue; +use pocketmine\nbt\NBT; use pocketmine\nbt\tag\Byte; use pocketmine\nbt\tag\Compound; use pocketmine\nbt\tag\Double; @@ -1461,6 +1462,9 @@ class Level implements ChunkManager, Metadatable{ */ public function dropItem(Vector3 $source, Item $item, Vector3 $motion = null, $delay = 10){ $motion = $motion === null ? new Vector3(lcg_value() * 0.2 - 0.1, 0.2, lcg_value() * 0.2 - 0.1) : $motion; + $itemTag = NBT::putItemHelper($item); + $itemTag->setName("Item"); + if($item->getId() > 0 and $item->getCount() > 0){ $itemEntity = Entity::createEntity("Item", $this->getChunk($source->getX() >> 4, $source->getZ() >> 4, true), new Compound("", [ "Pos" => new Enum("Pos", [ @@ -1479,11 +1483,7 @@ class Level implements ChunkManager, Metadatable{ new Float("", 0) ]), "Health" => new Short("Health", 5), - "Item" => new Compound("Item", [ - "id" => new Short("id", $item->getId()), - "Damage" => new Short("Damage", $item->getDamage()), - "Count" => new Byte("Count", $item->getCount()) - ]), + "Item" => $itemTag, "PickupDelay" => new Short("PickupDelay", $delay) ])); diff --git a/src/pocketmine/nbt/tag/Compound.php b/src/pocketmine/nbt/tag/Compound.php index f71159fe0..654f33aa1 100644 --- a/src/pocketmine/nbt/tag/Compound.php +++ b/src/pocketmine/nbt/tag/Compound.php @@ -50,7 +50,7 @@ class Compound extends NamedTag implements \ArrayAccess{ } public function offsetExists($offset){ - return isset($this->{$offset}); + return isset($this->{$offset}) and $this->{$offset} instanceof Tag; } public function offsetGet($offset){ diff --git a/src/pocketmine/nbt/tag/NamedTag.php b/src/pocketmine/nbt/tag/NamedTag.php index edba11262..723e174bc 100644 --- a/src/pocketmine/nbt/tag/NamedTag.php +++ b/src/pocketmine/nbt/tag/NamedTag.php @@ -24,7 +24,7 @@ namespace pocketmine\nbt\tag; abstract class NamedTag extends Tag{ - public $__name; + protected $__name; /** * @param string $name