Solved (Finally :\) How To Stop TNT From Igniting?

Discussion in 'Plugin Development' started by kmecpp, Jul 24, 2014.

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

    kmecpp

    Hi, i'm trying to make a plugin that allows you to place TNT on top of a redstone block but have the tnt just stay there without exploding. Does anyone know a simple way i could do this?

    EDIT: IT'S REALLY PRETTY SIMPLE TO UNDERSTAND, ALL I'M TRYING TO DO IS PUT A TNT BLOCK NEXT TO A REDSTONE BLOCK WITHOUT ANYTHING HAPPENING!


    Answer:

     
  2. Offline

    Ozeir

  3. Offline

    kmecpp

    i tried and if u cancel this event it only makes the tnt explode without doing anything. It doesn't stop it from igniting
     
  4. Offline

    dsouzamatt

    kmecpp Could you set the redstone block's power output to 0?
     
  5. Offline

    kmecpp

    how could i do that?
     
  6. Offline

    dsouzamatt

    kmecpp I'm sure I saw a method on the Javadocs a while a go which lets you set a block's power output; just have a look around.
     
  7. Offline

    Ozeir

  8. Offline

    kmecpp

    Ozeir How would i use this? the event doesn't even seem cancel-able
     
  9. Offline

    Ozeir

    kmecpp ExplosionPrimeEvent should've worked can u post your code?
     
  10. Offline

    dsouzamatt

    Ozeir I think that's the one.

    kmecpp Use the .setNewCurrent(int) method.

    Actually, that's a good point. It sounds like you've forgotten to register your events or to use the @EventHandler annotation.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  11. Offline

    kmecpp

    Ozeir It does work but it can only cancels the event after the tnt has been lit and is primed and is just about to explode, unless i'm doing something terribly wrong doing this...

    Code:
        @EventHandler
        public void onExplosionPrime(ExplosionPrimeEvent e){
            e.setCancelled(true);
            Bukkit.getServer().broadcastMessage(ChatColor.RED + "NOPE!!!");
        }
    "NOPE!!!" is printed into the console and the tnt doesn't explode when i use this code but thats not exactly what i want, i want to make it so that you can light the tnt at all and make it so that it can just sit right on top of a redstone block.... and just stay there without doing anything

    dsouzamatt i have registered my events and used @EventHandler because the code works, it's just not cancelling the event when i want it to (Before the TNT gets lit)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  12. Offline

    dsouzamatt

    You want a primed tnt block to sit there and not explode?
     
  13. Offline

    kmecpp

    dsouzamatt no i dont want it to get primed, i just want it to be like a normal block, as if u placed a dirt block next to a redstone block... nothing happens


    This event doesn't seem to get called... and yes before you ask! i did use @EventHandler and register my events!

    EDIT: It gets called for some redstone usage, but not when you place a TNT block next to a redstone block which is what im trying to do

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  14. Offline

    Ozeir

    try this:

    Code:java
    1. public void onExplosionPrime(ExplosionPrimeEvent event) {
    2. entity = event.getEntity();
    3. if (entity instanceof TNTPrimed) {
    4. event.setCancelled(true);
    5. }
    6. }
     
  15. Offline

    dsouzamatt

    Copied and pasted from here, may I ask?

    That code won't even work; your entity variable is never created and you're missing the @EventHandler annotation.
     
  16. Offline

    Ozeir

    yes, and its just an example..
     
  17. Offline

    kmecpp

    Also, Ozeir since i tried canceling all of these events

    Code:
    @EventHandler
        public void onExplosionPrime(ExplosionPrimeEvent e){
            e.setCancelled(true);
            Bukkit.getServer().broadcastMessage(ChatColor.RED + "NOPE!!!");
        }
    why would seeing if the entity is TNT help at all, it's not like i was getting errors with the code above and the event never finished
     
  18. Offline

    Ozeir

    If you only want it for a redstone block why aren't u using BlockRedstoneEvent?
     
  19. Offline

    kmecpp

    Ozeir iv'e tried that event and it doesn't get called when you place TNT on top of a redstone block which is what i'm trying to do! If you don't believe me, then test it yourself

    Bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  20. Offline

    Niknea

    kmecpp Use the PlayerInteractEvent, see if the player is right clicking a block, if so, check if the block is tnt, and if they are holding an item that can light it, ex. flint and steel. If they are, cancel the event.
     
  21. Offline

    kmecpp

    Niknea I don't want to stop the block from being placed, i want it to be able to get placed on top of a redstone block without exploding

    tempelis I tested ur code and it doesn't work either, like i said in half my other posts, the ExplosionPrimeEvent gets called after the TNT has ignited and right before it explodes. Also, the new TNT block that is created doesn't do what i want it to do either, it gets ignited by the redstone block.
     
  22. EDIT: IT'S REALLY PRETTY SIMPLE, ALL I'M TRYING TO DO IS PUT A TNT BLOCK NEXT TO A REDSTONE BLOCK WITHOUT ANYTHING HAPPENING!
    If it's so simple then figure it out yourself ...

    AFAIK you can try to use BlockIgniteEvent

    EDIT: kmecpp
     
  23. Offline

    kmecpp

    WD_MUFFINFLUFFER I'm just kinda frustrated cause everyones suggesting stuff that has already been suggested which doesn't work because iv'e tested everything everyones given me and nothing does what i want it to do so i thought i might as well make it very clear what i'm trying to do :p

    WD_MUFFINFLUFFER Also, BlockIgniteEvent is called when you set something on fire... not when TNT is primed.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  24. Offline

    xTigerRebornx

    kmecpp
    Code:
    @EventHandler
        public void onBlockPlace(BlockPlaceEvent event){
            if(event.getBlock().getType() == Material.TNT){
                event.setCancelled(true);
                BlockState s = event.getBlockReplacedState();
                s.setType(Material.TNT);
                s.update(true, false);
            }
        }
    This effectively stopped it. How this works, see the update(boolean, boolean) method used. I pass in false to the 2nd argument, and it doesn't apply physics (apparently tnt ignition is physics). It worked perfectly (note, a Block update will ignite the TNT I believe). I had to cancel the event to stop the update from being applied, then applied it myself without physics.
     
    kmecpp likes this.
  25. Oops xD
    Also I dont think this will ever be solved
    Go to
    https://forums.bukkit.org/threads/tnt-prime-event.139765/
    And read ShadyPotato's comment

    "Sorry to say, there is currently no event fired when a block of TNT is primed. EntityPrimeEvent fires "when an entity makes the decision to explode." In other words, it fires the tick before the TNT actually explodes. Your best bet is to listen to a PlayerInteractEvent, check if the clicked block is TNT, and somehow figure out if the event will prime the TNT. You could probably find another solution on the forums, as I've seen tons of threads about this issue."
     
  26. Offline

    xTigerRebornx

    WD_MUFFINFLUFFER I posted a (hacky but) valid solution. It doesn't ignite on placement. If he truly wanted to make it not ignite, he'd have override its behavior deep within NMS, which probably won't be too fun to do.
     
  27. Offline

    kmecpp

    xTigerRebornx Thank you so much!!!!! This works perfectly while everyone i asked told me it was impossible! +1 Like :D
     
Thread Status:
Not open for further replies.

Share This Page