Advertisement
JackOUT

Untitled

Sep 21st, 2022
867
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1.     private void shootArrowFromBlock(final LivingEntity target, final Block block) {
  2.         final Location blockLocation = block.getLocation().clone().add(0.5, 1.4, 0.5);
  3.         final Location targetLocation = target.getEyeLocation().clone();
  4.         final double distance = blockLocation.distance(targetLocation);
  5.         final Vector vector = targetLocation.subtract(blockLocation).toVector().normalize();
  6.         final Arrow arrow = target.getWorld().spawnArrow(blockLocation, vector, 1, 0);
  7.         final Location arrowLocation = arrow.getLocation().clone();
  8.  
  9.         if (distance < 1.5) {
  10.             target.damage(arrow.getDamage());
  11.             target.setVelocity(targetLocation.subtract(blockLocation).toVector().normalize().multiply(-0.5));
  12.             arrow.remove();
  13.             return;
  14.         }
  15.        
  16.         for (int i = 0; i <= 10; i++)
  17.             if (arrow.getLocation().getBlock().getType() != Material.AIR)
  18.                 arrow.teleport(arrowLocation.add(vector.clone().add(new Vector(0, -0.1, 0)).normalize().multiply(0.05)));
  19.  
  20.         final double power = Math.pow(2, 0.04 * distance);
  21.         vector.multiply(power);
  22.         vector.add(new Vector(0, power * 0.15, 0));
  23.  
  24.         arrow.setVelocity(vector);
  25.         Common.runLater(80, arrow::remove);
  26.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement