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

Change item name through NBT

Discussion in 'Development' started by Hipster, May 1, 2017.

  1. Hipster

    Hipster Zombie

    Messages:
    214
    How can i change an item's name through nbt tags?
     
  2. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Here's how PocketMine does it. I honestly don't know why you would want to handle NBT when there is already a function for it, but that example should get you started.
     
  3. Hipster

    Hipster Zombie

    Messages:
    214
    Which function?
     
  4. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Item::setCustomName(), which I highlighted on the GitHub link.
     
    Hipster and Lowkey like this.
  5. Lowkey

    Lowkey Slime

    Messages:
    94
    Can I just ask you why you want to do this instead of using setCustomName()?
     
  6. Hipster

    Hipster Zombie

    Messages:
    214
    If a player sets custom name on an item by setcustomname() and puts in chest, it seems to be glitching like it disappears, could be due to lag.
     
  7. Lowkey

    Lowkey Slime

    Messages:
    94
    Steps to reproduce issue? Just rename item with setCustomName and put in a chest?
     
  8. Hipster

    Hipster Zombie

    Messages:
    214
    But u will need 50+ players on server for lag
     
  9. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    speculation temporary memory leakage with using TP?
     
  10. Lowkey

    Lowkey Slime

    Messages:
    94
    I have seen your other thread and your server runs 11GB Memory/RAM... This cannot be a lag related issue. I will reproduce the issue myself. If it persists, feel free to open an issue on GitHub @ the PocketMine resporitory which you can find here; https://github.com/pmmp/PocketMine-MP
     
    Hipster likes this.
  11. Hipster

    Hipster Zombie

    Messages:
    214
    Yea okay thanks
     
  12. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Honestly, why do you think would this solve "lag"? The only way to rename an item in Minecraft is by manipulation of nbt tags. Item::setCustomName() is just the better way. Don't reinvent the wheel.
     
    corytortoise and jasonwynn10 like this.
  13. TheDiamondYT

    TheDiamondYT Zombie

    Messages:
    298
    GitHub:
    TheDiamondYT1
    Thats what almost every phone and car company in the world did.
     
    Teamblocket likes this.
  14. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Yes, however he isn't doing anything(that I know of) to make the wheel better. He is just doing what the setCustomName method already does. A better analogy would be driving a car with the convertible top down. It doesn't change the way the car functions, but it may cause you to have a bad time if it rains. If there are any NBT changes(Given what I've heard about the current NBT implementation, this is very possible), the setCustomName method in PMMP will most likely be updated to support those changes, possibly preventing you from having issues in your plugin.
     
    jasonwynn10, Muqsit and HimbeersaftLP like this.
  15. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    but no one is stopping you, you may refer to how PMMP did it which may just result in the same lag issues
     
  16. Hipster

    Hipster Zombie

    Messages:
    214
    PHP:
    $item Item::get(Item::BOW01NBT::parseJSON("{display:"));
    is this laggy or setCustomName();?
     
  17. Aviv

    Aviv Baby Zombie

    Messages:
    156
    Honestly, no idea why you want to do this when there is already a function for that, but
    PHP:
    $nbt = new CompoundTag("", [
      new 
    CompoundTag("display", [
        new 
    StringTag("Name"$customName)
      ])
    ]);
    $item->setCompoundTag($nbt);
    // or
    Item::get($itemId$itemDamage$itemCountNBT::parseJson("{display:{Name:'$customName'}}");
     
    Muqsit, Hipster and jasonwynn10 like this.
  18. Hipster

    Hipster Zombie

    Messages:
    214
    What function?
     
  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.