Advertisement
JackOUT

Untitled

Sep 18th, 2022
770
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.36 KB | None | 0 0
  1.     private void shootArrow(final LivingEntity target, final Block block) {
  2.         if (target != null) {
  3.             final Location blockLocation = block.getLocation().add(0.5, 1.5, 0.5);
  4.             final Location targetLocation = target.getLocation().clone().add(-0.5, 1, -0.5);
  5.             final double distance = blockLocation.distance(targetLocation);
  6.             final Vector vector = targetLocation.subtract(block.getLocation()).toVector().normalize().multiply(1.5);
  7.             final Arrow arrow = block.getWorld().spawnArrow(blockLocation, vector, 1, 0);
  8.             final Location arrowLocation = arrow.getLocation().clone();
  9.  
  10.             if (distance < 4) {
  11.                 arrow.teleport(blockLocation.clone().add(0, 0.5, 0));
  12.                 vector.add(new Vector(0, -0.8, 0));
  13.             } else {
  14.                 for (int i = 0; i <= 10; i++)
  15.                     if (arrow.getLocation().getBlock().getType() != Material.AIR)
  16.                         arrow.teleport(arrowLocation.add(vector.clone().add(new Vector(0, -0.1, 0)).normalize().multiply(0.1)));
  17.  
  18.                 if (distance >= 4 && distance <= 10)
  19.                     vector.add(new Vector(0, -0.16, 0));
  20.                 else if (distance > 10 && distance <= 18)
  21.                     vector.add(new Vector(0, -0.12, 0)).multiply(1.6);
  22.                 else if (distance > 18 && distance <= 25)
  23.                     vector.add(new Vector(0, 0, 0)).multiply(2);
  24.                 else if (distance > 25)
  25.                     vector.add(new Vector(0, 0.02, 0)).multiply(2);
  26.             }
  27.  
  28.             arrow.setVelocity(vector);
  29.             Common.runLater(80, arrow::remove);
  30.         }
  31.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement