Change a block with a Snowball

Discussion in 'Plugin Development' started by The__Master_Coder, Mar 28, 2014.

Thread Status:
Not open for further replies.
  1. Hello guys, I just need help on a minor line of code. I am trying to change a block to a green wool if it is hit by a snowball. Does anybody know how to do this? I only need the block change part not the checks. My code:

    1. @SuppressWarnings("deprecation")
    2. @EventHandler
    3. public void ChangeBlock(ProjectileHitEvent e) {
    4. if (!(e.getEntity() instanceof Snowball)) return;
    5. Snowball s = (Snowball) e.getEntity();
    6. if (!(s.getShooter() instanceof Player)) return;
    7. Player shooter = (Player) s.getShooter();
    8. if (!(shooter.getItemInHand().getType() == Material.IRON_HOE)) return;
    9. if (s.getLocation().getBlock().getType() == Material.AIR) return;
    11. }
    12. }
  2. Offline


  3. amhokies
    That doesn't even register in eclipse.. lol. I am also trying to set a spread of block changes too. I want it to create about 3-4 blocks that are changed. And remeber I want the wool to be lime.
  4. Offline


    You don't literally type "Block.setType"... it's not a static method. If you have a Block object, you use the method on the object you want to set the type of.
  5. Offline


    Your block object is "s.getLocation().getBlock()".
  6. GotRice amhokies Yes I understand, but if I do:

    1. Location l = s.getLocation().getBlock().getLocation();
    2. l.getBlock().setType(Material.WOOL);

    Then it will almost never set a block because for some reason the snowball seems to hit air before it hits a block and I made it if it hits air it cancels (Because this is a paintball arena so I don't want random floating wools). Also I don't know how to make the wool a lime color. And it doesn't set blocks around it to be wool. (I don't know how) If I do:

    1. Location l = s.getLocation().getBlock().getLocation();
    2. l.add(0, 0, 1); {
    3. if (l.getBlock().getType() == Material.AIR) return;
    4. l.getBlock().setType(Material.WOOL);

    It still won't work for reasons I don't know.
  7. Offline


    how about

    1. if(l.getBlock().getType() != Material.AIR)
    2. l.getBlock().setType(Material.WOOL);
  8. GotRice Nope, that's not working either. :( But do you know how to make it so it sets a lime wool instead of white? And sets blocks around the snowball hit like that too?
  9. Offline


    1. ItemStack wool = new ItemStack(Material.WOOOL);
    2. wool.setDurability(//Lime wools byte goes here);
  10. Offline


    A much easier way is:
    Wool w = new Wool();
    If you need it as a block,
    ItemStack is w.toItemStack();
  11. Offline


    As i heard projectile hit event does only call if a entity got hit?
  12. Jalau Aperx Voltex I still can't get it. The snowball always seems to hit air, so nothing happens. Really shouldn't be this hard right?
Thread Status:
Not open for further replies.

Share This Page