Fixed properties for NBT, fixed dropping items removing extra data set

This commit is contained in:
Shoghi Cervantes 2015-08-06 21:51:39 +02:00
parent 02cb9d69a9
commit cba9ff393c
4 changed files with 7 additions and 100 deletions

View File

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

View File

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

View File

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

View File

@ -24,7 +24,7 @@ namespace pocketmine\nbt\tag;
abstract class NamedTag extends Tag{
public $__name;
protected $__name;
/**
* @param string $name