AutoGap module

AutoGap: Minecraft 26.3 cheat module, full source for every implementation (1 client: OfflineClient).

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.

OfflineClientPLAYERsrc/main/java/com/jellypudding/offlineclient/modules/player/AutoGap.javaJava · 253 lines · 8.9 KB

Eats golden apples to hold your buffs and your health up.

SettingsAlwaysHealthChoiceAbsorptionRegenerationFire resistanceExpiryKeep heldPause combatNo slowdown
AutoGap.javaJava · Minecraft 26.2 · 253 lines · 8.9 KB · complete file, verbatimOriginal ↗
1
package com.jellypudding.offlineclient.modules.player;
2
3
import com.jellypudding.offlineclient.event.Subscribe;
4
import com.jellypudding.offlineclient.event.events.TickEvent;
5
import com.jellypudding.offlineclient.module.Category;
6
import com.jellypudding.offlineclient.module.Module;
7
import com.jellypudding.offlineclient.setting.BoolSetting;
8
import com.jellypudding.offlineclient.setting.EnumSetting;
9
import com.jellypudding.offlineclient.setting.NumberSetting;
10
import com.jellypudding.offlineclient.util.EntityUtil;
11
import com.jellypudding.offlineclient.util.InventoryUtil;
12
import com.jellypudding.offlineclient.util.Modules;
13
import com.jellypudding.offlineclient.util.UseHold;
14
import net.minecraft.core.Holder;
15
import net.minecraft.world.effect.MobEffect;
16
import net.minecraft.world.effect.MobEffectInstance;
17
import net.minecraft.world.effect.MobEffects;
18
import net.minecraft.world.item.ItemStack;
19
import net.minecraft.world.item.Items;
20
21
// Eats golden apples to hold buffs up.
22
// Only the enchanted apple grants fire resistance.
23
public final class AutoGap extends Module {
24
25
    // Ticks to wait after a bite whilst the effects land. A laggy server needs a moment.
26
    private static final int SETTLE_TICKS = 20;
27
28
    // Minimum ticks between two apples. A slow server has time to register one.
29
    private static final int MEAL_GAP = 100;
30
31
    public enum Choice { PLAIN_FIRST, PLAIN_ONLY, ENCHANTED_FIRST, ENCHANTED_ONLY }
32
33
    private final BoolSetting always = new BoolSetting("Always",
34
        "Eats apples back to back for as long as the module is on whatever your health or effects.",
35
        false);
36
    private final NumberSetting health = new NumberSetting("Health",
37
        "Eat at or below this many hearts. Zero turns it off.", 7, 0, 10, 0.5, " hearts")
38
        .min(0).max(20)
39
        .unless(always);
40
    private final EnumSetting<Choice> choice = new EnumSetting<>("Choice",
41
        "Which apple to reach for.", Choice.PLAIN_FIRST)
42
        .describe(Choice.PLAIN_FIRST, "Eats a plain apple and only takes an enchanted one when there is none.")
43
        .describe(Choice.PLAIN_ONLY, "Never eats an enchanted apple.")
44
        .describe(Choice.ENCHANTED_FIRST, "Eats an enchanted apple and falls back to a plain one.")
45
        .describe(Choice.ENCHANTED_ONLY, "Never eats a plain apple.");
46
    private final BoolSetting absorption = new BoolSetting("Absorption",
47
        "Eat to keep the absorption effect topped up.", true)
48
        .unless(always);
49
    private final BoolSetting regeneration = new BoolSetting("Regeneration",
50
        "Eat to keep the regeneration effect topped up.", false)
51
        .unless(always);
52
    private final BoolSetting fireResistance = new BoolSetting("Fire resistance",
53
        "Eat to keep the fire resistance effect topped up. Only an enchanted apple gives it.", false)
54
        .visibleWhen(() -> !always.isOn() && !choice.is(Choice.PLAIN_ONLY));
55
    private final NumberSetting expiry = new NumberSetting("Expiry",
56
        "Start eating this many ticks before an effect runs out.", 60, 0, 200, 10, " ticks")
57
        .min(0)
58
        .unless(always);
59
    private final BoolSetting hold = new BoolSetting("Keep held",
60
        "Stay on the apple slot between bites.", true);
61
    private final BoolSetting pauseCombat = new BoolSetting("Pause combat",
62
        "Holds the combat modules back whilst you eat.", true);
63
    private final BoolSetting noSlowdown = new BoolSetting("No slowdown",
64
        "Keeps your normal speed whilst an apple goes down.", false);
65
66
    private boolean eating;
67
    private final UseHold use = new UseHold();
68
    private boolean needsEnchanted;
69
    private int settle;
70
    private int lastMeal = Integer.MIN_VALUE / 2;
71
    private final InventoryUtil.HotbarLoan loan = new InventoryUtil.HotbarLoan();
72
73
    public AutoGap() {
74
        super("AutoGap", "Eats golden apples to hold your buffs and your health up.", Category.PLAYER);
75
        addSettings(always, health, choice, absorption, regeneration, fireResistance, expiry, hold,
76
            pauseCombat, noSlowdown);
77
        searchTags("gapple", "golden apple", "egap");
78
    }
79
80
    public boolean isEating() {
81
        return isEnabled() && eating && pauseCombat.isOn();
82
    }
83
84
    public boolean isBusy() {
85
        return isEnabled() && eating;
86
    }
87
88
    // Read by LocalPlayerMixin to stop the apple slowing you. Manual bites count too.
89
    public boolean suppressesSlowdown() {
90
        if (!isEnabled() || !noSlowdown.isOn() || mc.player == null || !mc.player.isUsingItem()) {
91
            return false;
92
        }
93
        ItemStack using = mc.player.getUseItem();
94
        return using.is(Items.GOLDEN_APPLE) || using.is(Items.ENCHANTED_GOLDEN_APPLE);
95
    }
96
97
    @Override
98
    public String getSuffix() {
99
        return eating ? "eating" : null;
100
    }
101
102
    @Override
103
    protected void onDisable() {
104
        stopEating();
105
    }
106
107
    @Subscribe
108
    private void onTick(TickEvent event) {
109
        if (!inGame() || mc.player.isSpectator()) {
110
            stopEating();
111
            return;
112
        }
113
        // A fresh world hands you a player whose tick count starts again at zero.
114
        if (mc.player.tickCount < lastMeal) {
115
            lastMeal = Integer.MIN_VALUE / 2;
116
        }
117
        if (mc.player.isDeadOrDying()) {
118
            // Respawn rebuilds the inventory and restarts the tick count.
119
            loan.forget();
120
            stopEating();
121
            settle = 0;
122
            lastMeal = Integer.MIN_VALUE / 2;
123
            return;
124
        }
125
        if (settle > 0) {
126
            settle--;
127
            return;
128
        }
129
        if (eating) {
130
            continueEating();
131
            return;
132
        }
133
        if (handBusy()) {
134
            return;
135
        }
136
        if (!InventoryUtil.inventoryFree()) {
137
            return;
138
        }
139
140
        needsEnchanted = false;
141
        if (!wantsApple()) {
142
            loan.giveBack();
143
            return;
144
        }
145
        // Health that is actually low is never made to wait. A buff top up is.
146
        if (!always.isOn() && !EntityUtil.healthAtOrBelow(health.getValue())
147
            && mc.player.tickCount - lastMeal < MEAL_GAP) {
148
            return;
149
        }
150
        int slot = findApple();
151
        if (slot == -1) {
152
            loan.giveBack();
153
            return;
154
        }
155
        beginEating(slot);
156
    }
157
158
    private boolean handBusy() {
159
        return Modules.feeding(this);
160
    }
161
162
    private boolean wantsApple() {
163
        if (always.isOn() || EntityUtil.healthAtOrBelow(health.getValue())) {
164
            return true;
165
        }
166
        if (absorption.isOn() && isRunningOut(MobEffects.ABSORPTION)) {
167
            return true;
168
        }
169
        if (fireResistance.isOn() && !choice.is(Choice.PLAIN_ONLY)
170
            && isRunningOut(MobEffects.FIRE_RESISTANCE)) {
171
            needsEnchanted = true;
172
            return true;
173
        }
174
        return regeneration.isOn() && isRunningOut(MobEffects.REGENERATION);
175
    }
176
177
    private boolean isRunningOut(Holder<MobEffect> effect) {
178
        MobEffectInstance instance = mc.player.getEffect(effect);
179
        return instance == null || instance.getDuration() <= expiry.getInt();
180
    }
181
182
    private void beginEating(int slot) {
183
        if (!loan.select(slot)) {
184
            return;
185
        }
186
        eating = true;
187
        use.begin();
188
    }
189
190
    private void continueEating() {
191
        ItemStack held = mc.player.getInventory().getSelectedItem();
192
        if (mc.gui.screen() != null || !isApple(held)) {
193
            stopEating();
194
            return;
195
        }
196
        if (!use.tick()) {
197
            finishBite();
198
        }
199
    }
200
201
    private void finishBite() {
202
        boolean keep = hold.isOn() && !loan.isLent();
203
        use.release();
204
        eating = false;
205
        settle = SETTLE_TICKS;
206
        lastMeal = mc.player.tickCount;
207
        if (!keep) {
208
            loan.giveBack();
209
        }
210
    }
211
212
    private void stopEating() {
213
        if (eating) {
214
            use.release();
215
            eating = false;
216
        }
217
        loan.giveBack();
218
    }
219
220
    private int findApple() {
221
        int plain = -1;
222
        int enchanted = -1;
223
        for (int i = 0; i < InventoryUtil.WHOLE_INVENTORY; i++) {
224
            ItemStack stack = mc.player.getInventory().getItem(i);
225
            if (plain == -1 && stack.is(Items.GOLDEN_APPLE)) {
226
                plain = i;
227
            } else if (enchanted == -1 && stack.is(Items.ENCHANTED_GOLDEN_APPLE)) {
228
                enchanted = i;
229
            }
230
        }
231
        if (needsEnchanted || choice.is(Choice.ENCHANTED_ONLY)) {
232
            return enchanted;
233
        }
234
        if (choice.is(Choice.PLAIN_ONLY)) {
235
            return plain;
236
        }
237
        if (choice.is(Choice.ENCHANTED_FIRST)) {
238
            return enchanted != -1 ? enchanted : plain;
239
        }
240
        return plain != -1 ? plain : enchanted;
241
    }
242
243
    private boolean isApple(ItemStack stack) {
244
        if (needsEnchanted || choice.is(Choice.ENCHANTED_ONLY)) {
245
            return stack.is(Items.ENCHANTED_GOLDEN_APPLE);
246
        }
247
        if (choice.is(Choice.PLAIN_ONLY)) {
248
            return stack.is(Items.GOLDEN_APPLE);
249
        }
250
        return stack.is(Items.GOLDEN_APPLE) || stack.is(Items.ENCHANTED_GOLDEN_APPLE);
251
    }
252
}
253