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; } protected static function createAdditionalNBT(CompoundTag $nbt, Vector3 $pos, ?int $face = null, ?Item $item = null, ?Player $player = null) : void{ if($item !== null and $item->hasCustomName()){ $nbt->setString(Nameable::TAG_CUSTOM_NAME, $item->getCustomName()); } } 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); } } }