Save items properly on several places, added NBT::getItemHelper() and NBT::putItemHelper()

This commit is contained in:
Shoghi Cervantes
2015-08-06 21:44:00 +02:00
parent 554bfb4855
commit 02cb9d69a9
10 changed files with 84 additions and 65 deletions

View File

@ -111,11 +111,7 @@ class Chest extends Spawnable implements InventoryHolder, Container{
if($i < 0){
return Item::get(Item::AIR, 0, 0);
}else{
$item = Item::get($this->namedtag->Items[$i]["id"], $this->namedtag->Items[$i]["Damage"], $this->namedtag->Items[$i]["Count"]);
if(isset($this->namedtag->Items[$i]["tag"])){
$item->setNamedTag($this->namedtag->Items[$i]["tag"]);
}
return $item;
return NBT::getItemHelper($this->namedtag->Items[$i]);
}
}
@ -130,17 +126,7 @@ class Chest extends Spawnable implements InventoryHolder, Container{
public function setItem($index, Item $item){
$i = $this->getSlotIndex($index);
$d = new Compound("", [
new Byte("Count", $item->getCount()),
new Byte("Slot", $index),
new Short("id", $item->getId()),
new Short("Damage", $item->getDamage()),
]);
if($item->hasCompoundTag() and ($tag = $item->getNamedTag()) !== null){
$tag->setName("tag");
$d->tag = $tag;
}
$d = NBT::putItemHelper($item, $index);
if($item->getId() === Item::AIR or $item->getCount() <= 0){
if($i >= 0){