I would suggest using PHP: $item->setCustomName("Diamond Sword");// You can use \n to get to a new line!
The easy way is but if you want to set the item name using nbt: PHP: $item = Item::get($itemId, $itemDamage, $itemCount);$nbt = new CompoundTag("", [new CompoundTag("display", [new StringTag("Name", "type your name here")])]);$item->setCompoundTag($nbt); // this will also remove any other nbt tags or PHP: $item = Item::get($itemId, $itemDamage, $itemCount, NBT::parseJSON('{display:{Name:"your name here"}}'));
How could you method be easy? My method is easy and also has the same outcome as your. I'm not sure if NBT has \n
i showed him how to change item's name using nbt from all the ways, now he can choose what is easy or hard for him, and nbt has \n (i tried)
Always prefer using API methods over directly editing the NBT so that plugins will continue to work even if the NBT format is somehow changed in some versions. NBT changes are not documented or guaranteed consistent in the API.
then you need to update the item in the player's inventory correct way: PHP: $item = $player->getInventory()->getItemInHand();$slot = $player->getInventory()->getHeldItemSlot();$item->setCount($item->getCount() - 1);$player->getInventory()->clear($slot);$player->getInventory()->setItem($slot, $item);