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

Getting/placing block with custom name

Discussion in 'Development' started by Karanpatel567, Oct 25, 2017.

  1. Karanpatel567

    Karanpatel567 Baby Zombie

    Messages:
    115
    GitHub:
    Karanpatel567
    Hey does anyone know how to get a block which a custom name example a chest which has a custom name called "hai" and when placing it it sends a message but if it's a normal chest it doesn't do anything. I want it to be on the function BlockBreakEvent.
     
  2. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    Can you please show proof of a previous attempt?
     
  3. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
  4. Karanpatel567

    Karanpatel567 Baby Zombie

    Messages:
    115
    GitHub:
    Karanpatel567
    PHP:
    Public function onPlace (Blockplaceevent  $ev){
      
    $player $ev->getPlayer();
      
    $hand $player->getInventory()->getItemInHand();
      If(
    $hand->getId() == 54){
        If (
    $hand->getCustomName() === "hai"){
            
    $player->sendMessage("hai");
            }
        
        }
    }
     
  5. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    PHP:
    Public function onPlace (Blockplaceevent  $ev) {
        
    $hand $ev->getPlayer()->getInventory()->getItemInHand();
        if(
    $hand->getId() === Block::CHEST and $hand->getName() === "hai") {
            
    $player->sendMessage("hai");
        }
    }
     
    Last edited: Oct 28, 2017
  6. Karanpatel567

    Karanpatel567 Baby Zombie

    Messages:
    115
    GitHub:
    Karanpatel567
    How would I remove that block I placed?
     
  7. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    With setBlock()
     
  8. Karanpatel567

    Karanpatel567 Baby Zombie

    Messages:
    115
    GitHub:
    Karanpatel567
    Ik it's set block but doesn't work
     
  9. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    You doing something wrong then
     
  10. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    When do you want the block placed to be removed?
     
  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.