1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

setCompoundTag / setCustomName

Discussion in 'Development' started by VentroxStudio, Jan 4, 2017.

  1. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    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(29901)->setCustomName(TextFormat::GREEN "Name");
                                
    $tempTag = new CompoundTag("", []);
    $tempTag->customColor = new IntTag("customColor"0xDA2623);
    $item->setCompoundTag($tempTag);
                                
    $player->getInventory()->setItem(4$item);
     
    StuckDexter likes this.
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Because you set a new CompoundTag on an item, which overrides the compound tag containing the display name.
    Read source.
     
    applqpak likes this.
  3. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    But how can I set the new name?
    This don't work:
    PHP:
    $tempTag->customName = new StringTag("customName""CustomName");
     
  4. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    PHP:
    $item Item::get(29901);
    $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);
     
    VentroxStudio and Kenn Fatt like this.
  5. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    Thanks. That worked :)
     
    Muqsit likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.