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..
Currently not as long as i am concirned. But i saw setCustomName($name) once. If that doesn't work, have a look at my Firecracker plugin: https://github.com/ImagicalCorp/Firecracker/blob/master/src/thebigsmileXD/Firecracker/Main.php This will atleast "rename" them when you select them in your hotbar.
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!
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 /:
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!"."}}");
No apparently it has been added in august, but I've never noticed. I just found a thread about it: http://forums.pocketmine.net/threads/how-to-use-namedtag.14538/#post-143725
Oh sorry yes the quotation marks should be escaped: PHP: $tags = NBT::parseJSON("{display:{Name:\"My custom item name!\"}}");
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.
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!" } } }
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.
Actually, most of the Inventory methods clone the items that got from parameters and return cloned Item instances.
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; }