Add Item->setNamedTagEntry() and Item->removeNamedTagEntry()

This commit is contained in:
Dylan K. Taylor 2017-10-08 15:06:30 +01:00
parent 7239dbbb1a
commit ae5aa31e7b

View File

@ -36,6 +36,7 @@ use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\ByteTag;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\ListTag;
use pocketmine\nbt\tag\NamedTag;
use pocketmine\nbt\tag\ShortTag;
use pocketmine\nbt\tag\StringTag;
use pocketmine\nbt\tag\Tag;
@ -535,6 +536,18 @@ class Item implements ItemIds, \JsonSerializable{
return $this->getNamedTag()->{$name} ?? null;
}
public function setNamedTagEntry(NamedTag $new) : void{
$tag = $this->getNamedTag();
$tag->{$new->getName()} = $new;
$this->setNamedTag($tag);
}
public function removeNamedTagEntry(string $name) : void{
$tag = $this->getNamedTag();
unset($tag->{$name});
$this->setNamedTag($tag);
}
/**
* Returns a tree of Tag objects representing the Item's NBT. If the item does not have any NBT, an empty CompoundTag
* object is returned to allow the caller to manipulate and apply back to the item.