Hi, With this code I add a colored Leather Tunic to the players inventory (And set the name of the item). But if I use the setCompoundTag the name don't set. Does someone know why? PHP: $item = Item::get(299, 0, 1)->setCustomName(TextFormat::GREEN . "Name"); $tempTag = new CompoundTag("", []);$tempTag->customColor = new IntTag("customColor", 0xDA2623);$item->setCompoundTag($tempTag); $player->getInventory()->setItem(4, $item);
Because you set a new CompoundTag on an item, which overrides the compound tag containing the display name. Read source.
But how can I set the new name? This don't work: PHP: $tempTag->customName = new StringTag("customName", "CustomName");
PHP: $item = Item::get(299, 0, 1);$tempTag = new CompoundTag("", []);$tempTag->customColor = new IntTag("customColor", 0xDA2623);$tempTag->display = new CompoundTag("display", [ "Name" => new StringTag("Name", TextFormat::GREEN."Name")]);$item->setCompoundTag($tempTag);$player->getInventory()->setItem(4, $item);