Bouncing snowballs

Discussion in 'Plugin Development' started by randomman159, Aug 9, 2011.

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

    randomman159

    Haha typing this post title made me think of an epic snowball fight.

    Anyway, i tried this bit of code:

    World world = player.getWorld();
    snowball = world.spawn(player.getLocation(), Snowball.class);
    snowball.setBounce(true);


    The actual spawning of the snowball was working, but it says that setBounce doesn't exist.

    Snowball extends projectile though, and projectile has the setBounce method:

    http://jd.bukkit.org/apidocs/org/bukkit/entity/Projectile.html



    Anyone know the solution to my problem?
     
  2. Offline

    nisovin

    What type is your snowball variable?
     
  3. Offline

    randomman159

    Snowball

    should i put it as Projectile?

    EDIT: this didn't work either. Anyone have any ideas?
     
  4. Offline

    masteroftime

  5. Offline

    randomman159

    so no idea masteroftime?
     
  6. Offline

    masteroftime

    no sry

    I posted this problem on redmine.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 18, 2016
  7. Offline

    Shamebot

  8. Offline

    randomman159

    still no answer :(

    anyone got a clue why it says the function doesn't exist?
     
  9. Offline

    Shamebot

    What's your craftbukkit version?
     
  10. Offline

    randomman159

    erm, the server is running (according to when i run the batch file) Craftbukkit version git-Bukkit-0.0.0-904-g9277096-b953jnks (MC: 1.7.2)

    if that isn't it... i am still trying to work out where i can find the version :p
     
  11. Offline

    Shamebot

    That seems to be rather old, try it with the newest. Is this the craftbukkit you're compiling with?
     
  12. Offline

    randomman159

    oooh the bukkit version.. ill check that :)
    *checks*
    don't know the version, but i downloaded it just a few days ago. Gah im feeling newby :p

    so ill update the craftbukkit for the server and see's if it works

    EDIT: ok im pretty sure i had the latest version, still doesn't work. says method doesn't exist (i think i can't remember and am so tired... )
     
  13. Offline

    Shamebot

    It works for me.
     
  14. Offline

    masteroftime

    Damn it. I got the wrong repo. Thought I deleted that already.
     
  15. Offline

    Shamebot

    From looking on the code and a bit of testing it looks like doesBounce() only determines whether the entity sticks into the block if the ProjectileHitEvent was cancelled.
     
  16. Offline

    randomman159

    So wait is it actually "bouncing" and what approach do i take to get it to bounce?
     
  17. Offline

    Shamebot

    Cancel the ProjectileHitEvent
     
  18. Offline

    DrBowe

    What he's saying is that if you want it to bounce, you must first cancel the ProjectileHitEvent.
    So put in an EntityListener, and cancel all ProjectileHitEvents if it happens to be a snowball. Then, your previous method should work.

    EDIT:
    Ninjas everywhere :D
     
    Shamebot likes this.
  19. Offline

    randomman159

    erm, there is no setCancelled method for the ProjectileHitEvent class.
     
  20. Offline

    Shamebot

    Er, my bad it's the EntityDamageByEntityEvent, ill look into what happens if it hits a block.

    Turns out what doesBounce does in the code:
    Code:
     if (event.isCancelled()) {
                            stick = !projectile.doesBounce();
                        }
                    ...
                    if (stick) {
                        ;
                    }
    Right, nothing. You need implement bouncing in onProjectileEvent yourself :(.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 18, 2016
  21. Offline

    randomman159

    After
    All
    This...

    haha thanks for the help along the way Shamebot :D
     
Thread Status:
Not open for further replies.

Share This Page