Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

explosion drop all blocks?

Comments in 'Plugin Development' started by dxm_hippie, Jun 20, 2015.

  1. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    Hi, just wondering if anyone would care to tell meh if it's possible to make a explosion drop all effectedblcoks? like ores and stone and what not.
  2. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    try this:
    PHP:
    public function onExplode(EntityExplodeEvent $e){
            
    $e->setCancelled();
            
    $blocks $e->getBlockList();
            
    $level $b->getLevel();
            foreach(
    $blocks as $b){
                
    $level->setBlock(new Vector3($b->x$b->y$b->z), Block::get(0));
                
    $level->dropItem(new Vector3($b->x$b->y$b->z), Item::get($b->getId()));
            }
        }
    dxm_hippie likes this.
  3. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    thank you :D will test it out later, I'm making a power mining plugin for a VIP perk
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Will this prevent entity damages?
  5. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    seems like it should to me, considering there will be no boom anymore but i am having some trouble putting this in with the mining plugin im working on..seems to only work with tnt and not when a plugin caused a explosion, or more likely i have it goofed up lol
  6. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    is there a explodeEvent? instead of EntityExplodeEvent?
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Could you just modify the block list?
    Creeperface likes this.
  8. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    So..i just came back to this and this works..

    PHP:
    public function onExplode(Explosion $e){
            
    $blocks $e->affectedBlocks;
            foreach(
    $blocks as $b){
                
    $b->getLevel()->dropItem($b, new Item($b->getId())); //need to use $b->getDrops();
          
    }
        }
    but now im having troubles using $b->getDrops(Item::get(278, 116); instead of $b->getId(); ): it would still drop the unchanged block but would only drop somthing for grass and stone no ores with the getDrops method..idky just thought that might be some usefull info lol
    Last edited: Oct 28, 2015
  9. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    don't construct new Item object, instead do Item::get($id, $meta, $ammount);
  10. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    When using getDrops()?
    PHP:
    $b->getLevel()->dropItem($b, new Item($b->getId()));
    worked fine..but im having trouble with getDrops()


    \/

    PHP:
    $b->getLevel()->dropItem($bItem::get($b->getDrops(Item::get(279117))));
    it just dont get the drops, it keeps the block as if it were getId()
  11. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    I also swapped it to this..but same deal

    PHP:
     public function onExplode(Explosion $e$p){
            
    $blocks $e->affectedBlocks;
            foreach(
    $blocks as $b){
                
    $axe Item::get(279117);
                
    $p->getInventory()->addItem(Item::get($b->getDrops($axe)));
                }
        }
        }
  12. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    $tools = array(Item::get(Item::DIAMOND_AXE01), Item::get(Item::DIAMOND_PICKAXE01), Item::get(Item::DIAMOND_HOE01));

    foreach(
    $tools as $tool)
    {
    $drops $b->getDrops($tool);
    if(
    is_array($drops))
    {
    foreach(
    $drops as $drop)
    {
    $p->getInventory()->addItem($drop);
    }
    break;
    }
    }
  13. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    Did the same thing..gave me stone instead of cobble and no ores
    PHP:
    public function onExplode(Explosion $e$p){
            
    $blocks $e->affectedBlocks;
            foreach(
    $blocks as $b){
               
            
    $tools = array(Item::get(Item::DIAMOND_AXE01), Item::get(Item::DIAMOND_PICKAXE01), Item::get(Item::DIAMOND_SHOVEL01));
            foreach(
    $tools as $tool)
            {
            
    $drops $b->getDrops($tool);
            }
            if(
    is_array($drops)){
            foreach(
    $drops as $drop){
                
    $p->getInventory()->addItem(Item::get($drop));
            }
          }
        }
      }
  14. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    be creative add more if/else statements like
    PHP:
    foreach($drops as $drop)
    {
        if(
    $drop->getId() === 1)
        {
            
    $drop Item::get(Item::COBBLESTONE01);
        }
    }
  15. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    Well yes I could add a BlockChange function to manually change ores to their drops and stone to cobble..but I thought getDrops() did that automatically. Thanks for your help tho! :D
  16. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    Uhm..one more thing, do you know if i can set the drops on this? using $event->setDrops([]) crashed i also tried $e->affectedBlocks = ([]) but no effect. I did go with the manual way of changing the blocks to their broken form btw :p
    Last edited: Oct 29, 2015
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    :facepalm:
    Why did you pass $axe to $b->getDrops()...
  18. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    Bc when I left it blank there was a error saying it needs to be a instance of item none given.. it was a pickaxe.
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    $p->getInventory()->addItem($axe) ok?

    And why Item::get(279, 117)? You want to add an axe with 117 damage?
  20. dxm_hippie
    Offline

    dxm_hippie Active Member Plugin Developer

    Joined:
    Feb 1, 2015
    Posts:
    413
    Plugins:
    1
    Minecraft User:
    XxDXM_hippiexX
    Wont that give them a diamond pickaxe?.. and I was thinking that was the media :p

Share This Page

Advertisement