Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void shootArrow(final LivingEntity target, final Block block) {
- if (target != null) {
- final Location blockLocation = block.getLocation().add(0.5, 1.5, 0.5);
- final Location targetLocation = target.getLocation().clone().add(-0.5, 1, -0.5);
- final double distance = blockLocation.distance(targetLocation);
- final Vector vector = targetLocation.subtract(block.getLocation()).toVector().normalize().multiply(1.5);
- final Arrow arrow = block.getWorld().spawnArrow(blockLocation, vector, 1, 0);
- final Location arrowLocation = arrow.getLocation().clone();
- if (distance < 4) {
- arrow.teleport(blockLocation.clone().add(0, 0.5, 0));
- vector.add(new Vector(0, -0.8, 0));
- } else {
- for (int i = 0; i <= 10; i++)
- if (arrow.getLocation().getBlock().getType() != Material.AIR)
- arrow.teleport(arrowLocation.add(vector.clone().add(new Vector(0, -0.1, 0)).normalize().multiply(0.1)));
- if (distance >= 4 && distance <= 10)
- vector.add(new Vector(0, -0.16, 0));
- else if (distance > 10 && distance <= 18)
- vector.add(new Vector(0, -0.12, 0)).multiply(1.6);
- else if (distance > 18 && distance <= 25)
- vector.add(new Vector(0, 0, 0)).multiply(2);
- else if (distance > 25)
- vector.add(new Vector(0, 0.02, 0)).multiply(2);
- }
- arrow.setVelocity(vector);
- Common.runLater(80, arrow::remove);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement