How to Spawn in Prime TNT?

Discussion in 'Plugin Development' started by artish1, Jul 18, 2012.

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

    artish1

    Title pretty much says it,
    I know you need to get Prime tnt from EntityType.PRIMED_TNT
    i tried spawning it with world.playEffect(location, etc, etc,)
    That only spawns sounds of objects. such as doors, ghast screams, etc
    I was Looking through trying to find a way of HOW TO spawn a freaking Primed TNT where i look and do a certain command... someone care to help me?
     
  2. Offline

    lx3krypticx

    Here's something that you might need :)

    Code:
    public class KnockBackTnTListener implements Listener {
       
          @EventHandler(priority=EventPriority.HIGH)
          public void tntPlace(BlockPlaceEvent event)
          {
            if (event.getBlock().getType() == Material.DIAMOND_ORE)
            {
              event.getBlock().setType(Material.AIR);
              Entity tnt = event.getPlayer().getWorld().spawn(event.getBlock().getLocation(), TNTPrimed.class);
              ((TNTPrimed)tnt).setFuseTicks(0);
              //player.getInventory().setItemInHand(null);
            }
          }
    }
    
     
  3. Offline

    artish1

    Off topic:
    Nice diamond ore troll :p
    that made my day.. i wonder how much people in your server mined diamond ore and freaked out lol.
    on topic:
    How would i create the TNTPrimed.class? Thats what really gets me off... i tried creating an object such as prime tnt:
    EntityType tnt = EntityType.PRIMED_TNT;
    then i would just have to put the object tnt in somewhere... I just don't know which code or line or Specific area i would have to put tnt in.
     
  4. Offline

    lx3krypticx

    What are you trying to do? When you place tnt it is primed?
     
  5. Offline

    artish1

    Exactly, Well not exactly, I guess i could share a little bit more on my project,
    I would detect the Item in the players hand which is player.getHand(); or w/e it is im too lazy to check. and if He is an op, and if he is holding the item that i specifically say, it will then spawn a Primed tnt at the location of where he or she is looking.
    All i need is just where to to put the object "tnt" in a code where it can spawn in Entity's
    Since PrimeTNT is an entity
     
  6. Offline

    lx3krypticx

    Alright so is this on block place?
     
  7. Offline

    artish1

    No, its where the player looks.

    Code:
    if (blockId == 369){
                        Block block = targetPlayer.getTargetBlock(null, 75);
                        World world = targetPlayer.getWorld();
                        Location location = block.getLocation();
                        EntityType tnt = EntityType.PRIMED_TNT;
            
    Now the next line would be the line of spawning in the actual PRIME tnt, or inserting the object "tnt" since tnt is holding the information of what it is, i just NEED TO PUT it somewhere in a place where it can spawn Entity's
     
  8. Offline

    lx3krypticx

    How are you toggling this? A command?
     
  9. Offline

    artish1

    i will add that in later on, so far there is no toggle. The only specific way to prevent other players from using it is that it only works if YOU are op, and if YOU are holding a specific Item/block then you would spawn in a specific thing. although i havent added in any toggling commands, i will later on, for now im just trying to understand where to spawn in Entities, (Where the line is or code to spawn in Entities).
     
  10. Offline

    Njol

    This line will spawn a primed TNT above the targeted block:
    Code:
    TNTPrimed tnt = targetPlayer.getWorld().spawn(block.getLocation().add(0, 1, 0), TNTPrimed.class);
    You even have the entity reference which you can e.g. use to change the fuse length:
    Code:
    tnt.setFuseLength(ticks);
     
    Pingre likes this.
  11. Offline

    artish1

    Yes! Ty.... this is what i was looking for, a specific line ...

    Now just a thought in my mind popped up.. now that i can spawn primed tnt is there anyway to propel it? Such as if you have a pumpkin in your hand and the code says if block id = pumpkin then spawn a primed tnt( this is just out of the blue not really my code)
    and i would like to know instead of actually spawning the tnt on the target block you are looking at is there anyway the prime tnt can actually start out in front of your face or your hand and it then is propelled to the location you are looking at. something like a tnt cannon.. that type of propel, and i know this can be done considering that one plugin called
    Colour Fireworks, when drop party is about done it Propels a tnt up in the air and it explodes

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

    Njol

    Simply spawn the TNT in the player's head (literally) and set it's velocity to match where the player is looking:
    Code:
    TNTPrimed tnt = player.getWorld().spawn(player.getEyeLocation(), TNTPrimed.class);
    tnt.setVelocity(player.getLocation().getDirection().multiply(<speed the TNT should have>));
    You can test different speeds and choose one you like or make it an option in the config.
     
    Pingre, Grimerlin, ferrybig and 2 others like this.
  13. Offline

    Cowboys1919

    Ha I like TNT flying out from the player's head :p , I'm gonna add a class for that on my mcspleef.com server
     
  14. Offline

    artish1

    ty very much sir! You earned a like from me :)
     
  15. Offline

    joehot2000

    player.getWorld().SpawnEntity(Location, EntityType.PrimedTNT);
     
  16. Offline

    pilot3101

    If you are admin and have world guard, get a shovel and do /powertool tnt. The left click where you want it to go
     
  17. Offline

    PatoTheBest

    when you place a tnt, change the block besides to a redstone block, then change it back to a normal block
     
Thread Status:
Not open for further replies.

Share This Page