Solved Change block on projectile impact

Discussion in 'Plugin Development' started by SuperJenBot, Aug 2, 2015.

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


    I was wondering what would be the best way to go about changing a block to another block when it is hit by a projectile, like an egg or a snowball. Any help would be much appreciated.
  2. @SuperJenBot ProjectileHitEvent
    Change the block that was hit
  3. Offline


    get the block at the location of the hit
    change block
  4. Offline


    @bwfcwalshy @SuperSniper I tried using the code below, it sort of works but it places a wool block above where the snowball hits instead of changing the block it hits. So if I hit a grass block with a snowball it will place a wool block on top of it. I would like the grass block itself to change to a wool block. Any idea on how to fix this?

    public class BlockChange implements Listener {
        public void snowballHit(ProjectileHitEvent e) {
            Block block = e.getEntity().getWorld().getBlockAt(e.getEntity().getLocation());
    Last edited: Aug 2, 2015
  5. Offline


    @bwfcwalshy Awesome so I got it working, but I have one more question. If I wanted it to change the ground in a 3x3 radius instead of just 1 block, how would I do this?
  6. Offline


    @SuperJenBot, that would require some fancy math. Math isn't my strong suit, but i'd bet @Chiller might be able to get this one.
  7. Offline


    I actually figured it out with a pretty primitive method, but it works. @Tecno_Wizard
  8. Offline


    @SuperJenBot Ya you just iterate over that 3x3 and check if sqrt(x^2 + y^2) <= 3!
  9. Offline


    Close, except in Java the ^ operator is actually the bitwise xor operator, not an exponentiation.
  10. Offline


    @Quantum64 Hahaha, dummy, that was pseudo code I was writing... Get smart.
Thread Status:
Not open for further replies.

Share This Page