Need an event which fires when I prime my TNT

Discussion in 'Plugin Development' started by Etsijä, Apr 21, 2014.

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


    I can't believe I'm still not finding an event from Bukkit which fires when the TNT is being lit up (with flint & steel, fire, or redstone), ie. primed - not yet detonated. ExplosionPrimeEvent isn't it - for the fact that it fires one tick before the explosion happens, so is useless to me.

    What I really really need is this: when a TNT gets primed ("light up", "started", pick your term), an event fires which gives me the source, ie. the TNT block which it was before being primed (and so, changed into an entity).

    I really can't believe this is still not fixed - after some 3 years of debate and numerous pull requests. Tell me I'm just blind. Make me happy. Thank you.
  2. Offline


    Hi, try this:
    1. public void onCreatureSpawn(CreatureSpawnEvent event) {
    2. //Check if entity is tnt
    3. if (event.getEntityType() == EntityType.PRIMED_TNT) {
    4. //TODO: Do stuff
    5. }
    6. }

    It's based upon the fact that Primed Tnt is an entity, so when you prime the tnt-block, it changes into an entity

    EDIT: Don't forget to add an @EventHandler
  3. Offline


    No, sad to say that doesn't seem to work. The event just doesn't fire when I light up my TNT.

    I'm actually now thinking more along these lines: how would it be possible to detect interaction with a TNT block? I mean, lighting it with fire, F&S or redstone should be somehow detectable, right? This would be just what I need, since I need to read info from the original TNT block, and after it becomes the TNTPrimed entity, it is pretty useless for me.

    EDIT: Of course, F&S is easy to detect, since that is always a player interaction. But redstone isn't - so how could it be detected that a TNT got primed by redstone?

    You see, what we REALLY would need would be a proper event to get fired when these happen!

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


    Okay, I tried some things, and this worked for me:
    1. @EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent event) {
    3. //Check if the player clicked a block
    4. if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    5. //Check if the player is holding Flint And Steel
    6. if (event.getMaterial() == Material.FLINT_AND_STEEL) {
    7. //Check if you clicked TNT
    8. if (event.getClickedBlock().getType() == Material.TNT) {
    9. //TODO: Do things
    10. }
    11. }
    12. }
    13. }
  5. Offline


    Yes, yes, that is simple. But how to detect redstone interaction? Since it is not primarily caused by the player.

    EDIT: Regarding your earlier suggestion: I think CreatureSpawnEvent doesn't work, since it needs Living entities, and TNTPrimed is not such.
  6. Offline


    I'm not sure what you're trying to achieve. You could use the entityexplodeevent if you're trying to stop anything exploding:
    1. @EventHandler
    2. public void onEntityExplode(EntityExplodeEvent e) {
    3. if (e.getEntity().getType() == EntityType.PRIMED_TNT) {
    4. e.setCancelled(true);
    5. e.blockList().clear();
    6. }
    7. }

    The CreatureSpawnEvent has worked for me in the past, try that again
  7. Offline


    I am not trying to cancel the detonation, that would be easy. It's difficult to explain, but let me ensure you, the task is not dead simple, and it comes to the point that I need to detect when somewhere in the world a TNT gets primed - not necessarily by a player. By anything. I do not need to get the detonation, nor the moment one tick before the detonation. When primed.
  8. Offline


  9. Offline


    Sure, you can check if the TnT is powered. But when? He wants an event or events that will be the end-all, be-all, "Hey, a TnT is primed now" from which he can procure the original block. For some reason.

    ...Why do you want to do this, off the subject?
  10. Offline


    Finally. Thank you, Derplee, I will try your suggestion.

    To all suggesting CreatureSpawnEvent: it does not work. I don't know if it has, sometimes, but nowadays, creation of a TNTPrimed does NOT fire up the event. I verified this three times with my event handler.
  11. Offline


    Etsijä You could try the following (untested):
    • BlockIgniteEvent
    • EntityCombustEvent
    • ExplosionPrimeEvent (sounds like the best option)
  12. Offline


    Ah, thisguy, you're right. ...and it all once again boiles down to this: an event would be needed, which fires up when the TNT gets primed. Simple as that. This has been requested for over three years, and as I said, numerous solutions have been suggested, and all of them turned down, which is a bit odd.

    What I need it for? Well, in short, I have a plugin called ImpactTNT, which makes it possible to throw TNT out of your hand with left-click. Then the TNT detonates on impact to something solid, not when its normal fusetick counter reaches zero.

    The plugin works great, when user by the player (ie. TNT thrown by the player) but I want to extend it further: I have a TNT cannon, which effectively ignites the TNT and shoots it away. I lay my TNT to the cannon and start it with redstone. And I want this TNT shot by the cannon to behave like my ordinary "ImpactTNT", ie. detonate on impact.

    Here's the plugin link for those interested:

    Zach, I can try out your two first suggestions, but regarding the third one (ExplosionPrimeEvent): I explained already in my starting message that it is of no use to me, since it fires one tick before the explosion, and NOT when the TNT is primed (like its name suggests).

    This looks like a hopeless mission, since Bukkit just doesn't include the stuff I would need. If I have understood it correctly, the lifecycle of a TNT is this:
    • when it is in your inventory, it is an item (or a stack of items). I am using a special naming tactics for any "special TNT" carried by a player (I name them ImpactTNT), so the plugin can easily find out if someone carries this special TNT in their inventory
    • but when the player places it to the ground, it becomes a block and loses its special name, so the plugin risks losing info on this special TNT layed on the ground somewhere
    • and when you prime it, it becomes an entity, and the only event fired ever after it (I tested it) is the ExplosionPrimeEvent, which only fires one tick before the explosion
    I have to seriously think about abandoning my idea, since the implementation seems hopelessly complicated due to the missing stuff.

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


    A was inspired of ideas to create bukkit plugin several days ago after two months of playing this incredible game. And i needed the same event-handler (get block source just before entity was created).
    I've never known Java before and it's my first try to create plugin. And i decided that I am so stupid... And then i found this topic and it made me happy: there is no possibility to do that I want! :D

    So afterwards i think there are one solution:
    Make a list of events that can be before TNT being primed.
    2. ?
    May be it's possible to detect all cases?
  14. Offline


    Well, that has some idea in it, but as said in messages #9 and #10, it would become very tedious to find out when the TNT is light up with redstone.
  15. Offline


    Couldn't you use a BlockRedstoneEvent to detect when redstone current goes and then check if the block affected was TNT?
  16. Offline


    Well yes, that actually could work with not too much overhead in checking.
  17. Offline


    Etsijä So how'd it go? If it worked please label the thread as Solved
  18. Offline


    I found another way of doing this and circumvented the whole issue. I'd hate to mark this as solved since it really isn't - the event is still missing.
Thread Status:
Not open for further replies.

Share This Page