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

Block custom name

Discussion in 'Development' started by Astro, Aug 24, 2018.

  1. Astro

    Astro Slime

    Messages:
    78
    GitHub:
    RealAstro
    Is there a way to make a block keep its custom name after breaking it?
     
  2. OnTheVerge

    OnTheVerge Spider Jockey

    Messages:
    46
    After breaking the block and the custom name does not remain, I'd assume you can simply use PlayerItemHeldEvent and if your desired block is held and does not have the custom name... set the custom name for the held item.:p If you want an example code feel free to ask if you don't understand.:)
     
  3. Astro

    Astro Slime

    Messages:
    78
    GitHub:
    RealAstro
    sure, can i see your example
     
  4. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    if(heldItemId = 21) heldItemId set custom name();
     
    Astro likes this.
  5. OnTheVerge

    OnTheVerge Spider Jockey

    Messages:
    46
    PHP:
    public function onItemHeld(PlayerItemHeldEvent $event){
    #Variables
    $player $event->getPlayer();
    $hand $player->getInventory()->getItemInHand();

      if(
    $hand->getId() == 21 && $hand->getCustomName() !== "the original custom name"){
        
    $hand->setCustomName("the original custom name");
        
    $player->getInventory()->setItemInHand($hand);
        
       }
    }
     
    Astro and Qeis2007 like this.
  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.