auto-gap module

auto-gap: 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/AutoGap.javaJava · 336 lines · 10.8 KB

Automatically eats Gaps or E-Gaps.

Settingsallow-egapalwayspause-auraspause-baritonebefore-expiryexpiry-thresholdpotions-regenerationpotions-fire-resistancepotions-absorptionhealth-enabledhealth-threshold
AutoGap.javaJava · Minecraft 26.2 · 336 lines · 10.8 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 it.unimi.dsi.fastutil.objects.ReferenceArrayList;
9
import meteordevelopment.meteorclient.events.entity.player.ItemUseCrosshairTargetEvent;
10
import meteordevelopment.meteorclient.events.world.TickEvent;
11
import meteordevelopment.meteorclient.pathing.PathManagers;
12
import meteordevelopment.meteorclient.settings.BoolSetting;
13
import meteordevelopment.meteorclient.settings.IntSetting;
14
import meteordevelopment.meteorclient.settings.Setting;
15
import meteordevelopment.meteorclient.settings.SettingGroup;
16
import meteordevelopment.meteorclient.systems.modules.Categories;
17
import meteordevelopment.meteorclient.systems.modules.Module;
18
import meteordevelopment.meteorclient.systems.modules.Modules;
19
import meteordevelopment.meteorclient.systems.modules.combat.AnchorAura;
20
import meteordevelopment.meteorclient.systems.modules.combat.BedAura;
21
import meteordevelopment.meteorclient.systems.modules.combat.CrystalAura;
22
import meteordevelopment.meteorclient.systems.modules.combat.KillAura;
23
import meteordevelopment.meteorclient.utils.Utils;
24
import meteordevelopment.meteorclient.utils.player.InvUtils;
25
import meteordevelopment.orbit.EventHandler;
26
import net.minecraft.core.Holder;
27
import net.minecraft.world.effect.MobEffect;
28
import net.minecraft.world.effect.MobEffectInstance;
29
import net.minecraft.world.effect.MobEffects;
30
import net.minecraft.world.item.Item;
31
import net.minecraft.world.item.ItemStack;
32
import net.minecraft.world.item.Items;
33
34
import java.util.List;
35
import java.util.Map;
36
37
public class AutoGap extends Module {
38
    @SuppressWarnings("unchecked")
39
    private static final Class<? extends Module>[] AURAS = new Class[]{KillAura.class, CrystalAura.class, AnchorAura.class, BedAura.class};
40
41
    private final SettingGroup sgGeneral = settings.getDefaultGroup();
42
    private final SettingGroup sgPotions = settings.createGroup("Potions");
43
    private final SettingGroup sgHealth = settings.createGroup("Health");
44
45
    // General
46
47
    private final Setting<Boolean> allowEgap = sgGeneral.add(new BoolSetting.Builder()
48
        .name("allow-egap")
49
        .description("Allow eating E-Gaps over Gaps if found.")
50
        .defaultValue(true)
51
        .build()
52
    );
53
54
    private final Setting<Boolean> always = sgGeneral.add(new BoolSetting.Builder()
55
        .name("always")
56
        .description("If it should always eat.")
57
        .defaultValue(false)
58
        .build()
59
    );
60
61
    private final Setting<Boolean> pauseAuras = sgGeneral.add(new BoolSetting.Builder()
62
        .name("pause-auras")
63
        .description("Pauses all auras when eating.")
64
        .defaultValue(true)
65
        .build()
66
    );
67
68
    private final Setting<Boolean> pauseBaritone = sgGeneral.add(new BoolSetting.Builder()
69
        .name("pause-baritone")
70
        .description("Pause baritone when eating.")
71
        .defaultValue(true)
72
        .build()
73
    );
74
75
    // Potions
76
    private final Setting<Boolean> beforeExpiry = sgPotions.add(new BoolSetting.Builder()
77
        .name("before-expiry")
78
        .description("If it should eat before potion effects expire.")
79
        .defaultValue(false)
80
        .build()
81
    );
82
83
    private final Setting<Integer> expiryThreshold = sgPotions.add(new IntSetting.Builder()
84
        .name("expiry-threshold")
85
        .description("Time in ticks before the potion effect expires to start eating.")
86
        .defaultValue(60)
87
        .min(0)
88
        .sliderMax(200)
89
        .visible(beforeExpiry::get)
90
        .build()
91
    );
92
93
    private final Setting<Boolean> potionsRegeneration = sgPotions.add(new BoolSetting.Builder()
94
        .name("potions-regeneration")
95
        .description("If it should eat when Regeneration runs out.")
96
        .defaultValue(false)
97
        .build()
98
    );
99
100
    private final Setting<Boolean> potionsFireResistance = sgPotions.add(new BoolSetting.Builder()
101
        .name("potions-fire-resistance")
102
        .description("If it should eat when Fire Resistance runs out. Requires E-Gaps.")
103
        .defaultValue(true)
104
        .visible(allowEgap::get)
105
        .build()
106
    );
107
108
    private final Setting<Boolean> potionsAbsorption = sgPotions.add(new BoolSetting.Builder()
109
        .name("potions-absorption")
110
        .description("If it should eat when Absorption runs out. Requires E-Gaps.")
111
        .defaultValue(false)
112
        .visible(allowEgap::get)
113
        .build()
114
    );
115
116
    // Health
117
118
    private final Setting<Boolean> healthEnabled = sgHealth.add(new BoolSetting.Builder()
119
        .name("health-enabled")
120
        .description("If it should eat when health drops below threshold.")
121
        .defaultValue(true)
122
        .build()
123
    );
124
125
    private final Setting<Integer> healthThreshold = sgHealth.add(new IntSetting.Builder()
126
        .name("health-threshold")
127
        .description("Health threshold to eat at. Includes absorption.")
128
        .defaultValue(20)
129
        .min(0)
130
        .sliderMax(40)
131
        .build()
132
    );
133
134
    private boolean requiresEGap;
135
136
    private boolean eating;
137
    private int slot, prevSlot;
138
139
    private final List<Class<? extends Module>> wasAura = new ReferenceArrayList<>();
140
    private boolean wasBaritone;
141
142
    public AutoGap() {
143
        super(Categories.Player, "auto-gap", "Automatically eats Gaps or E-Gaps.");
144
    }
145
146
    @Override
147
    public void onDeactivate() {
148
        if (eating) stopEating();
149
    }
150
151
    @EventHandler
152
    private void onTick(TickEvent.Pre event) {
153
        if (eating) {
154
            // If we are eating check if we should still be still eating
155
            if (shouldEat()) {
156
                // Check if the item in current slot is not gap or egap
157
                if (isNotGapOrEGap(mc.player.getInventory().getItem(slot))) {
158
                    // If not try finding a new slot
159
                    int slot = findSlot();
160
161
                    // If no valid slot was found then stop eating
162
                    if (slot == -1) {
163
                        stopEating();
164
                        return;
165
                    }
166
                    // Otherwise change to the new slot
167
                    else {
168
                        changeSlot(slot);
169
                    }
170
                }
171
172
                // Continue eating
173
                eat();
174
            }
175
            // If we shouldn't be eating anymore then stop
176
            else {
177
                stopEating();
178
            }
179
        } else {
180
            // If we are not eating check if we should start eating
181
            if (shouldEat()) {
182
                // Try to find a valid slot
183
                slot = findSlot();
184
185
                // If slot was found then start eating
186
                if (slot != -1) startEating();
187
            }
188
        }
189
    }
190
191
    @EventHandler
192
    private void onItemUseCrosshairTarget(ItemUseCrosshairTargetEvent event) {
193
        if (eating) event.target = null;
194
    }
195
196
    private void startEating() {
197
        prevSlot = mc.player.getInventory().getSelectedSlot();
198
        eat();
199
200
        // Pause auras
201
        wasAura.clear();
202
        if (pauseAuras.get()) {
203
            for (Class<? extends Module> klass : AURAS) {
204
                Module module = Modules.get().get(klass);
205
206
                if (module.isActive()) {
207
                    wasAura.add(klass);
208
                    module.toggle();
209
                }
210
            }
211
        }
212
213
        // Pause baritone
214
        wasBaritone = false;
215
        if (pauseBaritone.get() && PathManagers.get().isPathing()) {
216
            wasBaritone = true;
217
            PathManagers.get().pause();
218
        }
219
    }
220
221
    private void eat() {
222
        changeSlot(slot);
223
        setPressed(true);
224
        if (!mc.player.isUsingItem()) Utils.rightClick();
225
226
        eating = true;
227
    }
228
229
    private void stopEating() {
230
        changeSlot(prevSlot);
231
        setPressed(false);
232
233
        eating = false;
234
235
        // Resume auras
236
        if (pauseAuras.get()) {
237
            for (Class<? extends Module> klass : AURAS) {
238
                if (wasAura.contains(klass)) {
239
                    Modules.get().get(klass).enable();
240
                }
241
            }
242
        }
243
244
        // Resume baritone
245
        if (pauseBaritone.get() && wasBaritone) {
246
            PathManagers.get().resume();
247
        }
248
    }
249
250
    private void setPressed(boolean pressed) {
251
        mc.options.keyUse.setDown(pressed);
252
    }
253
254
    private void changeSlot(int slot) {
255
        InvUtils.swap(slot, false);
256
        this.slot = slot;
257
    }
258
259
    private boolean shouldEat() {
260
        requiresEGap = false;
261
262
        if (always.get()) return true;
263
        if (shouldEatPotions()) return true;
264
        return shouldEatHealth();
265
    }
266
267
    private boolean shouldEatPotions() {
268
        Map<Holder<MobEffect>, MobEffectInstance> effects = mc.player.getActiveEffectsMap();
269
270
        // Regeneration
271
        if (potionsRegeneration.get()) {
272
            MobEffectInstance effect = effects.get(MobEffects.REGENERATION);
273
            if (effect == null || (beforeExpiry.get() && effect.getDuration() <= expiryThreshold.get())) return true;
274
        }
275
276
        // Fire resistance
277
        if (potionsFireResistance.get()) {
278
            MobEffectInstance effect = effects.get(MobEffects.FIRE_RESISTANCE);
279
            if (effect == null || (beforeExpiry.get() && effect.getDuration() <= expiryThreshold.get())) {
280
                requiresEGap = true;
281
                return true;
282
            }
283
        }
284
285
        // Absorption
286
        if (potionsAbsorption.get()) {
287
            MobEffectInstance effect = effects.get(MobEffects.ABSORPTION);
288
            if (effect == null || (beforeExpiry.get() && effect.getDuration() <= expiryThreshold.get())) {
289
                requiresEGap = true;
290
                return true;
291
            }
292
        }
293
294
        return false;
295
    }
296
297
    private boolean shouldEatHealth() {
298
        if (!healthEnabled.get()) return false;
299
300
        int health = Math.round(mc.player.getHealth() + mc.player.getAbsorptionAmount());
301
        return health < healthThreshold.get();
302
    }
303
304
    private int findSlot() {
305
        for (int i = 0; i < 9; i++) {
306
            ItemStack stack = mc.player.getInventory().getItem(i);
307
308
            // Skip if item stack is empty
309
            if (stack.isEmpty()) continue;
310
311
            // Skip if item isn't a gap or egap
312
            if (isNotGapOrEGap(stack)) continue;
313
314
            Item item = stack.getItem();
315
316
            // If egap was found and allowEgapSetting is true we can return the current slot
317
            if (item == Items.ENCHANTED_GOLDEN_APPLE && allowEgap.get()) return i;
318
319
            // If gap was found and egap is not required we can return the current slot
320
            if (item == Items.GOLDEN_APPLE && !requiresEGap) return i;
321
        }
322
323
        // No suitable gap or egap found
324
        return -1;
325
    }
326
327
    private boolean isNotGapOrEGap(ItemStack stack) {
328
        Item item = stack.getItem();
329
        return item != Items.GOLDEN_APPLE && item != Items.ENCHANTED_GOLDEN_APPLE;
330
    }
331
332
    public boolean isEating() {
333
        return isActive() && eating;
334
    }
335
}
336