funkemunky

SkiddedUtils.java

Sep 9th, 2019
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.17 KB | None | 0 0
  1. import cc.funkemunky.api.utils.MathUtils;
  2. import org.bukkit.Location;
  3. import org.bukkit.entity.LivingEntity;
  4. import org.bukkit.entity.Player;
  5. import org.bukkit.util.Vector;
  6.  
  7. public class SkiddedUtils {
  8.  
  9.     /*public static double[] cursor(Player player, LivingEntity entity) {
  10.         Location entityLoc = entity.getLocation().add(0.0D, entity.getEyeHeight(), 0.0D);
  11.         Location playerLoc = player.getLocation().add(0.0D, player.getEyeHeight(), 0.0D);
  12.         Vector playerRotation = new Vector(playerLoc.getYaw(), playerLoc.getPitch(), 0.0F);
  13.         Vector expectedRotation = getRotation(playerLoc, entityLoc);
  14.         double deltaYaw = clamp180(playerRotation.getX() - expectedRotation.getX());
  15.         double deltaPitch = clamp180(playerRotation.getY() - expectedRotation.getY());
  16.         double horizontalDistance = MathUtilsDL.getHorizontalDistance(playerLoc, entityLoc);
  17.         double distance = getDistance3D(playerLoc, entityLoc);
  18.         double offsetX = deltaYaw * horizontalDistance * distance;
  19.         double offsetY = deltaPitch * Math.abs(Math.sqrt(entityLoc.getY() - playerLoc.getY())) * distance;
  20.         return new double[]{Math.abs(offsetX), Math.abs(offsetY)};
  21.     }*/
  22.  
  23.     public static double[] cursor(Player player, double dividend, LivingEntity entity) {
  24.         Location entityLoc = entity.getLocation().add(0.0D, entity.getEyeHeight(), 0.0D);
  25.         Location playerLoc = player.getLocation().add(0.0D, player.getEyeHeight(), 0.0D);
  26.  
  27.         Vector playerRotation = new Vector(playerLoc.getYaw(), playerLoc.getPitch(), 0.0F);
  28.         Vector expectedRotation = getRotation(playerLoc, entityLoc);
  29.  
  30.         double deltaYaw = clamp180(playerRotation.getX() - expectedRotation.getX() / dividend);
  31.         double deltaPitch = clamp180(playerRotation.getY() - expectedRotation.getY());
  32.  
  33.         double horizontalDistance = MathUtils.getHorizontalDistance(playerLoc, entityLoc);
  34.         double distance = getDistance3D(playerLoc, entityLoc);
  35.  
  36.         double offsetX = deltaYaw * horizontalDistance * distance;
  37.         double offsetY = deltaPitch * Math.abs(Math.sqrt(entityLoc.getY() - playerLoc.getY())) * distance;
  38.  
  39.         return new double[]{Math.abs(offsetX), Math.abs(offsetY)};
  40.     }
  41.  
  42.     public static double getDistance3D(Location one, Location two) {
  43.         double toReturn = 0.0D;
  44.         double xSqr = (two.getX() - one.getX()) * (two.getX() - one.getX());
  45.         double ySqr = (two.getY() - one.getY()) * (two.getY() - one.getY());
  46.         double zSqr = (two.getZ() - one.getZ()) * (two.getZ() - one.getZ());
  47.         double sqrt = Math.sqrt(xSqr + ySqr + zSqr);
  48.         toReturn = Math.abs(sqrt);
  49.         return toReturn;
  50.     }
  51.  
  52.     public static Vector getRotation(Location one, Location two) {
  53.         double dx = two.getX() - one.getX();
  54.         double dy = two.getY() - one.getY();
  55.         double dz = two.getZ() - one.getZ();
  56.         double distanceXZ = Math.sqrt(dx * dx + dz * dz);
  57.         float yaw = (float) (Math.atan2(dz, dx) * 180.0D / 3.141592653589793D) - 90.0F;
  58.         float pitch = (float) -(Math.atan2(dy, distanceXZ) * 180.0D / 3.141592653589793D);
  59.         return new Vector(yaw, pitch, 0.0F);
  60.     }
  61.  
  62.     public static double clamp180(double theta) {
  63.         theta %= 360.0D;
  64.         if (theta >= 180.0D) {
  65.             theta -= 360.0D;
  66.         }
  67.         if (theta < -180.0D) {
  68.             theta += 360.0D;
  69.         }
  70.         return theta;
  71.     }
  72.  
  73.     public static double getAimbotoffset(Location playerLocLoc, double playerEyeHeight, LivingEntity entity) {
  74.         Location entityLoc = entity.getLocation().add(0.0D, entity.getEyeHeight(), 0.0D);
  75.         Location playerLoc = playerLocLoc.add(0.0D, playerEyeHeight, 0.0D);
  76.  
  77.         Vector playerRotation = new Vector(playerLoc.getYaw(), playerLoc.getPitch(), 0.0F);
  78.         Vector expectedRotation = getRotation(playerLoc, entityLoc);
  79.  
  80.         double deltaYaw = clamp180(playerRotation.getX() - expectedRotation.getX());
  81.  
  82.         double horizontalDistance = MathUtils.getHorizontalDistance(playerLoc, entityLoc);
  83.         double distance = getDistance3D(playerLoc, entityLoc);
  84.  
  85.         double offsetX = deltaYaw * horizontalDistance * distance;
  86.  
  87.         return offsetX;
  88.     }
  89.  
  90.     public static double getAimbotoffset2(Location playerLocLoc, double playerEyeHeight, LivingEntity entity) {
  91.         Location entityLoc = entity.getLocation().add(0.0D, entity.getEyeHeight(), 0.0D);
  92.         Location playerLoc = playerLocLoc.add(0.0D, playerEyeHeight, 0.0D);
  93.  
  94.         Vector playerRotation = new Vector(playerLoc.getYaw(), playerLoc.getPitch(), 0.0F);
  95.         Vector expectedRotation = getRotation(playerLoc, entityLoc);
  96.  
  97.         double deltaPitch = clamp180(playerRotation.getY() - expectedRotation.getY());
  98.  
  99.         double distance = getDistance3D(playerLoc, entityLoc);
  100.  
  101.         double offsetY = deltaPitch * Math.abs(Math.sqrt(entityLoc.getY() - playerLoc.getY())) * distance;
  102.  
  103.         return offsetY;
  104.     }
  105.  
  106.     public static double[] getOffsetsOffCursor(Player player, LivingEntity entity) {
  107.         Location entityLoc = entity.getLocation().add(0.0D, entity.getEyeHeight(), 0.0D);
  108.         Location playerLoc = player.getLocation().add(0.0D, player.getEyeHeight(), 0.0D);
  109.  
  110.         Vector playerRotation = new Vector(playerLoc.getYaw(), playerLoc.getPitch(), 0.0F);
  111.         Vector expectedRotation = getRotation(playerLoc, entityLoc);
  112.  
  113.         double deltaYaw = clamp180(playerRotation.getX() - expectedRotation.getX());
  114.         double deltaPitch = clamp180(playerRotation.getY() - expectedRotation.getY());
  115.  
  116.         double horizontalDistance = MathUtils.getHorizontalDistance(playerLoc, entityLoc);
  117.         double distance = getDistance3D(playerLoc, entityLoc);
  118.  
  119.         double offsetX = deltaYaw * horizontalDistance * distance;
  120.         double offsetY = deltaPitch * Math.abs(Math.sqrt(entityLoc.getY() - playerLoc.getY())) * distance;
  121.  
  122.         return new double[]{Math.abs(offsetX), Math.abs(offsetY)};
  123.     }
  124.  
  125.     public static double getOffsetOffCursor(Player player, LivingEntity entity) {
  126.         double offset = 0.0D;
  127.         double[] offsets = getOffsetsOffCursor(player, entity);
  128.  
  129.         offset += offsets[0];
  130.         offset += offsets[1];
  131.  
  132.         return offset;
  133.     }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment