How to get block id

Discussion in 'Development' started by Hoyee, Mar 9, 2020.

  1. Hoyee

    Hoyee Baby Zombie

    Messages:
    115
    PHP:
    public function destoryCheck(BlockBreakEvent $event){
          
    $blockID $event->getBlockId();

          if(
    $blockID==1){
            
    $this->getServer()->broadCastMessage("break");

        }
      }
    It doesn't work. it says "Call to undefined method pocketmine\event\block\BlockBreakEvent::getBlockId()" (EXCEPTION)

    I want to make if stone is broken, sendMessage "break"
     
  2. Gianluxx

    Gianluxx Slime

    Messages:
    96
    GitHub:
    Gianluxx
    $blockID = $event->getBlock()->getId();
     
    GamakCZ likes this.
  3. GodWeedZao

    GodWeedZao Zombie

    Messages:
    205
    GitHub:
    godweedzao
    use
    PHP:
     public function onViewBlock(/*IDK :)*/ $event) {
    $block $event->getBlock();

    if (
    $block->getId() === Block::IDK) {
    //IDK AGAIN ;)
    }
    }
    Use this code
     
    Last edited: Jul 29, 2020
  4. GodWeedZao

    GodWeedZao Zombie

    Messages:
    205
    GitHub:
    godweedzao
    SOLVED? if yes please update Prefix ;)
     
  5. Primus

    Primus Zombie

    Messages:
    399
    Stop using loosely equal comparison. Check the difference here

    The method OP is looking for is Block::getId()

    Simply get the block object from Event object, if it is present, and call the method above. It will return an integer.
     
  6. GodWeedZao

    GodWeedZao Zombie

    Messages:
    205
    GitHub:
    godweedzao
    no matter in this CODE, its working fine.
     
  7. GodWeedZao

    GodWeedZao Zombie

    Messages:
    205
    GitHub:
    godweedzao
    oh yes, sorry i though i used !== in the code! XD
    you say correct, i fix it now. ;)
     
  8. GodWeedZao

    GodWeedZao Zombie

    Messages:
    205
    GitHub:
    godweedzao
    the best way (Full CODE):
    PHP:
    public function onBreak(BlockBreakEvent $event) {
    $player $event->getPlayer();
    $block $event->getBlock();
    if (
    $block->getId() === Block::DIAMOND_BLOCK) {
    $this->getServer()->broadcastmessage("Break");
    }
    //for check if block is not Diamond_Block use !== instead ===
    }
    DONE.
     
  9. GodWeedZao

    GodWeedZao Zombie

    Messages:
    205
    GitHub:
    godweedzao
    im not in my ide, mybe it has a little wrong.
     
  10. GodWeedZao

    GodWeedZao Zombie

    Messages:
    205
    GitHub:
    godweedzao
    please set prefix to SOLVED, if you dont have any more question... @Hoyee
     

Share This Page

  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.