I want to rename an Item, but its not working. PHP: $vip = Item::get(Item::GOLDEN_NUGGET, 0, 1); $vip->setCustomName(Color::AQUA."VIP-Item!"); $player->getInventory()->addItem($vip); setCustomName doesnt work. :/ Has anyone an another idea to rename items? Thanks!
PHP: use pocketmine\event\player\PlayerItemHeldEvent as itemheld;public function renameItem(itemheld $im){ if($im->getItem() == "1"){ $im->getPlayer()->getInventory()->setItemInHand($im->getItem()->setCustomName("TESTING")); } } Not tested, but maybe working...
try this i think it works PHP: public function setCustomName(Item $item, $name) { if ((string)$name === "") { $item->clearCustomName(); } if (!$item->hasCompound()) { $tag = new Compound("", []); } else { $tag = $item->getNamedTag(); } if (isset($tag->display) and $tag->display instanceof Compound) { $tag->display->Name = new StringTag("Name", $name); } else { $tag->display = new Compound("display", ["Name" => new StringTag("Name", $name) ]); } $item->setNamedTag($tag); return $item; }
Not renamed, but if you ok, why don't you test? Get player helding item (using PlayerItemHeldEvent), and send item name as popup.
Can I disable the ItemName-PopUp (the name of the item) and change it to a popUp? So if i got a item in my hand, it shows me not the item name, but it will show me a popUp? Omg, sorry for my english btw.
Yes. getPlayer from PlayerItemHeldEvent And use "switch" (item id). ex: case "1" 1 is item id. And set the item id and messages.