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

Renaming a block? client sided..?

Comments in 'Plugin Development' started by dxm_hippie, Jan 26, 2016.

  1. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    Is it possible to rename a block? even if it has to be done in pocketmine source code directly? So for example when a player holds a sword instead if it saying "Diamond sword" above the hot bar it will sayy..."Smite tool" i know anvils will be able to do this one day but it dont work as of right now..
  2. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    dxm_hippie likes this.
  3. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
  4. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    I will try the setcustomename quick.
  5. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    Not working /: ill just use the popup for now.
  6. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    390
    Setting a custom display name and much more is possible using the new NBT support for items! Even the built-in give command has support for it. Look at this interesting gist from Shoghi.
    The easiest way to use this in your plugin:
    PHP:
    $tags NBT::parseJSON('{display:{Name:"My custom item name!"}}');
    // $item is the Item object you want to change the name from
    $item->setNamedTag($tags);
    I didn't know these NBT tags myself until I found that gist of shoghi couple weeks ago. You can even lock chests! It's insane!
    Last edited: Jan 26, 2016
  7. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    Woah..lots of cool stuff i never saw there. Is that from one of the new pocketmine dev builds? bc everytime i try to check the new dev builds the website is offline /:
  8. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    Should it also be like this? it had a syntax error before and i know nothing about JSON.
    PHP:
    $tags NBT::parseJSON("{display:{Name:"."My custom item name!"."}}");
  9. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    390
  10. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    390
    Oh sorry yes the quotation marks should be escaped:
    PHP:
    $tags NBT::parseJSON("{display:{Name:\"My custom item name!\"}}");
    PEMapModder and dxm_hippie like this.
  11. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    Thanks! ill try it out.
  12. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    How does it come that noone knows it need JSON file format lol.
  13. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    This is the first time ive ran into a situation where i needed JSON lol but that didnt work /: is the json format wrong? bc it works with commands but i cant get that to work..no error or anything and ive tried switching up the format a bit.
  14. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    Please someone help me here..lol ive tried so many different formats for the $json..looked up tutorials..i cant get it to work /:

    PHP:
    $json '{"display":{"Name":"§r§6§lMy custom name!"}}';
                    
    var_dump(NBT::parseJSON($json));
    Code:
    class pocketmine\nbt\tag\Compound#22291 (3) {
      protected $__name =>
      string(0) ""
      protected $value =>
      NULL
      public $"display" =>
      class pocketmine\nbt\tag\Compound#25251 (3) {
        protected $__name =>
        string(9) ""display""
        protected $value =>
        NULL
        public $"Name" =>
        class pocketmine\nbt\tag\String#25253 (2) {
          protected $__name =>
          string(6) ""Name""
          protected $value =>
          string(25) "§r§6§lMy custom name!"
        }
      }
    }
    
  15. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
  16. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    OHHMERRGRRD...i have to remove the item then clone the new "named one" and re add it to their inventory -_- alllll that head ache...will clone cause memory leaks? i hear it will..i will use the pm function to check if it has a custom name before adding it again tho.
  17. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    Also had to move the string to a txt file..no idea why..but it works lol
  18. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Actually, most of the Inventory methods clone the items that got from parameters and return cloned Item instances.
    CrazedMiner likes this.
  19. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    CustomName
    Thats what you want, not name
  20. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    I dont get what you mean? isn't a custom name anything different than the real name? lol i just had to remove the old item and add the new one with the custom name..

    PHP:
    if($item->getId() === Block::SPONGE)
            {
                if(
    $item->hasCustomName())
                {
                    return;
                }
                
    $data file_get_contents($this->getPlugin()->getDataFolder()."Sponge.txt");
                
    $tags NBT::parseJSON($data);
                
    $player->getInventory()->removeItem($item);
                
    $items $item->setNamedTag($tags);
               
                if(
    $player->getInventory()->getItemInHand() !== Item::get(0))
                {
                    
    $player->getInventory()->addItem(clone $items);
                    return;
                }
                    
    $player->getInventory()->setItemInHand(clone $items);
                    return;
               
            }

Share This Page

Advertisement