Explosion damage causes, entities and blocks confusion

Discussion in 'Plugin Development' started by toadmess, Mar 9, 2011.

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

    toadmess

    Hello fellow developers,

    Could someone please help unconfuse me about DamageCause.BLOCK_EXPLOSION and DamageCause.ENTITY_EXPLOSION?

    It looks to me like a BLOCK_EXPLOSION shouldn't be possible because TNT and Fireballs are both entities rather than blocks when they explode (i.e. TNT is a TNTPrimed entity not a block).

    In a plugin I'm listening to when explosions harm an entity (ENTITY_DAMAGED events) from a registered listener's EntityListener.onEntityDamage() method.

    When creepers explode and cause damage, this listener get calls with an EntityDamageByEntityEvent object. This is nice because it lets us discover that the cause of the damage was ENTITY_EXPLOSION and the getDamager() method correctly reports that it was a CraftCreeper that caused the pain.

    When it comes to a TNT or fireball explosion, the same listener method will be passed an EntityDamageByBlockEvent whose getDamager() returns null and whose damage cause is reported as BLOCK_EXPLOSION. Without the damager, I can't distinguish between the fireball and TNT explosions.

    I noticed some TODO comments in Explosion.a() which questioned whether it was even possible for a block explosion to happen. Here the damager is left as null when creating the BLOCK_EXPLOSION damage event. However, the block below happily sets the damager to the entity that was passed in to the constructor for the Explosion.

    Both EntityFireball and EntityTNTPrimed are passing in a null entity (here and here respectively) when creating their explosions. I tried simply changing them to pass themselves in and then we happily start getting EntityDamageByEntityEvents coming through with ENTITY_EXPLOSION causes and the appropriate non-null entity damager.

    In EntityFireball this was just changing:
    Code:
    this.world.a((Entity) null, this.locX, this.locY, this.locZ, event.getRadius(), event.getFire());
    to
    this.world.a((Entity) this, this.locX, this.locY, this.locZ, event.getRadius(), event.getFire());
    ..and the exact same treatment to EntityTNTPrimed too.

    Is it worth wrapping these two tweaks into a pull request? If so, it seems like the DamageCause.BLOCK_EXPLOSION enum should be removed? I'm happy to submit a pull request (if I can figure out git/github's way of doing things). Or does someone have intentions to do something with BLOCK_EXPLOSION? - as I don't want to tread on anyone's toes.

    Thanks for taking the time to read this far! :)
     
  2. Offline

    toadmess

Thread Status:
Not open for further replies.

Share This Page