Throwable tnt

Discussion in 'Spigot Plugin Development' started by UnlimitedNinjas, Aug 1, 2018.

  1. I am trying to make throwable tnt but how do i actually launch the tnt, i know i can use vector but spawnfallingblock() cant figure it out.
    I tried this but it needs a byte
    Code (Text):
                if (e.getPlayer().getItemInHand().getType() == Material.TNT) {
                    ItemMeta meta = e.getPlayer().getItemInHand().getItemMeta();
                    if (meta.getDisplayName().equals("Throwable TNT")) {
                        if (e.getPlayer().hasPermission("upg.throwtnt")) {
                            e.getPlayer().getWorld().spawnFallingBlock(e.getPlayer().getLocation(), Material.TNT);
  2. I did not work with such thinks but it may work to spawn a projectile, add the tnt as passenger and then work with that..?

    Edit: Use Entity#setVelocity(Vector velocity)
    #2 Alex_qp, Aug 1, 2018
    Last edited: Aug 1, 2018
  3. Spawn a primed tnt (Entity) using World#spawnEntity (I think).
    Set a velocity ? to that entity using Entity#setVelocity
  4. TNTPrimed is actually an entity that represents a primed TNT. You can spawn that entity in and change it's velocity; making it actually throwable. Set it's velocity using a somewhat multiplied vector of the player's direction.
  5. just have a listener that listens for a left click.
    then summon primed tnt at your eye location and set its velocity
  6. you should probably add an action filter so it only activates on right/left click not when he steps on a pressure plate ect
  7. Seriously, it's not that hard.
    1) You get the player's eye location
    2) Spawn the TNT at the eye location
    3) Set velocity to player's direction
    4) Multiply the velocity to make it go faster

    I don't want to spoon feed as it's way too easy, so here are some tips if you're still stuck:
    • The class of primed TNT is TNTPrimed
    • You can get player direction using getEyeLocation#getDirection
  8. I dont know how to summon the primed tnt tho
  9. Did you try searching around on the internet for it?