Getting TNTPrimed from BlockDispenseEvent

Discussion in 'Programming' started by EmeraldExplorer, May 13, 2015.

  1. I think the title explains it all. How would I do this?

    Code (Text):
    public void dispenseEvent(BlockDispenseEvent e){
    TNTPrimed tnt = //how would I get this?
    }
    Could I somehow find out a way to cast the tnt item to the tnt entity (am I saying that the wrong way around? :p), because this gets called when tnt is launched from a dispenser.
    Code (Text):
    if(e.getItem().getType().equals(Material.TNT)){}
    Edit 1:
    I could also get the dispenser from the tnt. I just need to figure out which tnt corresponds to which dispenser.

    Edit:2
    Anyway to have data carry on from the tnt item to the tnt entity? If I could do this if would fix my problem
     
    #1 EmeraldExplorer, May 13, 2015
    Last edited: May 26, 2015
  2. I can't remember how to do it specifically BUT primedtnt isn't a block, it's an entity.
     
  3. Think I would have to go into NMS code?
     
  4. TNTPrimed tnt = (TNTPrimed) e.getBlock();
     
  5. #1 as stated TNTPrimed is an entity, while BlockDispenseEvent#getBlock() returns a block, therefore => ClassCastException

    #2 getBlock returns the dispenser, NOT the dispensed item


    @TO:
    BlockDispenseEvent only works for dispensed items (ItemStacks). However fireballs, tnt, snowballs(?) etc. are launched entities, you can't get them from the event. Maybe try to use ProjectileLaunchEvent or similar.
     
  6. My bad, it was late and wasn't really thinking.
     
  7. ProjectileLaunchEvent only works for entities launching entities, not blocks launching entities :,(

    Edit: TNT is not considered a projectile.
     
    #10 EmeraldExplorer, May 19, 2015
    Last edited: May 19, 2015
  8. Then I can only think of TNTPrimeEvent.
     
  9. Doesn't exist?
     
  10. I thought of ExplosionPrimeEvent, but that's only called if the TNT already exploding... Sorry, no idea.