diff options
author | olim <bobq4582@gmail.com> | 2024-05-24 15:41:07 +0100 |
---|---|---|
committer | olim <bobq4582@gmail.com> | 2024-07-01 14:26:13 +0100 |
commit | f7910f5e7d9efd1f3b55c07db896576c81e51f46 (patch) | |
tree | 0831a908e210184a5eab3ab9a41a50f28f4f6852 /src/main/java/de | |
parent | f8a95bc502530f14d6edc08855127a67a5f7cf99 (diff) | |
download | Skyblocker-f7910f5e7d9efd1f3b55c07db896576c81e51f46.tar.gz Skyblocker-f7910f5e7d9efd1f3b55c07db896576c81e51f46.tar.bz2 Skyblocker-f7910f5e7d9efd1f3b55c07db896576c81e51f46.zip |
improve control helper
re work how the control helper works to give a smother and hopefully more accurate guess of where to aim
Diffstat (limited to 'src/main/java/de')
-rw-r--r-- | src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/ControlTestHelper.java | 50 | ||||
-rw-r--r-- | src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DojoManager.java | 7 |
2 files changed, 47 insertions, 10 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/ControlTestHelper.java b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/ControlTestHelper.java index cc37ef64..d2b0b8aa 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/ControlTestHelper.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/ControlTestHelper.java @@ -12,25 +12,61 @@ import java.awt.*; public class ControlTestHelper { private static WitherSkeletonEntity correctWitherSkeleton; - private static long pingMultiplier; + private static long ping; + private static Vec3d lastTargetPos; + private static Vec3d lastPos; + private static Vec3d aimOffset; protected static void reset() { correctWitherSkeleton = null; - pingMultiplier = 0; + ping = 0; + lastTargetPos = null; + lastPos = null; + aimOffset = null; } + /** + * Find the correct WitherSkeleton entity when it spawns to start tracking it + * + * @param entity spawned entity + */ protected static void onEntitySpawn(Entity entity) { if (entity instanceof WitherSkeletonEntity witherSkeleton && correctWitherSkeleton == null) { correctWitherSkeleton = witherSkeleton; - pingMultiplier = Util.getMeasuringTimeMs() / 100000; + ping = Util.getMeasuringTimeMs(); + aimOffset = new Vec3d(0, 0, 0); } } - protected static void render(WorldRenderContext context) { + /** + * update the aim offset for the wither skeleton based on ping + */ + protected static void update() { if (correctWitherSkeleton != null) { - Vec3d movementVector = correctWitherSkeleton.getPos().subtract(new Vec3d(correctWitherSkeleton.prevX, correctWitherSkeleton.prevY, correctWitherSkeleton.prevZ)); - Vec3d offset = movementVector.multiply(pingMultiplier); - Vec3d aimPos = correctWitherSkeleton.getEyePos().add(offset); + //smoothly adjust the ping throughout the test + ping = (ping + Util.getMeasuringTimeMs()) / 2; + if (lastPos != null) { + lastTargetPos = aimOffset; + double ping = (double) ControlTestHelper.ping / 1000000; + //find distance between last position and current position of skeleton + Vec3d movementVector = correctWitherSkeleton.getPos().subtract(lastPos).multiply(1, 0.1, 1); + //adjust the vector to current ping (20 / 3 is used because that is how many times this is updated a second. Every 3 ticks) + movementVector = movementVector.multiply((double) 20 / 3 * ping); + //smoothly adjust the aim offset based on the new value + aimOffset = (aimOffset.add(movementVector)).multiply(0.5); + } + lastPos = correctWitherSkeleton.getPos(); + } + } + + /** + * Renders a line from the cursor where the player should aim + * + * @param context render context + */ + protected static void render(WorldRenderContext context) { + if (correctWitherSkeleton != null && aimOffset != null && lastTargetPos != null) { + Vec3d aimPos = correctWitherSkeleton.getEyePos().add(aimOffset); RenderHelper.renderLineFromCursor(context, aimPos, Color.LIGHT_GRAY.getColorComponents(new float[]{0, 0, 0}), 1, 3); } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DojoManager.java b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DojoManager.java index 8cbfca7b..3de425ec 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DojoManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DojoManager.java @@ -125,9 +125,10 @@ public class DojoManager { if (Utils.getLocation() != Location.CRIMSON_ISLE || !inArena) { return; } - if (currentChallenge == DojoChallenges.STAMINA) { - StaminaTestHelper.update(); - } + switch (currentChallenge) { + case STAMINA -> StaminaTestHelper.update(); + case CONTROL -> ControlTestHelper.update(); + }; } /** |