22declare(strict_types=1);
35 private $customName =
null;
37 abstract public function getDefaultName() : string;
39 public function getName() :
string{
40 return $this->customName ?? $this->getDefaultName();
43 public function setName(
string $name) :
void{
45 $this->customName =
null;
47 $this->customName = $name;
51 public function hasName() :
bool{
52 return $this->customName !==
null;
55 public function addAdditionalSpawnData(
CompoundTag $nbt) :
void{
56 if($this->customName !==
null){
57 $nbt->
setString(Nameable::TAG_CUSTOM_NAME, $this->customName);
61 protected function loadName(
CompoundTag $tag) :
void{
62 if(($customNameTag = $tag->
getTag(Nameable::TAG_CUSTOM_NAME)) instanceof
StringTag){
63 $this->customName = $customNameTag->getValue();
67 protected function saveName(
CompoundTag $tag) :
void{
68 if($this->customName !==
null){
69 $tag->
setString(Nameable::TAG_CUSTOM_NAME, $this->customName);
78 if($item->hasCustomName()){
79 $this->setName($item->getCustomName());
setString(string $name, string $value)
copyDataFromItem(Item $item)