Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void shootArrowFromBlock(final LivingEntity target, final Block block) {
- final Location blockLocation = block.getLocation().clone().add(0.5, 1.4, 0.5);
- final Location targetLocation = target.getEyeLocation().clone();
- final double distance = blockLocation.distance(targetLocation);
- final Vector vector = targetLocation.subtract(blockLocation).toVector().normalize();
- final Arrow arrow = target.getWorld().spawnArrow(blockLocation, vector, 1, 0);
- final Location arrowLocation = arrow.getLocation().clone();
- if (distance < 1.5) {
- target.damage(arrow.getDamage());
- target.setVelocity(targetLocation.subtract(blockLocation).toVector().normalize().multiply(-0.5));
- arrow.remove();
- return;
- }
- 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.05)));
- final double power = Math.pow(2, 0.04 * distance);
- vector.multiply(power);
- vector.add(new Vector(0, power * 0.15, 0));
- arrow.setVelocity(vector);
- Common.runLater(80, arrow::remove);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement