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

Solved Why BlockBreakEvent Not Working?

Discussion in 'Development' started by Bintang Putra, Jun 9, 2017.

  1. Bintang Putra

    Bintang Putra Witch

    Messages:
    63
    GitHub:
    chaostixzix
    Hi, i want to set another drops when player break a stone block
    Here's the code ;
    function onBreak(BlockBreakEvent $ev){
    switch($ev->getBlock()->getId()){
    case 1:
    $ev->setDrops(array(Item::get(276,0,1)->setCustomName("TEST")));
    break;
    }
    }

    But, Its not working, it drop cobblestone
    i've seen this post https://forums.pmmp.io/threads/blockbreakevent-does-not-work-wtf.898/page-2 and addet implement Listener

    but still not working :(
     
  2. RoyalMCPE

    RoyalMCPE Slime

    Messages:
    87
    It needs to be
    PHP:
    $level $event->getBlock()->getLevel();
    $level->setDrops (new Vector3 ($block->getX(), $block->getY(), $block->getZ()), array(Item::get(276,0,1)->setCustomName("TEST")));
     
  3. Bintang Putra

    Bintang Putra Witch

    Messages:
    63
    GitHub:
    chaostixzix
    Ok, i'll test it
     
  4. Bintang Putra

    Bintang Putra Witch

    Messages:
    63
    GitHub:
    chaostixzix
    Why There is no setdrops method?
     
  5. Bintang Putra

    Bintang Putra Witch

    Messages:
    63
    GitHub:
    chaostixzix
    I Used addDrops and Its Working Perfectly, but how to check if the player using pickaxe or no?
     
  6. RoyalMCPE

    RoyalMCPE Slime

    Messages:
    87
    Sorry it's actually dropItem
     
  7. Bintang Putra

    Bintang Putra Witch

    Messages:
    63
    GitHub:
    chaostixzix
    do you know how to check if the player using pickaxe for breaking the block or no?
     
  8. RoyalMCPE

    RoyalMCPE Slime

    Messages:
    87
    PHP:
    if  ($event->getPlayer()->getInventory()->getItemInHand()->getId() === array(Item::DIAMOND_PICKAXEItem::IRON_PICKAXEItem::GOLD_PICKAXEItem::STONE_PICKAXEItem::WOODEN_PICKAXE)) {
      
    // Your Code
    } else {
        return;
    }
     
    OnTheVerge likes this.
  9. Bintang Putra

    Bintang Putra Witch

    Messages:
    63
    GitHub:
    chaostixzix
    Wow, Thanks :D

    did u forgot } ?
     
  10. RoyalMCPE

    RoyalMCPE Slime

    Messages:
    87
    Updated
     
  11. Bintang Putra

    Bintang Putra Witch

    Messages:
    63
    GitHub:
    chaostixzix
    btw, How if i want to drop a Dyed Leather Armor?
     
  12. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    No, an integer will never be equal to an array, which means this will never work. Use in_array if you are using an array.
     
    jasonwynn10 likes this.
  13. Bintang Putra

    Bintang Putra Witch

    Messages:
    63
    GitHub:
    chaostixzix
    its solved :D ,thanks btw, do you know how to drops dyed leather armor?
     
  14. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    $event->setDrops() ?
     
  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.