aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/rosegoldaddons/utils/RotationUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/rosegoldaddons/utils/RotationUtils.java')
-rw-r--r--src/main/java/rosegoldaddons/utils/RotationUtils.java141
1 files changed, 86 insertions, 55 deletions
diff --git a/src/main/java/rosegoldaddons/utils/RotationUtils.java b/src/main/java/rosegoldaddons/utils/RotationUtils.java
index a9b2e78..2ead71f 100644
--- a/src/main/java/rosegoldaddons/utils/RotationUtils.java
+++ b/src/main/java/rosegoldaddons/utils/RotationUtils.java
@@ -1,52 +1,82 @@
package rosegoldaddons.utils;
-import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiChat;
import net.minecraft.client.gui.GuiIngameMenu;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.Entity;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.network.play.client.C03PacketPlayer;
-import net.minecraft.util.ChatComponentText;
import net.minecraft.util.MathHelper;
import net.minecraft.util.Vec3;
+import net.minecraftforge.client.event.RenderWorldLastEvent;
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import rosegoldaddons.Main;
-import java.security.Key;
-
public class RotationUtils {
static boolean working = false;
static boolean snek = false;
- static boolean antiafking = false;
+ public static Rotation startRot;
+ public static Rotation neededChange;
+ public static Rotation endRot;
+ public static long startTime;
+ public static long endTime;
+
+ @SubscribeEvent
+ public void onRender(RenderWorldLastEvent event) {
+ update();
+ }
- public static void antiAfk() {
- if (Minecraft.getMinecraft().currentScreen != null) {
- if (Minecraft.getMinecraft().currentScreen instanceof GuiIngameMenu || Minecraft.getMinecraft().currentScreen instanceof GuiChat) {
- } else {
- return;
+ //bing chilling thx apfel
+ public static void update() {
+ if (System.currentTimeMillis() <= endTime) {
+ if(startRot != null && endRot != null) {
+ Main.mc.thePlayer.rotationYaw = interpolate(startRot.getYaw(), endRot.getYaw());
+ Main.mc.thePlayer.rotationPitch = interpolate(startRot.getPitch(), endRot.getPitch());
}
- }
- if (snek) return;
- KeyBinding right = Minecraft.getMinecraft().gameSettings.keyBindRight;
- KeyBinding left = Minecraft.getMinecraft().gameSettings.keyBindLeft;
- new Thread(() -> {
- try {
- KeyBinding.setKeyBindState(right.getKeyCode(), true);
- Thread.sleep(50);
- KeyBinding.setKeyBindState(right.getKeyCode(), false);
- Thread.sleep(200);
- KeyBinding.setKeyBindState(left.getKeyCode(), true);
- Thread.sleep(50);
- KeyBinding.setKeyBindState(left.getKeyCode(), false);
- } catch (InterruptedException e) {
- e.printStackTrace();
+ } else {
+ if(startRot != null && endRot != null) {
+ Main.mc.thePlayer.rotationYaw = endRot.getYaw();
+ Main.mc.thePlayer.rotationPitch = endRot.getPitch();
+ reset();
}
- }).start();
+ }
}
+ private static void reset() {
+ startRot = null;
+ neededChange = null;
+ endRot = null;
+ }
+
+ private static float interpolate(float f, float t) {
+ float x = System.currentTimeMillis() - startTime;
+ float u = (f - t) / 2.0f;
+ return (float) (u * Math.cos((float) (x * Math.PI / (endTime - startTime))) - u + f);
+ }
+
+ public static void setup(Rotation rot, Long aimTime) {
+ startRot = new Rotation(Main.mc.thePlayer.rotationYaw, Main.mc.thePlayer.rotationPitch);
+ neededChange = getNeededChange(startRot, rot);
+ endRot = new Rotation(startRot.getYaw() + neededChange.getYaw(), startRot.getPitch() + neededChange.getPitch());
+ startTime = System.currentTimeMillis();
+ endTime = System.currentTimeMillis() + aimTime;
+ }
+
+ public static Rotation getNeededChange(Rotation startRot, Rotation endRot) {
+ float yawChng = (float) (wrapAngleTo180(endRot.getYaw()) - wrapAngleTo180(startRot.getYaw()));
+ if (yawChng <= -180.0F) {
+ yawChng += 360.0F;
+ } else if (yawChng > 180.0F) {
+ yawChng += -360.0F;
+ }
+
+ return new Rotation(yawChng, endRot.getPitch() - startRot.getPitch());
+ }
+
+
public static void shootEman() {
- if (Minecraft.getMinecraft().currentScreen != null) {
- if (Minecraft.getMinecraft().currentScreen instanceof GuiIngameMenu || Minecraft.getMinecraft().currentScreen instanceof GuiChat) {
+ if (Main.mc.currentScreen != null) {
+ if (Main.mc.currentScreen instanceof GuiIngameMenu || Main.mc.currentScreen instanceof GuiChat) {
} else {
return;
}
@@ -55,13 +85,13 @@ public class RotationUtils {
new Thread(() -> {
try {
snek = true;
- KeyBinding.setKeyBindState(Minecraft.getMinecraft().gameSettings.keyBindSneak.getKeyCode(), true);
+ KeyBinding.setKeyBindState(Main.mc.gameSettings.keyBindSneak.getKeyCode(), true);
Thread.sleep(50);
- KeyBinding.setKeyBindState(Minecraft.getMinecraft().gameSettings.keyBindSneak.getKeyCode(), false);
+ KeyBinding.setKeyBindState(Main.mc.gameSettings.keyBindSneak.getKeyCode(), false);
Thread.sleep(50);
- KeyBinding.setKeyBindState(Minecraft.getMinecraft().gameSettings.keyBindSneak.getKeyCode(), true);
+ KeyBinding.setKeyBindState(Main.mc.gameSettings.keyBindSneak.getKeyCode(), true);
Thread.sleep(50);
- KeyBinding.setKeyBindState(Minecraft.getMinecraft().gameSettings.keyBindSneak.getKeyCode(), false);
+ KeyBinding.setKeyBindState(Main.mc.gameSettings.keyBindSneak.getKeyCode(), false);
snek = false;
} catch (Exception e) {
e.printStackTrace();
@@ -70,8 +100,8 @@ public class RotationUtils {
}
public static void facePos(Vec3 vector) {
- if (Minecraft.getMinecraft().currentScreen != null) {
- if (Minecraft.getMinecraft().currentScreen instanceof GuiIngameMenu || Minecraft.getMinecraft().currentScreen instanceof GuiChat) {
+ if (Main.mc.currentScreen != null) {
+ if (Main.mc.currentScreen instanceof GuiIngameMenu || Main.mc.currentScreen instanceof GuiChat) {
} else {
return;
}
@@ -80,21 +110,22 @@ public class RotationUtils {
new Thread(() -> {
try {
working = true;
- double diffX = vector.xCoord - (Minecraft.getMinecraft()).thePlayer.posX;
- double diffY = vector.yCoord - (Minecraft.getMinecraft()).thePlayer.posY;
- double diffZ = vector.zCoord - (Minecraft.getMinecraft()).thePlayer.posZ;
+ double diffX = vector.xCoord - Main.mc.thePlayer.posX;
+ double diffY = vector.yCoord - (Main.mc.thePlayer.posY + Main.mc.thePlayer.getEyeHeight());
+ double diffZ = vector.zCoord - Main.mc.thePlayer.posZ;
double dist = Math.sqrt(diffX * diffX + diffZ * diffZ);
- float pitch = (float) -Math.atan2(dist, diffY);
- float yaw = (float) Math.atan2(diffZ, diffX);
- pitch = (float) wrapAngleTo180((pitch * 180F / Math.PI + 90) * -1 - Minecraft.getMinecraft().thePlayer.rotationPitch);
- yaw = (float) wrapAngleTo180((yaw * 180 / Math.PI) - 90 - Minecraft.getMinecraft().thePlayer.rotationYaw);
+ float pitch = (float) -(Math.atan2(diffY, dist) * 180.0D / Math.PI);
+ float yaw = (float) (Math.atan2(diffZ, diffX) * 180.0D / Math.PI - 90.0D);
+ pitch = MathHelper.wrapAngleTo180_float(pitch - Main.mc.thePlayer.rotationPitch);
+ yaw = MathHelper.wrapAngleTo180_float(yaw - Main.mc.thePlayer.rotationYaw);
for (int i = 0; i < Main.configFile.smoothLookVelocity; i++) {
- Minecraft.getMinecraft().thePlayer.rotationYaw += yaw / Main.configFile.smoothLookVelocity;
- Minecraft.getMinecraft().thePlayer.rotationPitch += pitch / Main.configFile.smoothLookVelocity;
+ Main.mc.thePlayer.rotationYaw += yaw / Main.configFile.smoothLookVelocity;
+ Main.mc.thePlayer.rotationPitch += pitch / Main.configFile.smoothLookVelocity;
Thread.sleep(1);
}
+ //setup(new Rotation(yaw, pitch), (long) Main.configFile.smoothLookVelocity);
working = false;
if (Main.endermanMacro) {
shootEman();
@@ -111,8 +142,8 @@ public class RotationUtils {
try {
working = true;
for (int i = 0; i < Main.configFile.smoothLookVelocity; i++) {
- Minecraft.getMinecraft().thePlayer.rotationYaw += yaw / Main.configFile.smoothLookVelocity;
- Minecraft.getMinecraft().thePlayer.rotationPitch += pitch / Main.configFile.smoothLookVelocity;
+ Main.mc.thePlayer.rotationYaw += yaw / Main.configFile.smoothLookVelocity;
+ Main.mc.thePlayer.rotationPitch += pitch / Main.configFile.smoothLookVelocity;
Thread.sleep(1);
}
working = false;
@@ -124,33 +155,33 @@ public class RotationUtils {
public static void faceEntity(Entity en) {
if (en instanceof EntityCreeper) {
- facePos(new Vec3(en.posX, en.posY - 1.5, en.posZ));
- } else {
facePos(new Vec3(en.posX, en.posY, en.posZ));
+ } else {
+ facePos(new Vec3(en.posX, en.posY + Main.mc.thePlayer.getEyeHeight(), en.posZ));
}
}
public static void packetFaceEntity(Entity en) {
if (en == null) return;
Vec3 vector = new Vec3(en.posX, en.posY - 1.5, en.posZ);
- if (Minecraft.getMinecraft().currentScreen != null) {
- if (Minecraft.getMinecraft().currentScreen instanceof GuiIngameMenu || Minecraft.getMinecraft().currentScreen instanceof GuiChat) {
+ if (Main.mc.currentScreen != null) {
+ if (Main.mc.currentScreen instanceof GuiIngameMenu || Main.mc.currentScreen instanceof GuiChat) {
} else {
return;
}
}
- double diffX = vector.xCoord - (Minecraft.getMinecraft()).thePlayer.posX;
- double diffY = vector.yCoord - (Minecraft.getMinecraft()).thePlayer.posY;
- double diffZ = vector.zCoord - (Minecraft.getMinecraft()).thePlayer.posZ;
+ double diffX = vector.xCoord - (Main.mc).thePlayer.posX;
+ double diffY = vector.yCoord - (Main.mc).thePlayer.posY;
+ double diffZ = vector.zCoord - (Main.mc).thePlayer.posZ;
double dist = Math.sqrt(diffX * diffX + diffZ * diffZ);
float pitch = (float) -Math.atan2(dist, diffY);
float yaw = (float) Math.atan2(diffZ, diffX);
- pitch = (float) wrapAngleTo180((pitch * 180F / Math.PI + 90) * -1 - Minecraft.getMinecraft().thePlayer.rotationPitch);
- yaw = (float) wrapAngleTo180((yaw * 180 / Math.PI) - 90 - Minecraft.getMinecraft().thePlayer.rotationYaw);
+ pitch = (float) wrapAngleTo180((pitch * 180F / Math.PI + 90) * -1 - Main.mc.thePlayer.rotationPitch);
+ yaw = (float) wrapAngleTo180((yaw * 180 / Math.PI) - 90 - Main.mc.thePlayer.rotationYaw);
- Minecraft.getMinecraft().thePlayer.sendQueue.addToSendQueue(new C03PacketPlayer.C05PacketPlayerLook(yaw, pitch, Minecraft.getMinecraft().thePlayer.onGround));
+ Main.mc.thePlayer.sendQueue.addToSendQueue(new C03PacketPlayer.C05PacketPlayerLook(yaw, pitch, Main.mc.thePlayer.onGround));
}