customName ?? $this->getDefaultName(); } /** * @param string $name */ public function setName(string $name) : void{ if($name === ""){ $this->customName = null; }else{ $this->customName = $name; } } /** * @return bool */ public function hasName() : bool{ return $this->customName !== null; } public function addAdditionalSpawnData(CompoundTag $nbt) : void{ if($this->customName !== null){ $nbt->setString(Nameable::TAG_CUSTOM_NAME, $this->customName); } } protected function loadName(CompoundTag $tag) : void{ if($tag->hasTag(Nameable::TAG_CUSTOM_NAME, StringTag::class)){ $this->customName = $tag->getString(Nameable::TAG_CUSTOM_NAME); } } protected function saveName(CompoundTag $tag) : void{ if($this->customName !== null){ $tag->setString(Nameable::TAG_CUSTOM_NAME, $this->customName); } } /** * @param Item $item * @see Tile::copyDataFromItem() */ public function copyDataFromItem(Item $item) : void{ parent::copyDataFromItem($item); if($item->hasCustomName()){ //this should take precedence over saved NBT $this->setName($item->getCustomName()); } } }