How Can I Make Projectile Travel Farther Than Default Distance?

Discussion in 'Plugin Development' started by AaronL98, Jun 20, 2013.

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

    AaronL98

    Hey again, I'm pretty new to java but I'd say I'm making an alright start :) I've created a plugin that fires snowballs from a right click with hoe and was wondering how i would make the snowballs fly farther than they do already in Minecraft. Also is there a way to make them swerve maybe a little to the left, right or up? I would also love to know how i would implement when you shoot someone with the snowball hoe it will do X amount of damage, but still leaving normal snowballs thrown from hand doing no damage. Thanks.

    This is kinda urgent :l

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

    Tzeentchful

    I have answered a similar question before. I would spawn a snowball in the world and then set it's velocity relative to the way the player is looking. Here is my code.
    Code:java
    1. public static void shootSnowball(Double speed, Player player) {
    2. Location shootLocation = player.getEyeLocation();
    3. Vector directionVector = shootLocation.getDirection().normalize();
    4.  
    5. double startShift = 2;
    6. Vector shootShiftVector = new Vector(directionVector.getX() * startShift, directionVector.getY() * startShift, directionVector.getZ() * startShift);
    7. shootLocation = shootLocation.add(shootShiftVector.getX(), shootShiftVector.getY(), shootShiftVector.getZ());
    8.  
    9. Snowball snowball = shootLocation.getWorld().spawn(shootLocation, Snowball.class);
    10. snowball.setVelocity(directionVector.multiply(speed));
    11.  
    12. if(snowball instanceof Snowball){
    13. ((Snowball) snowball).setShooter(player);
    14. }
    15. }
     
  3. Offline

    AaronL98


    Code:java
    1. if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK){
    2. if (player.getItemInHand().getType() == Material.WOOD_HOE){
    3. if(player.getInventory().contains(Material.SNOW_BALL)){
    4. player.launchProjectile(Snowball.class);


    That's what my code is at (the main part) Would i need to change player.launchProjectile(Snowball.class); ?
     
  4. Offline

    Tzeentchful

    Totally remove that line and use my method.
    Code:java
    1. if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    2. if (player.getItemInHand().getType() == Material.WOOD_HOE) {
    3. if(player.getInventory().contains(Material.SNOW_BALL)) {
    4. shootSnowball(5.0, player); //change the 5.0 to set the speed of the snowball
     
  5. Offline

    AaronL98

    Thanks :) Works perfect. Any idea on how to make it swerve slightly up/down/left/right or how to make the snowball fired from the hoe and only the hoe, not right click with snowball in hand, deal X amount of damage to the player?

    shameful, yet urgent bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
Thread Status:
Not open for further replies.

Share This Page