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:

    Code:java
    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;
    10.  
    11. }
    12. }
     
  2. Offline

    amhokies

  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

    amhokies

    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

    GotRice

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

    Code:java
    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:

    Code:java
    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

    GotRice

    how about

    Code:java
    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

    Aperx

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

    Voltex

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

    Jalau

    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