1.7.10 If Snowball Hits TnT Explode?

Discussion in 'Plugin Development' started by PROwolfpcgames, May 24, 2015.

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

    PROwolfpcgames

    How Can I check if a Snowball has his TnT and how can I make that tnt explode? Thanks!
     
  2. Offline

    JooshYT

    Get the projectile of the snowball and check the location where it lands, get that locations block then check it against TNT then .setType to primed tnt
     
  3. Offline

    PROwolfpcgames

    How do I get the landing location?
     
  4. Offline

    JooshYT

  5. Offline

    PROwolfpcgames

    This seems to not work at long distances. any reason that would be happening?

    Got It to work with

    @EventHandler
    public void HitTnT(ProjectileHitEvent e) {
    if (sweps) {
    if (e.getEntity() instanceof Snowball) {
    Snowball s = (Snowball) e.getEntity();
    if (s.getShooter() instanceof Player) {
    Player shooter = (Player) s.getShooter();
    Location l1 = new Location(s.getWorld(), s.getLocation().getX(), s.getLocation().getY() - 1, s.getLocation().getZ());
    if (l1.getBlock().getType() == Material.TNT) {
    if (shooter.getItemInHand().getType() == Material.WOOD_SPADE) {
    l1.getBlock().setType(Material.AIR);
    l1.getWorld()
    .spawn(l1, TNTPrimed.class);
    }
    }
    Location l2 = new Location(s.getWorld(), s.getLocation().getX(), s.getLocation().getY() + 1, s.getLocation().getZ());
    if (l2.getBlock().getType() == Material.TNT) {
    if (shooter.getItemInHand().getType() == Material.WOOD_SPADE) {
    l2.getBlock().setType(Material.AIR);
    l2.getWorld()
    .spawn(l2, TNTPrimed.class);
    }
    }
    Location l3 = new Location(s.getWorld(), s.getLocation().getX() - 1, s.getLocation().getY(), s.getLocation().getZ());
    if (l3.getBlock().getType() == Material.TNT) {
    if (shooter.getItemInHand().getType() == Material.WOOD_SPADE) {
    l3.getBlock().setType(Material.AIR);
    l3.getWorld()
    .spawn(l3, TNTPrimed.class);
    }
    }
    Location l4 = new Location(s.getWorld(), s.getLocation().getX() + 1, s.getLocation().getY(), s.getLocation().getZ());
    if (l4.getBlock().getType() == Material.TNT) {
    if (shooter.getItemInHand().getType() == Material.WOOD_SPADE) {
    l4.getBlock().setType(Material.AIR);
    l4.getWorld()
    .spawn(l4, TNTPrimed.class);
    }
    }
    Location l5 = new Location(s.getWorld(), s.getLocation().getX(), s.getLocation().getY(), s.getLocation().getZ() - 1);
    if (l5.getBlock().getType() == Material.TNT) {
    if (shooter.getItemInHand().getType() == Material.WOOD_SPADE) {
    l5.getBlock().setType(Material.AIR);
    l5.getWorld()
    .spawn(l5, TNTPrimed.class);
    }
    }
    Location l6 = new Location(s.getWorld(), s.getLocation().getX(), s.getLocation().getY(), s.getLocation().getZ() + 1);
    if (l6.getBlock().getType() == Material.TNT) {
    if (shooter.getItemInHand().getType() == Material.WOOD_SPADE) {
    l6.getBlock().setType(Material.AIR);
    l6.getWorld()
    .spawn(l6, TNTPrimed.class);
    }
    }
    }
    }
    }
    }

    but thanks anyway!

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

    JooshYT

    No problem, it dosnt work at long distance because when it gets too fare away from you it will unload.
     
  7. @PROwolfpcgames Bare in mind that that will ignite TNT if it hits the block next to it.
     
  8. Offline

    PROwolfpcgames

    I meant like any block that was more that 2 blocks away not that long.
     
  9. Offline

    Agentleader1

    Make your code easier by just looking for ProjectileHitEvent, then get the block, then get it's state, and check. I'm not all out sure that getting the block of ProjectileHitEvent exists, so get the location from the event, then get the block, then state, then check if it's TNT. Then explode?
     
Thread Status:
Not open for further replies.

Share This Page