TNT that explodes instantly

Discussion in 'Plugin Development' started by Summit, Oct 11, 2011.

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

    Summit

    I want TNT to explode instantly, not do it's blinky animation. So far I've tried:

    - Hooking into the event when TNT becomes primed (starts blinking) - Doesn't seem to be one, onEntityPrime gets called when the TNT actually explodes
    - Hooking into the event when a TNT block becomes a TNT entity - tried onItemSpawn but it's not called in this case

    So, as far as I can see, there's 2 options:

    1. If I could get an event that lets me determine when the state of a TNT block switches to that of a TNT entity then I could remove the block and just do an explosion immediately.
    2. I could shorten the TNT fuse time to 0.

    Does anyone have any ideas for any of these options?
     
  2. Offline

    nickrak

    Either way is totally do-able:

    1)
    Code:java
    1. class Example extends EntityListener
    2. {
    3. @Override
    4. public void onExplosionPrime(ExplosionPrimeEvent event)
    5. {
    6. if (event.getEntity() instanceof TNTPrimed)
    7. {
    8. final TNTPrimed primed = (TNTPrimed) event.getEntity();
    9. final Location where = primed.getLocation();
    10. final int size = 5; // Made up number, not sure what normal size is.
    11. final boolean incendiary = true;
    12. primed.remove();
    13. where.getWorld().createExplosion(where, size, incendiary);
    14. }
    15. }
    16. }


    2)
    Code:java
    1. class Example extends EntityListener
    2. {
    3. @Override
    4. public void onExplosionPrime(ExplosionPrimeEvent event)
    5. {
    6. if (event.getEntity() instanceof TNTPrimed)
    7. {
    8. final TNTPrimed primed = (TNTPrimed) event.getEntity();
    9. primed.setFuseTicks(0);
    10. }
    11. }
    12. }
     
  3. Offline

    Tim Visee

    I think the second one is the best; If you use the first one and you use any plugin that blocks the TNT explosions, it wouldn't work..
     
    NathanWolf likes this.
Thread Status:
Not open for further replies.

Share This Page