Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved No way to rename Items?

Comments in 'Plugin Development' started by cake23, Feb 10, 2016.

  1. cake23
    Offline

    cake23 Active Member

    Joined:
    Aug 10, 2015
    Posts:
    124
    Minecraft User:
    TheEnd
    I want to rename an Item, but its not working.
    PHP:
    $vip Item::get(Item::GOLDEN_NUGGET01);
                
    $vip->setCustomName(Color::AQUA."VIP-Item!");
                
    $player->getInventory()->addItem($vip);
    setCustomName doesnt work. :/ Has anyone an another idea to rename items?
    Thanks!
  2. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    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...
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    https://github.com/PocketMine/PocketMine-MP/issues/3864
    cake23 likes this.
  4. cake23
    Offline

    cake23 Active Member

    Joined:
    Aug 10, 2015
    Posts:
    124
    Minecraft User:
    TheEnd
  5. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    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;
        }
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Test it and pull request :)
  7. cake23
    Offline

    cake23 Active Member

    Joined:
    Aug 10, 2015
    Posts:
    124
    Minecraft User:
    TheEnd
    Hm...it doesnt work. :( Maybe i make something wrong...
  8. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    And what version of MCPE do you have?
  9. cake23
    Offline

    cake23 Active Member

    Joined:
    Aug 10, 2015
    Posts:
    124
    Minecraft User:
    TheEnd
    0.13.2 :D
  10. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    Not renamed, but if you ok, why don't you test?
    Get player helding item (using PlayerItemHeldEvent), and send item name as popup.
  11. cake23
    Offline

    cake23 Active Member

    Joined:
    Aug 10, 2015
    Posts:
    124
    Minecraft User:
    TheEnd
    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.
  12. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    Yes. getPlayer from PlayerItemHeldEvent
    And use "switch" (item id).
    ex: case "1" 1 is item id.

    And set the item id and messages.
    cake23 likes this.
  13. cake23
    Offline

    cake23 Active Member

    Joined:
    Aug 10, 2015
    Posts:
    124
    Minecraft User:
    TheEnd
    Thank you! I will try it out :3
  14. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    If can't, try elseif.
    cake23 likes this.
  15. cake23
    Offline

    cake23 Active Member

    Joined:
    Aug 10, 2015
    Posts:
    124
    Minecraft User:
    TheEnd
    Yes, it works. :D Thank you! <3

    I will use this method and wait until setCustomName will be fix :3
    korado531m7 likes this.
  16. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    You're welcome :)
    xXFuryHDXx and cake23 like this.

Share This Page

Advertisement