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

Custom block name

Discussion in 'Development' started by Daniktheboss, Nov 19, 2016.

  1. Daniktheboss

    Daniktheboss Baby Zombie

    Messages:
    144
    GitHub:
    daniktheboss
    So, i know theres
    $item->setCustomName("God sword")

    But, is there somthing like
    $event->getBlock->setCustomName("Name")?
     
  2. JackboyPlay

    JackboyPlay Spider

    Messages:
    11
    GitHub:
    JackboyPlay
    Did you mean the Item that get dropped on break? (
     
  3. Daniktheboss

    Daniktheboss Baby Zombie

    Messages:
    144
    GitHub:
    daniktheboss
    No, you hold the item and it has a name like "Stone"
     
  4. JackboyPlay

    JackboyPlay Spider

    Messages:
    11
    GitHub:
    JackboyPlay
    PHP:
    public function onItemHeld (PlayerItemHeldEvent $e){
    If (
    $e->getItem ()->getId () === 1){
    $e->getItem ()->setCustomName ("The lonely stone");
    }
    }
     
  5. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    it should be same
    on hold stone
    get item -> set custom name (awesom stone)
    since anything that is in inventory can be consider an item so does a block
    name resets when place AFAIK
     
  6. Daniktheboss

    Daniktheboss Baby Zombie

    Messages:
    144
    GitHub:
    daniktheboss
    :confused:Really? I tried that and it didnt work.
     
  7. JackboyPlay

    JackboyPlay Spider

    Messages:
    11
    GitHub:
    JackboyPlay
    Use the dropped Item and rename it just like a normal Item.
     
  8. Daniktheboss

    Daniktheboss Baby Zombie

    Messages:
    144
    GitHub:
    daniktheboss
    i have a plugin when i do /spawner (mob) it gives me a spawner, and sets the spawner name as "pig spawner", then when i place it, i do if $event->getBlock->getCustomName() == "pig spawner"{ set the spawner a certain mob spawner} but it doesnt get past the get name part
     
  9. BalAnce

    BalAnce Silverfish

    Messages:
    22
    GitHub:
    YaBoiBalAnce
    Just use NBT tags
     
    Reid and XShockinFireX like this.
  10. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    You can't setCustomName() on a block object. You are referring to the Item that the player is holding that would result in the block being placed.

    Item and Block are data objects. Calling most methods (with the exception of certain event handling functions like useOn()) on them only alters their own properties, does not change PocketMine behaviour, unless you then pass these altered objects to the PocketMine API. For example, callinlg setCustomName() alone doesn't do anything; you have to put it into an inventory slot.
     
  11. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    A pocketmine\block\Block instance doesn't have an NBT tag (NamedTag/CompoundTag), that's what tiles are for. You'll want to save your custom NBT data to the mob spawners tile rather than the block.

    Like @SOFe said, there is not Block::setCustomName() as there is no NBT tag to save the custom name when the chunk the block is in unloads, if the function did exist it would be pretty useless if the custom name wasn't saved after every restart/chunk unload.

    Use the item constants, they're there for a reason and not just to look pretty.
     
    HimbeersaftLP likes this.
  12. JackboyPlay

    JackboyPlay Spider

    Messages:
    11
    GitHub:
    JackboyPlay
    I use item constants in my code, but to demonstrate it I've written the id
     
  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.