From ae5aa31e7b7b32aae6ebb4599310fe19549a26b6 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 8 Oct 2017 15:06:30 +0100 Subject: [PATCH] Add Item->setNamedTagEntry() and Item->removeNamedTagEntry() --- src/pocketmine/item/Item.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/pocketmine/item/Item.php b/src/pocketmine/item/Item.php index 26c38c261a..c0997258e3 100644 --- a/src/pocketmine/item/Item.php +++ b/src/pocketmine/item/Item.php @@ -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.