diff options
| author | RoseGoldIsntGay <yoavkau@gmail.com> | 2022-02-04 14:17:32 +0200 |
|---|---|---|
| committer | RoseGoldIsntGay <yoavkau@gmail.com> | 2022-02-04 14:17:32 +0200 |
| commit | 20894963147ef84a7ad7d578191de69a856f6403 (patch) | |
| tree | 34bf1488f2042630c595f557543d324510bd1429 /src/main/java/rosegoldaddons/utils | |
| parent | f4b58abbda168b01513a5ac2ba2870bc00df7074 (diff) | |
| download | RGA-20894963147ef84a7ad7d578191de69a856f6403.tar.gz RGA-20894963147ef84a7ad7d578191de69a856f6403.tar.bz2 RGA-20894963147ef84a7ad7d578191de69a856f6403.zip | |
2.7.1
Diffstat (limited to 'src/main/java/rosegoldaddons/utils')
3 files changed, 140 insertions, 115 deletions
diff --git a/src/main/java/rosegoldaddons/utils/RotationUtils.java b/src/main/java/rosegoldaddons/utils/RotationUtils.java index 2ead71f..874f238 100644 --- a/src/main/java/rosegoldaddons/utils/RotationUtils.java +++ b/src/main/java/rosegoldaddons/utils/RotationUtils.java @@ -15,64 +15,6 @@ import rosegoldaddons.Main; public class RotationUtils { static boolean working = false; static boolean snek = 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(); - } - - //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()); - } - } else { - if(startRot != null && endRot != null) { - Main.mc.thePlayer.rotationYaw = endRot.getYaw(); - Main.mc.thePlayer.rotationPitch = endRot.getPitch(); - reset(); - } - } - } - - 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 (Main.mc.currentScreen != null) { @@ -136,23 +78,6 @@ public class RotationUtils { }).start(); } - public static void faceAngles(double yaw, double pitch) { - if (working) return; - new Thread(() -> { - try { - working = true; - for (int i = 0; i < Main.configFile.smoothLookVelocity; i++) { - Main.mc.thePlayer.rotationYaw += yaw / Main.configFile.smoothLookVelocity; - Main.mc.thePlayer.rotationPitch += pitch / Main.configFile.smoothLookVelocity; - Thread.sleep(1); - } - working = false; - } catch (Exception e) { - e.printStackTrace(); - } - }).start(); - } - public static void faceEntity(Entity en) { if (en instanceof EntityCreeper) { facePos(new Vec3(en.posX, en.posY, en.posZ)); @@ -160,44 +85,4 @@ public class RotationUtils { 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 (Main.mc.currentScreen != null) { - if (Main.mc.currentScreen instanceof GuiIngameMenu || Main.mc.currentScreen instanceof GuiChat) { - } else { - return; - } - } - - 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 - Main.mc.thePlayer.rotationPitch); - yaw = (float) wrapAngleTo180((yaw * 180 / Math.PI) - 90 - Main.mc.thePlayer.rotationYaw); - - Main.mc.thePlayer.sendQueue.addToSendQueue(new C03PacketPlayer.C05PacketPlayerLook(yaw, pitch, Main.mc.thePlayer.onGround)); - - } - - public static void faceEntity2(Entity en) { - facePos(new Vec3(en.posX, en.posY + en.getEyeHeight() - en.height / 1.5D, en.posZ)); - } - - private static double wrapAngleTo180(double angle) { - angle %= 360; - while (angle >= 180) { - angle -= 360; - } - while (angle < -180) { - angle += 360; - } - return angle; - } - } diff --git a/src/main/java/rosegoldaddons/utils/ScoreboardUtils.java b/src/main/java/rosegoldaddons/utils/ScoreboardUtils.java index 38312a7..a9d7d63 100644 --- a/src/main/java/rosegoldaddons/utils/ScoreboardUtils.java +++ b/src/main/java/rosegoldaddons/utils/ScoreboardUtils.java @@ -8,6 +8,8 @@ import net.minecraft.scoreboard.ScoreObjective; import net.minecraft.scoreboard.ScorePlayerTeam; import net.minecraft.scoreboard.Scoreboard; import net.minecraft.util.StringUtils; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; import rosegoldaddons.Main; import java.util.ArrayList; @@ -20,6 +22,7 @@ import java.util.stream.Collectors; */ public class ScoreboardUtils { + public static boolean inSkyblock = false; public static String cleanSB(String scoreboard) { char[] nvString = StringUtils.stripControlCodes(scoreboard).toCharArray(); StringBuilder cleaned = new StringBuilder(); @@ -61,4 +64,23 @@ public class ScoreboardUtils { return lines; } + + public static String removeFormatting(String input) { + return input.replaceAll("ยง[0-9a-fk-or]", ""); + } + + private int ticks = 0; + @SubscribeEvent + public void onTick(TickEvent.ClientTickEvent event) { + if(ticks % 20 == 0) { + if(Main.mc.thePlayer != null && Main.mc.theWorld != null) { + ScoreObjective scoreboardObj = Main.mc.theWorld.getScoreboard().getObjectiveInDisplaySlot(1); + if(scoreboardObj != null) { + inSkyblock = removeFormatting(scoreboardObj.getDisplayName()).contains("SKYBLOCK"); + } + } + ticks = 0; + } + ticks++; + } } diff --git a/src/main/java/rosegoldaddons/utils/ShadyRotation.java b/src/main/java/rosegoldaddons/utils/ShadyRotation.java new file mode 100644 index 0000000..fdacc59 --- /dev/null +++ b/src/main/java/rosegoldaddons/utils/ShadyRotation.java @@ -0,0 +1,118 @@ +package rosegoldaddons.utils; + +import net.minecraft.entity.Entity; +import net.minecraft.util.BlockPos; +import net.minecraft.util.Vec3; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; +import rosegoldaddons.Main; + +public class ShadyRotation { + private static float pitchDifference; + public static float yawDifference; + private static int ticks = -1; + private static int tickCounter = 0; + private static Runnable callback = null; + + public static boolean running = false; + + public static class Rotation { + public float pitch; + public float yaw; + + public Rotation(float pitch, float yaw) { + this.pitch = pitch; + this.yaw = yaw; + } + } + + private static double wrapAngleTo180(double angle) { + return angle - Math.floor(angle / 360 + 0.5) * 360; + } + + public static Rotation getRotationToBlock(BlockPos block) { + double diffX = block.getX() - Main.mc.thePlayer.posX + 0.5; + double diffY = block.getY() - Main.mc.thePlayer.posY + 0.5 - Main.mc.thePlayer.getEyeHeight(); + double diffZ = block.getZ() - Main.mc.thePlayer.posZ + 0.5; + 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); + yaw = (float) wrapAngleTo180((yaw * 180 / Math.PI) - 90); + + return new Rotation(pitch, yaw); + } + + public static Rotation getRotationToEntity(Entity entity) { + double diffX = entity.posX - Main.mc.thePlayer.posX; + double diffY = entity.posY + entity.getEyeHeight() - Main.mc.thePlayer.posY - Main.mc.thePlayer.getEyeHeight(); + double diffZ = entity.posZ - 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); + yaw = (float) wrapAngleTo180((yaw * 180 / Math.PI) - 90); + + return new Rotation(pitch, yaw); + } + + public static Rotation vec3ToRotation(Vec3 vec) { + double diffX = vec.xCoord - Main.mc.thePlayer.posX; + double diffY = vec.yCoord - Main.mc.thePlayer.posY - Main.mc.thePlayer.getEyeHeight(); + double diffZ = vec.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); + yaw = (float) wrapAngleTo180((yaw * 180 / Math.PI) - 90); + + return new Rotation(pitch, yaw); + } + + public static void smoothLook(Rotation rotation, int ticks, Runnable callback) { + if(ticks == 0) { + look(rotation); + callback.run(); + return; + } + + ShadyRotation.callback = callback; + + pitchDifference = rotation.pitch - Main.mc.thePlayer.rotationPitch; + yawDifference = rotation.yaw - Main.mc.thePlayer.rotationYaw; + + ShadyRotation.ticks = ticks * 20; + ShadyRotation.tickCounter = 0; + } + + public static void smartLook(Rotation rotation, int ticksPer180, Runnable callback) { + float rotationDifference = Math.max( + Math.abs(rotation.pitch - Main.mc.thePlayer.rotationPitch), + Math.abs(rotation.yaw - Main.mc.thePlayer.rotationYaw) + ); + smoothLook(rotation, (int) (rotationDifference / 180 * ticksPer180), callback); + } + + public static void look(Rotation rotation) { + Main.mc.thePlayer.rotationPitch = rotation.pitch; + Main.mc.thePlayer.rotationYaw = rotation.yaw; + } + + @SubscribeEvent + public void onTick(TickEvent event) { + if(Main.mc.thePlayer == null) return; + if(tickCounter < ticks) { + running = true; + Main.mc.thePlayer.rotationPitch += pitchDifference / ticks; + Main.mc.thePlayer.rotationYaw += yawDifference / ticks; + tickCounter++; + } else if(callback != null) { + running = false; + callback.run(); + callback = null; + } + } +} |
