Allow Tiles to decide how to copy data from an item

This commit is contained in:
Dylan K. Taylor
2018-12-26 20:01:14 +00:00
parent f6983efec1
commit 2c6381632c
4 changed files with 34 additions and 16 deletions

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace pocketmine\tile;
use pocketmine\item\Item;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\StringTag;
@@ -80,4 +81,15 @@ trait NameableTrait{
$tag->setString(Nameable::TAG_CUSTOM_NAME, $this->customName);
}
}
/**
* @param Item $item
* @see Tile::copyDataFromItem()
*/
protected function copyDataFromItem(Item $item) : void{
parent::copyDataFromItem($item);
if($item->hasCustomName()){ //this should take precedence over saved NBT
$this->setName($item->getCustomName());
}
}
}