Change speed of snowball

Discussion in 'Plugin Development' started by marknzl, Jan 11, 2015.

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

    marknzl

    Hey,

    So I want to launch the Snowball projectile but change the speed of it as well.
    Heres my code:
    Code:
    @EventHandler
        public void onGunUse(PlayerInteractEvent event) {
            Player player = event.getPlayer();
            if (!(event.getAction() == Action.RIGHT_CLICK_AIR)) return;
            if (!(player.getInventory().getItemInHand().getType() == Material.BLAZE_ROD)) return;
            player.launchProjectile(Snowball.class);
        }
     
  2. Code:
    Snowball snowball = (Snowball) player.launchProjectile(Snowball.class);
    
    Then you can set its velocity to your liking, I think by multiplying its current velocity by <x>, e,g. 10
     
  3. Offline

    unrealdesign

    Using your code:
    Code:
        @EventHandler
        public void onGunUse(PlayerInteractEvent event) {
            Player player = event.getPlayer();
            if (!(event.getAction() == Action.RIGHT_CLICK_AIR)) return;
            if (!(player.getInventory().getItemInHand().getType() == Material.BLAZE_ROD)) return;
            player.launchProjectile(Snowball.class).setVelocity(new Vector());
        }
     
  4. Offline

    Krizeh

    Code:
    @EventHandler
        public void onGunUse(PlayerInteractEvent event) {
            Player player = event.getPlayer();
            if (!(event.getAction() == Action.RIGHT_CLICK_AIR)) return;
            if (!(player.getInventory().getItemInHand().getType() == Material.BLAZE_ROD)) return;
            Snowball s = player.launchProjectile(Snowball.class));
            s.setVelocity(player.getLocation().getDirection().multiply(2.0D));
        }
     
  5. You're just setting its velocity to a blank vector... Make the Snowball object so you can refer to it.
    Example:
    Code:
    Snowball snowball = (Snowball) player.launchProjectile(Snowball.class);
    snowball.setVelocity(snowball.getVelocity().multiply(10D));
    
    That may work, I'm not sure. However, Krizeh's version should almost definitely work.
     
  6. Offline

    mythbusterma

    @KingFaris11

    Nah, his code isn't quite as eloquent. Yours is certainly the correct solution, as, by definition, the velocity of the snowball launched by Entity#launchProjectile() has the same unit vector as the Player's direction. His is just ugly looking extra work, and would probably be slower than the normal projectile launch, with only an absolute velocity of 2 u/s.
     
    KingFaris11 likes this.
  7. Offline

    unrealdesign

    @mythbusterma @KingFaris11 These two are the exact same thing:
    Code:
    Snowball s = player.launchProjectile(Snowball.class));
    s.setVelocity(player.getLocation().getDirection().multiply(2.0D));
    Code:
    (SnowBall) (player.launchProjectile(Snowball.class)).setVelocity(player.getLocation().getDirection().multiply(2.0D));
    The only difference is I didn't create another varaible
     
  8. Offline

    mythbusterma

    @unrealdesign

    And you unnecessarily reference the player again, but that's a small qualm. Again, that's going to be slower than the actual launch speed as well, and doesn't reflect the responsibility of the server to determine the speed of it.

    Also, the two snippets you present are the same, and are not comparing KingFarris's solution to your "solution."

    Plus, his is much easier to read.
     
  9. Offline

    unrealdesign

    It wasn't my "solution" I'm just saying putting it on one line is fine. He only wants to do one change to the object, so there is no need to create a new variable for it. If you can't read it then you must not know Java.
     
  10. I'm sure you'll do well in a developing company, make sure to tell your employer "If you can't read ugly code, you must not know Java."
     
  11. Offline

    unrealdesign

    Well I already am employed and have a job and no one has complained because everyone has a little something called respect. What is worse is people like you complaining over the smallest things and making a problem out of nothing because you think your opinion is the only correct opinion. I bet I could go through your plugins that you've made and point out hundreds of "dumb" things, but you know what, I won't because I have respect. People read things differently and comprehend things differently, I just ask that you respect that at a minimum.
     
  12. Funny you talk about respect, I replied in that tone due to you suggesting myth does not know Java. That's disrespect and stupidity. It's not the fact that you can't read ugly code, it's just the psychological thinking that you feel a bit dodgy reading it. Also, I was saying IF you tell your employer that, never said that anyone's complained like you made the implication I did. Finally, Oracle programming conventions should be the best guideline for programming and in my opinion, people should follow it, regardless of their background.

    Anyway, this is getting off-topic, goodbye. If you want to continue, private message.
     
  13. Offline

    Krizeh


    It was an example, he's free to set the multiplier to whatever he wants.
     
Thread Status:
Not open for further replies.

Share This Page