auto-fish module

auto-fish: Minecraft 26.3 cheat module, full source for every implementation (1 client: Meteor Client).

1 implementationPlayer

Clients with this module

Full module source: 1 implementation

Every implementation below is the complete module file, verbatim. Expand a client to read its code.

Meteor ClientPlayersrc/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoFish.javaJava · 274 lines · 9.2 KB

Automatically fishes for you.

Settingsauto-switchanti-breakauto-castcast-delaycast-delay-variancecatch-delaycatch-delay-variance
AutoFish.javaJava · Minecraft 26.2 · 274 lines · 9.2 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client).
3
 * Copyright (c) Meteor Development.
4
 */
5
6
package meteordevelopment.meteorclient.systems.modules.player;
7
8
import meteordevelopment.meteorclient.events.world.TickEvent;
9
import meteordevelopment.meteorclient.mixin.FishingHookAccessor;
10
import meteordevelopment.meteorclient.settings.BoolSetting;
11
import meteordevelopment.meteorclient.settings.IntSetting;
12
import meteordevelopment.meteorclient.settings.Setting;
13
import meteordevelopment.meteorclient.settings.SettingGroup;
14
import meteordevelopment.meteorclient.systems.modules.Categories;
15
import meteordevelopment.meteorclient.systems.modules.Module;
16
import meteordevelopment.meteorclient.utils.Utils;
17
import meteordevelopment.meteorclient.utils.player.InvUtils;
18
import meteordevelopment.meteorclient.utils.world.TickRate;
19
import meteordevelopment.orbit.EventHandler;
20
import net.minecraft.world.InteractionHand;
21
import net.minecraft.world.entity.projectile.FishingHook;
22
import net.minecraft.world.item.FishingRodItem;
23
import net.minecraft.world.item.ItemStack;
24
import net.minecraft.world.item.enchantment.Enchantments;
25
import org.jspecify.annotations.NullMarked;
26
import org.jspecify.annotations.Nullable;
27
28
@NullMarked
29
public class AutoFish extends Module {
30
    private final SettingGroup sgGeneral = settings.getDefaultGroup();
31
32
    private final Setting<Boolean> autoSwitch = sgGeneral.add(new BoolSetting.Builder()
33
        .name("auto-switch")
34
        .description("Automatically switch to a fishing rod.")
35
        .defaultValue(true)
36
        .build()
37
    );
38
39
    private final Setting<Boolean> antiBreak = sgGeneral.add(new BoolSetting.Builder()
40
        .name("anti-break")
41
        .description("Avoid using rods that would break if they were cast.")
42
        .defaultValue(true)
43
        .build()
44
    );
45
46
    private final Setting<Boolean> autoCast = sgGeneral.add(new BoolSetting.Builder()
47
        .name("auto-cast")
48
        .description("Automatically cast the fishing rod.")
49
        .defaultValue(true)
50
        .build()
51
    );
52
53
    private final Setting<Integer> castDelay = sgGeneral.add(new IntSetting.Builder()
54
        .name("cast-delay")
55
        .description("How long to wait between recasts if the bobber fails to land in water.")
56
        .defaultValue(14)
57
        .min(1)
58
        .sliderMax(60)
59
        .build()
60
    );
61
62
    private final Setting<Integer> castDelayVariance = sgGeneral.add(new IntSetting.Builder()
63
        .name("cast-delay-variance")
64
        .description("Maximum amount of randomness added to cast delay.")
65
        .defaultValue(0)
66
        .min(0)
67
        .sliderMax(30)
68
        .build()
69
    );
70
71
    private final Setting<Integer> catchDelay = sgGeneral.add(new IntSetting.Builder()
72
        .name("catch-delay")
73
        .description("How long to wait after hooking a fish to reel it in.")
74
        .defaultValue(6)
75
        .min(1)
76
        .sliderMax(20)
77
        .build()
78
    );
79
80
    private final Setting<Integer> catchDelayVariance = sgGeneral.add(new IntSetting.Builder()
81
        .name("catch-delay-variance")
82
        .description("Maximum amount of randomness added to catch delay.")
83
        .defaultValue(0)
84
        .min(0)
85
        .sliderMax(10) // Since the shortest Java edition catch window is 20 ticks, this is the highest possible variance that won't miss fish.
86
        .build()
87
    );
88
89
    private enum State {
90
        IDLE,
91
        WAITING_FOR_BITE,
92
        WAITING_TO_REEL
93
    }
94
95
    private State state = State.IDLE;
96
    private double castDelayLeft = 0.0;
97
    private double catchDelayLeft = 0.0;
98
99
    public AutoFish() {
100
        super(Categories.Player, "auto-fish", "Automatically fishes for you.");
101
    }
102
103
    @Override
104
    public void onActivate() {
105
        state = State.IDLE;
106
        castDelayLeft = 0.0;
107
        catchDelayLeft = 0.0;
108
    }
109
110
    @Override
111
    public void onDeactivate() {
112
        state = State.IDLE;
113
    }
114
115
    @EventHandler
116
    private void onTick(TickEvent.Pre event) {
117
        if (mc.player.fishing != null) handleFishing();
118
        else handleIdle();
119
    }
120
121
    private void handleIdle() {
122
        if (state != State.IDLE) state = State.IDLE;
123
124
        RodCandidate candidate = findBestRodCandidate();
125
        if (candidate == null) return;
126
        if (!prepareRod(candidate)) return;
127
        if (!autoCast.get()) return;
128
129
        if (castDelayLeft > 0) {
130
            castDelayLeft -= TickRate.INSTANCE.getTickRate() / 20.0;
131
            return;
132
        }
133
134
        cast();
135
    }
136
137
    private void handleFishing() {
138
        switch (state) {
139
            case IDLE -> state = State.WAITING_FOR_BITE;
140
            case WAITING_FOR_BITE -> {
141
                if (mc.player.fishing.getHookedIn() != null) {
142
                    reel();
143
                    return;
144
                }
145
146
                if (mc.player.fishing.currentState != FishingHook.FishHookState.BOBBING) return;
147
                if (((FishingHookAccessor) mc.player.fishing).meteor$hasCaughtFish()) {
148
                    catchDelayLeft = randomizeDelay(catchDelay.get(), catchDelayVariance.get());
149
                    state = State.WAITING_TO_REEL;
150
                }
151
            }
152
            case WAITING_TO_REEL -> {
153
                if (mc.player.fishing.getHookedIn() != null) {
154
                    reel();
155
                    return;
156
                }
157
158
                if (catchDelayLeft > 0) {
159
                    catchDelayLeft -= TickRate.INSTANCE.getTickRate() / 20.0;
160
                    return;
161
                }
162
163
                reel();
164
            }
165
        }
166
    }
167
168
    private void cast() {
169
        if (useRod()) state = State.WAITING_FOR_BITE;
170
    }
171
172
    private void reel() {
173
        if (useRod()) state = State.IDLE;
174
    }
175
176
    private boolean useRod() {
177
        RodCandidate candidate = findBestRodCandidate();
178
        if (candidate == null) return false;
179
        if (!prepareRod(candidate)) return false;
180
181
        mc.gameMode.useItem(mc.player, candidate.hand());
182
        castDelayLeft = randomizeDelay(castDelay.get(), castDelayVariance.get());
183
        return true;
184
    }
185
186
    @SuppressWarnings("BooleanMethodIsAlwaysInverted")
187
    private boolean prepareRod(RodCandidate candidate) {
188
        if (candidate.hand() == InteractionHand.OFF_HAND) return true;
189
        if (candidate.hotbarSlot() == mc.player.getInventory().getSelectedSlot()) return true;
190
        if (!autoSwitch.get()) return false;
191
192
        InvUtils.swap(candidate.hotbarSlot(), false);
193
        return candidate.hotbarSlot() == mc.player.getInventory().getSelectedSlot();
194
    }
195
196
    private boolean isUsableRod(ItemStack stack) {
197
        if (!(stack.getItem() instanceof FishingRodItem)) return false;
198
        return !antiBreak.get() || stack.getDamageValue() != stack.getMaxDamage() - 1;
199
    }
200
201
    private int scoreRod(ItemStack stack) {
202
        int score = 0;
203
204
        score += Utils.getEnchantmentLevel(stack, Enchantments.LUCK_OF_THE_SEA);
205
        score += Utils.getEnchantmentLevel(stack, Enchantments.LURE);
206
        score += Utils.getEnchantmentLevel(stack, Enchantments.MENDING);
207
        score += Utils.getEnchantmentLevel(stack, Enchantments.UNBREAKING);
208
209
        return score;
210
    }
211
212
    /// Finds the best rod candidate in the player's inventory and offhand.
213
    ///
214
    /// Tie-break order:
215
    /// 1. Selected hotbar slot
216
    /// 2. Remaining hotbar slots in stable 0..8 order
217
    /// 3. Offhand
218
    ///
219
    /// Candidates only replace the current best when they have a strictly higher score,
220
    /// preserving the ordering above for equal scores.
221
    private @Nullable RodCandidate findBestRodCandidate() {
222
        int selectedSlot = mc.player.getInventory().getSelectedSlot();
223
        RodCandidate best = null;
224
225
        ItemStack mainHandStack = mc.player.getMainHandItem();
226
        if (isUsableRod(mainHandStack)) {
227
            best = new RodCandidate(InteractionHand.MAIN_HAND, selectedSlot, scoreRod(mainHandStack));
228
        }
229
230
        for (int i = 0; i < 9; i++) {
231
            if (i == selectedSlot) continue;
232
233
            ItemStack stack = mc.player.getInventory().getItem(i);
234
            if (!isUsableRod(stack)) continue;
235
236
            int score = scoreRod(stack);
237
238
            if (best == null || score > best.score()) {
239
                best = new RodCandidate(InteractionHand.MAIN_HAND, i, score);
240
            }
241
        }
242
243
        ItemStack offhandStack = mc.player.getOffhandItem();
244
        if (isUsableRod(offhandStack)) {
245
            int score = scoreRod(offhandStack);
246
247
            if (best == null || score > best.score()) {
248
                best = new RodCandidate(InteractionHand.OFF_HAND, -1, score);
249
            }
250
        }
251
252
        return best;
253
    }
254
255
    private record RodCandidate(InteractionHand hand, int hotbarSlot, int score) {
256
    }
257
258
    private double randomizeDelay(int delay, int variance) {
259
        if (variance == 0) return delay;
260
261
        // Sample the standard normal distribution via Box-Muller transform
262
        double scale = Math.sqrt(-2 * Math.log(Utils.random(0.0001, 1.0)));
263
        double angle = Math.TAU * Utils.random(0.0, 1.0);
264
        double norm = scale * Math.cos(angle);
265
266
        // Clamp to 3 standard deviations and re-scale to [-3.0, +3.0]
267
        final double MAX_SD = 3.0;
268
        norm = Math.clamp(norm, -MAX_SD, MAX_SD) / MAX_SD;
269
270
        delay += Math.round((float) (norm * variance));
271
        return Math.max(1, delay);
272
    }
273
}
274