Skip to content

Commit 97b481f

Browse files
authored
Add random delay settings to AutoFish (#5980)
1 parent 6cfdeb9 commit 97b481f

1 file changed

Lines changed: 36 additions & 2 deletions

File tree

  • src/main/java/meteordevelopment/meteorclient/systems/modules/player

src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoFish.java

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ public class AutoFish extends Module {
5555
.build()
5656
);
5757

58+
private final Setting<Integer> castDelayVariance = sgGeneral.add(new IntSetting.Builder()
59+
.name("cast-delay-variance")
60+
.description("Maximum amount of randomness added to cast delay.")
61+
.defaultValue(0)
62+
.min(0)
63+
.sliderMax(30)
64+
.build()
65+
);
66+
5867
private final Setting<Integer> catchDelay = sgGeneral.add(new IntSetting.Builder()
5968
.name("catch-delay")
6069
.description("How long to wait after hooking a fish to reel it in.")
@@ -64,6 +73,15 @@ public class AutoFish extends Module {
6473
.build()
6574
);
6675

76+
private final Setting<Integer> catchDelayVariance = sgGeneral.add(new IntSetting.Builder()
77+
.name("catch-delay-variance")
78+
.description("Maximum amount of randomness added to catch delay.")
79+
.defaultValue(0)
80+
.min(0)
81+
.sliderMax(10) // Since the shortest Java edition catch window is 20 ticks, this is the highest possible variance that won't miss fish.
82+
.build()
83+
);
84+
6785
public AutoFish() {
6886
super(Categories.Player, "auto-fish", "Automatically fishes for you.");
6987
}
@@ -118,7 +136,7 @@ private void tryCatch() {
118136

119137
if (!wasHooked) {
120138
if (((FishingBobberEntityAccessor) mc.player.fishHook).meteor$hasCaughtFish()) {
121-
catchDelayLeft = catchDelay.get();
139+
catchDelayLeft = randomizeDelay(catchDelay.get(), catchDelayVariance.get());
122140
wasHooked = true;
123141
}
124142

@@ -136,7 +154,7 @@ private void tryCatch() {
136154
private void useRod() {
137155
Utils.rightClick();
138156
wasHooked = false;
139-
castDelayLeft = castDelay.get();
157+
castDelayLeft = randomizeDelay(castDelay.get(), castDelayVariance.get());
140158
}
141159

142160
private int findBestRod() {
@@ -166,4 +184,20 @@ private int findBestRod() {
166184

167185
return bestSlot;
168186
}
187+
188+
private double randomizeDelay(int delay, int variance) {
189+
if (variance == 0) return delay;
190+
191+
// Sample the standard normal distribution via Box-Muller transform
192+
double scale = Math.sqrt(-2 * Math.log(Utils.random(0.0001, 1.0)));
193+
double angle = Math.TAU * Utils.random(0.0, 1.0);
194+
double norm = scale * Math.cos(angle);
195+
196+
// Clamp to 3 standard deviations and re-scale to [-3.0, +3.0]
197+
final double MAX_SD = 3.0;
198+
norm = Math.clamp(norm, -MAX_SD, MAX_SD) / MAX_SD;
199+
200+
delay += Math.round((float)(norm * variance));
201+
return Math.max(1, delay);
202+
}
169203
}

0 commit comments

Comments
 (0)