Block should not drop an item

Discussion in 'Plugin Development' started by sds, Feb 1, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    sds

    Hey, I'm making a TNT plugin, but I don't want the exploded blocks to drop items,
    e.g. I do /bomb, it will rain one TNT, but thit TNT shouldn't drop an item. How can I do that?

    Thx, sds
     
  2. Offline

    Kierrow

    Sooo... as far as I understand you, you'd want an explosion to not yield any drops?
    If so, this is what you'd need to do:

    What you're gonna want to do is listen for an EntityExplodeEvent.
    It should look somewhat like this:
    Code:
    @EventHandler
    public void onEntityExplode(EntityExplodeEvent event) {
        event.setYield(0F);
    }
    I hope this helps.

    If this is not the solution you were looking for,
    please explain your problem again and be a bit more specific...
     
  3. Offline

    skore87

    No, he wouldn't want to set a yield of zero to the tnt. What that would do would create just the explosion effect and not damage any blocks. What he is asking is to create the explosion, still remove the blocks, just have the items be destroyed and not actually drop. I have a few ideas how to do this, but I don't have a definitive answer. sorry =\
     
  4. Offline

    nisovin

    Are you sure about that? I'm pretty sure the yield is the percentage of blocks that drop items, and doesn't affect whether the blocks actually get destroyed.
     
  5. Offline

    skore87

    I am certain that it does not change the block drop as I use fake explosions in my TNTCannon plugin to simulate the muzzle blast from the cannon. I create both a zero yield and a variable yield explosion with this plugin. The only thing the yield does is dictate the size of the explosion (not the graphic) size. The explosion event might have a property you can change, but if it does not you may want to catch the event that an item is spawned and try to get the reason it was spawned then cancel it if it was from tnt.
     
  6. Offline

    desht

    Are you confusing the power parameter to world.createExplosion() and the yield field of the EntityExplodeEvent? I know from experience that event.setYield() in an EntityExplodeEvent handler does indeed affect the number of blocks dropped. To change the blocks that will be destroyed in the event, you need to modify the block list as returned by the event.blockList() method (or just cancel the event).
     
  7. Offline

    SirTyler

    Couldn't you just listen for BlockBreakEvent and check if its due to the tnt? then just cancel the event and set the block to air?
     
  8. Offline

    desht

    Why? event.setYield(0) works fine.
     
  9. Offline

    SirTyler

    Just offering another possible way to do it. It's not really the best method (as said before setYeild works better) but perhaps for a server wide change it would be good. But yeah it's just another way to do it is all.
     
  10. Offline

    skore87

    Looking at the event itself, the yield is actually the block percentage. What I was referring to was the createExplosion method's property. Sorry for the confusion.

    Edit: From the event, you may be able to modify the setYield of the entity (yes, same name, different result. it sets the radius, not drop rate) during the explosion as well.
     
Thread Status:
Not open for further replies.

Share This Page