Advertisement
GamingLVScripts

RotationUtil

Apr 1st, 2024
553
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.33 KB | None | 0 0
  1. package tech.atani.client.utility.player.rotation;
  2.  
  3. import net.minecraft.entity.Entity;
  4. import net.minecraft.util.*;
  5. import tech.atani.client.utility.interfaces.Methods;
  6. import tech.atani.client.utility.math.random.RandomUtil;
  7. import tech.atani.client.utility.player.PlayerHandler;
  8. import tech.atani.client.utility.player.raytrace.RaytraceUtil;
  9.  
  10. import java.security.NoSuchAlgorithmException;
  11. import java.security.SecureRandom;
  12.  
  13. public class RotationUtil implements Methods {
  14.  
  15.     public static Vec3 getBestVector(Vec3 look, AxisAlignedBB axisAlignedBB) {
  16.         return new Vec3(MathHelper.clamp(look.xCoord, axisAlignedBB.minX, axisAlignedBB.maxX), MathHelper.clamp(look.yCoord, axisAlignedBB.minY, axisAlignedBB.maxY), MathHelper.clamp(look.zCoord, axisAlignedBB.minZ, axisAlignedBB.maxZ));
  17.     }
  18.  
  19.     public static Vec3 toDirection(float yaw, float pitch) {
  20.         float f = MathHelper.cos(-yaw * 0.017453292F - (float) Math.PI);
  21.         float f1 = MathHelper.sin(-yaw * 0.017453292F - (float) Math.PI);
  22.         float f2 = -MathHelper.cos(-pitch * 0.017453292F);
  23.         float f3 = MathHelper.sin(-pitch * 0.017453292F);
  24.         return new Vec3((double) (f1 * f2), (double) f3, (double) (f * f2));
  25.     }
  26.  
  27.     public static Vec3 getVectorForRotation(float yaw, float pitch) {
  28.         float f = MathHelper.cos((float) (-yaw * 0.017163291F - Math.PI));
  29.         float f2 = MathHelper.sin((float) (-yaw * 0.017163291F - Math.PI));
  30.         float f3 = -MathHelper.cos(-pitch * 0.017163291F);
  31.         float f4 = MathHelper.sin(-pitch * 0.017163291F);
  32.         return new Vec3(f2 * f3, f4, f * f3);
  33.     }
  34.  
  35.     public static float[] getRotation(Vec3 aimVector) {
  36.         double x = aimVector.xCoord - mc.thePlayer.posX;
  37.         double y = aimVector.yCoord - (mc.thePlayer.posY + (double) mc.thePlayer.getEyeHeight());
  38.         double z = aimVector.zCoord - mc.thePlayer.posZ;
  39.  
  40.         double d3 = MathHelper.sqrt(x * x + z * z);
  41.         float f = (float) (MathHelper.atan2(z, x) * (180 / Math.PI)) - 90.0F;
  42.         float f1 = (float) (-(MathHelper.atan2(y, d3) * (180 / Math.PI)));
  43.         f1 = MathHelper.clamp(f1, -90, 90);
  44.         return new float[]{f, f1};
  45.     }
  46.  
  47.     public static float[] getRotation(Entity entity, String vectorMode, float heightDivisor, boolean mouseFix, boolean heuristics, double minRandomYaw, double maxRandomYaw, double minRandomPitch, double maxRandomPitch, boolean prediction, float minYaw, float maxYaw, float minPitch, float maxPitch, boolean snapYaw, boolean snapPitch) {
  48.         Vec3 aimVector = getBestVector(mc.thePlayer.getPositionEyes(1F), entity.getEntityBoundingBox());
  49.         switch (vectorMode) {
  50.             case "Bruteforce":
  51.                 for (double yPercent = 1; yPercent >= 0; yPercent -= 0.25) {
  52.                     for (double xPercent = 1; xPercent >= -0.5; xPercent -= 0.5) {
  53.                         for (double zPercent = 1; zPercent >= -0.5; zPercent -= 0.5) {
  54.                             Vec3 tempVec = new Vec3(xPercent, yPercent, zPercent);
  55.                             if (RaytraceUtil.rayCast(1F, getRotation(tempVec)).typeOfHit == MovingObjectPosition.MovingObjectType.ENTITY) {
  56.                                 aimVector = tempVec;
  57.                             }
  58.                         }
  59.                     }
  60.                 }
  61.                 break;
  62.             case "Head":
  63.                 aimVector = new Vec3(entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ);
  64.                 break;
  65.             case "Torso":
  66.                 aimVector = new Vec3(entity.posX, entity.posY + entity.getEyeHeight() / 2d, entity.posZ);
  67.                 break;
  68.             case "Feet":
  69.                 aimVector = new Vec3(entity.posX, entity.posY, entity.posZ);
  70.                 break;
  71.             case "Custom":
  72.                 aimVector = new Vec3(entity.posX, entity.posY + entity.getEyeHeight() / heightDivisor, entity.posZ);
  73.                 break;
  74.             case "Random":
  75.                 double x = RandomUtil.randomBetween(0, 0.4) - 0.2;
  76.                 double y = RandomUtil.randomBetween(0, 1) + 1;
  77.                 double z = RandomUtil.randomBetween(0, 0.4) - 0.2;
  78.                 aimVector = new Vec3(entity.posX + x, entity.posY + y, entity.posZ + z);
  79.                 break;
  80.         }
  81.         aimVector.xCoord += RandomUtil.randomBetween(minRandomYaw, maxRandomYaw);
  82.         aimVector.yCoord += RandomUtil.randomBetween(minRandomPitch, maxRandomPitch);
  83.         aimVector.zCoord += RandomUtil.randomBetween(minRandomYaw, maxRandomYaw);
  84.         double x = aimVector.xCoord - mc.thePlayer.posX;
  85.         double y = aimVector.yCoord - (mc.thePlayer.posY + (double) mc.thePlayer.getEyeHeight());
  86.         double z = aimVector.zCoord - mc.thePlayer.posZ;
  87.  
  88.         if (prediction) {
  89.             final boolean targetIsSprinting = entity.isSprinting();
  90.             final boolean playerIsSprinting = mc.thePlayer.isSprinting();
  91.  
  92.             final float walkingSpeed = 0.10000000149011612f;
  93.             final float targetSpeed = targetIsSprinting ? 1.25f : walkingSpeed;
  94.             final float playerSpeed = playerIsSprinting ? 1.25f : walkingSpeed;
  95.  
  96.             final float targetPredictedX = (float) ((entity.posX - entity.prevPosX) * targetSpeed);
  97.             final float targetPredictedZ = (float) ((entity.posZ - entity.prevPosZ) * targetSpeed);
  98.             final float playerPredictedX = (float) ((mc.thePlayer.posX - mc.thePlayer.prevPosX) * playerSpeed);
  99.             final float playerPredictedZ = (float) ((mc.thePlayer.posZ - mc.thePlayer.prevPosZ) * playerSpeed);
  100.  
  101.             if (targetPredictedX != 0.0f && targetPredictedZ != 0.0f || playerPredictedX != 0.0f && playerPredictedZ != 0.0f) {
  102.                 x += targetPredictedX + playerPredictedX;
  103.                 z += targetPredictedZ + playerPredictedZ;
  104.             }
  105.         }
  106.  
  107.         if (heuristics) {
  108.             try {
  109.                 x += SecureRandom.getInstanceStrong().nextDouble() * 0.1;
  110.                 y += SecureRandom.getInstanceStrong().nextDouble() * 0.1;
  111.                 z += SecureRandom.getInstanceStrong().nextDouble() * 0.1;
  112.             } catch (NoSuchAlgorithmException e) {
  113.                 e.printStackTrace();
  114.             }
  115.         }
  116.  
  117.         double d3 = MathHelper.sqrt(x * x + z * z);
  118.         float yawSpeed = (float) RandomUtil.randomBetween(minYaw, maxYaw);
  119.         float pitchSpeed = (float) RandomUtil.randomBetween(minPitch, maxPitch);
  120.         float f = (float) (MathHelper.atan2(z, x) * (180 / Math.PI)) - 90.0F;
  121.         float f1 = (float) (-(MathHelper.atan2(y, d3) * (180 / Math.PI)));
  122.         final float deltaYaw = (((f - PlayerHandler.yaw) + 540) % 360) - 180;
  123.         final float deltaPitch = f1 - PlayerHandler.pitch;
  124.         final float yawDistance = MathHelper.clamp_float(deltaYaw, -yawSpeed, yawSpeed);
  125.         final float pitchDistance = MathHelper.clamp_float(deltaPitch, -pitchSpeed, pitchSpeed);
  126.         float calcYaw = snapYaw ? f : PlayerHandler.yaw + yawDistance;
  127.         float calcPitch = snapPitch ? f1 : PlayerHandler.pitch + pitchDistance;
  128.         calcPitch = MathHelper.clamp(calcPitch, -90, 90);
  129.         if (!mouseFix)
  130.             return new float[]{calcYaw, calcPitch};
  131.         return applyMouseFix(calcYaw, calcPitch);
  132.     }
  133.  
  134.     public static float[] applyMouseFix(float newYaw, float newPitch) {
  135.         final float sensitivity = Math.max(0.001F, mc.gameSettings.mouseSensitivity);
  136.         final int deltaYaw = (int) ((newYaw - PlayerHandler.yaw) / ((sensitivity * (sensitivity >= 0.5 ? sensitivity : 1) / 2)));
  137.         final int deltaPitch = (int) ((newPitch - PlayerHandler.pitch) / ((sensitivity * (sensitivity >= 0.5 ? sensitivity : 1) / 2))) * -1;
  138.         final float f = sensitivity * 0.6F + 0.2F;
  139.         final float f1 = f * f * f * 8.0F;
  140.         final float f2 = (float) deltaYaw * f1;
  141.         final float f3 = (float) deltaPitch * f1;
  142.  
  143.         final float endYaw = (float) ((double) PlayerHandler.yaw + (double) f2 * 0.15);
  144.         float endPitch = (float) ((double) PlayerHandler.pitch - (double) f3 * 0.15);
  145.         endPitch = MathHelper.clamp(endPitch, -90, 90);
  146.         return new float[]{endYaw, endPitch};
  147.     }
  148.  
  149.     public static float[] updateRotationSimple(float newYaw, float newPitch, float speed) {
  150.         return RotationUtil.updateRotationSimple(PlayerHandler.yaw, newYaw, speed, PlayerHandler.pitch, newPitch, speed);
  151.     }
  152.  
  153.     public static float[] updateRotationSimple(float oldYaw, float newYaw, float yawSpeed, float oldPitch, float newPitch, float pitchSpeed) {
  154.         return new float[] {updateRotation(oldYaw, newYaw, yawSpeed), updateRotation(oldPitch, newPitch, pitchSpeed)};
  155.     }
  156.  
  157.     public static float getDistanceToLastPitch(final float pitch) {
  158.         return Math.abs(pitch - PlayerHandler.pitch);
  159.     }
  160.  
  161.     public static void resetRotations(float yaw, float pitch, boolean silent) {
  162.         if(silent) {
  163.             mc.thePlayer.rotationYaw = yaw - yaw % 360 + mc.thePlayer.rotationYaw % 360;
  164.         } else {
  165.             mc.thePlayer.rotationYaw = yaw;
  166.             mc.thePlayer.rotationPitch = pitch;
  167.         }
  168.     }
  169.  
  170.     public static float updateRotation(float oldRot, float newRot, float speed) {
  171.         float f = MathHelper.wrapDegrees(newRot - oldRot);
  172.  
  173.         if (f > (float) speed) {
  174.             f = (float) speed;
  175.         }
  176.  
  177.         if (f < -(float) speed) {
  178.             f = -(float) speed;
  179.         }
  180.  
  181.         return oldRot + f;
  182.     }
  183.  
  184. }
  185.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement