auto-armor module

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

1 implementationCombat

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 ClientCombatsrc/main/java/meteordevelopment/meteorclient/systems/modules/combat/AutoArmor.javaJava · 334 lines · 12.3 KB

Automatically equips armor.

Settingspreferred-protectionswap-delayavoided-enchantmentsblast-prot-leggingsanti-breakignore-elytra
AutoArmor.javaJava · Minecraft 26.2 · 334 lines · 12.3 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.combat;
7
8
import it.unimi.dsi.fastutil.objects.Object2IntMap;
9
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
10
import meteordevelopment.meteorclient.events.world.TickEvent;
11
import meteordevelopment.meteorclient.settings.*;
12
import meteordevelopment.meteorclient.systems.modules.Categories;
13
import meteordevelopment.meteorclient.systems.modules.Module;
14
import meteordevelopment.meteorclient.systems.modules.Modules;
15
import meteordevelopment.meteorclient.systems.modules.player.ChestSwap;
16
import meteordevelopment.meteorclient.utils.Utils;
17
import meteordevelopment.meteorclient.utils.player.InvUtils;
18
import meteordevelopment.orbit.EventHandler;
19
import net.minecraft.core.Holder;
20
import net.minecraft.core.component.DataComponents;
21
import net.minecraft.resources.ResourceKey;
22
import net.minecraft.tags.ItemTags;
23
import net.minecraft.world.entity.EquipmentSlot;
24
import net.minecraft.world.entity.ai.attributes.Attributes;
25
import net.minecraft.world.item.ItemStack;
26
import net.minecraft.world.item.Items;
27
import net.minecraft.world.item.component.ItemAttributeModifiers;
28
import net.minecraft.world.item.enchantment.Enchantment;
29
import net.minecraft.world.item.enchantment.Enchantments;
30
31
import java.util.Arrays;
32
import java.util.Comparator;
33
import java.util.Set;
34
35
public class AutoArmor extends Module {
36
    private final SettingGroup sgGeneral = settings.getDefaultGroup();
37
38
    private final Setting<Protection> preferredProtection = sgGeneral.add(new EnumSetting.Builder<Protection>()
39
        .name("preferred-protection")
40
        .description("Which type of protection to prefer.")
41
        .defaultValue(Protection.Protection)
42
        .build()
43
    );
44
45
    private final Setting<Integer> delay = sgGeneral.add(new IntSetting.Builder()
46
        .name("swap-delay")
47
        .description("The delay between equipping armor pieces.")
48
        .defaultValue(1)
49
        .min(0)
50
        .sliderMax(5)
51
        .build()
52
    );
53
54
    private final Setting<Set<ResourceKey<Enchantment>>> avoidedEnchantments = sgGeneral.add(new EnchantmentListSetting.Builder()
55
        .name("avoided-enchantments")
56
        .description("Enchantments that should be avoided.")
57
        .defaultValue(Enchantments.BINDING_CURSE, Enchantments.FROST_WALKER)
58
        .build()
59
    );
60
61
    private final Setting<Boolean> blastLeggings = sgGeneral.add(new BoolSetting.Builder()
62
        .name("blast-prot-leggings")
63
        .description("Uses blast protection for leggings regardless of preferred protection.")
64
        .defaultValue(true)
65
        .build()
66
    );
67
68
    private final Setting<Boolean> antiBreak = sgGeneral.add(new BoolSetting.Builder()
69
        .name("anti-break")
70
        .description("Takes off armor if it is about to break.")
71
        .defaultValue(false)
72
        .build()
73
    );
74
75
    private final Setting<Boolean> ignoreElytra = sgGeneral.add(new BoolSetting.Builder()
76
        .name("ignore-elytra")
77
        .description("Will not replace your elytra if you have it equipped.")
78
        .defaultValue(true)
79
        .build()
80
    );
81
82
    private final Object2IntMap<Holder<Enchantment>> enchantments = new Object2IntOpenHashMap<>();
83
    private final ArmorPiece[] armorPieces = new ArmorPiece[4];
84
    private final ArmorPiece helmet = new ArmorPiece(EquipmentSlot.HEAD);
85
    private final ArmorPiece chestplate = new ArmorPiece(EquipmentSlot.CHEST);
86
    private final ArmorPiece leggings = new ArmorPiece(EquipmentSlot.LEGS);
87
    private final ArmorPiece boots = new ArmorPiece(EquipmentSlot.FEET);
88
    private int timer;
89
90
    public AutoArmor() {
91
        super(Categories.Combat, "auto-armor", "Automatically equips armor.");
92
93
        armorPieces[0] = helmet;
94
        armorPieces[1] = chestplate;
95
        armorPieces[2] = leggings;
96
        armorPieces[3] = boots;
97
    }
98
99
    @Override
100
    public void onActivate() {
101
        timer = 0;
102
    }
103
104
    @EventHandler
105
    private void onPreTick(TickEvent.Pre event) {
106
        // Wait for timer (delay)
107
        if (timer > 0) {
108
            timer--;
109
            return;
110
        }
111
112
        // Reset armor pieces
113
        for (ArmorPiece armorPiece : armorPieces) armorPiece.reset();
114
115
        // Loop through items in inventory
116
        for (int i = 0; i < mc.player.getInventory().getNonEquipmentItems().size(); i++) {
117
            ItemStack itemStack = mc.player.getInventory().getItem(i);
118
            if (itemStack.isEmpty() || !isArmor(itemStack)) continue;
119
120
            // Check for durability if anti break is enabled
121
            if (antiBreak.get() && itemStack.isDamageableItem() && itemStack.getMaxDamage() - itemStack.getDamageValue() <= 10) {
122
                continue;
123
            }
124
125
            // Get enchantments on the item
126
            Utils.getEnchantments(itemStack, enchantments);
127
128
            // Check for avoided enchantments
129
            if (hasAvoidedEnchantment()) continue;
130
131
            // Add the item to the correct armor piece
132
            switch (getItemSlotId(itemStack)) {
133
                case 0 -> boots.add(itemStack, i);
134
                case 1 -> leggings.add(itemStack, i);
135
                case 2 -> chestplate.add(itemStack, i);
136
                case 3 -> helmet.add(itemStack, i);
137
            }
138
        }
139
140
        // Apply armor pieces
141
        for (ArmorPiece armorPiece : armorPieces) armorPiece.calculate();
142
        Arrays.sort(armorPieces, Comparator.comparingInt(ArmorPiece::getSortScore));
143
        for (ArmorPiece armorPiece : armorPieces) armorPiece.apply();
144
    }
145
146
    private boolean hasAvoidedEnchantment() {
147
        for (Holder<Enchantment> enchantment : enchantments.keySet()) {
148
            if (enchantment.is(avoidedEnchantments.get()::contains)) {
149
                return true;
150
            }
151
        }
152
153
        return false;
154
    }
155
156
    private int getItemSlotId(ItemStack itemStack) {
157
        if (itemStack.has(DataComponents.GLIDER)) return 2;
158
        return itemStack.get(DataComponents.EQUIPPABLE).slot().getIndex();
159
    }
160
161
    private int getScore(ItemStack itemStack) {
162
        if (itemStack.isEmpty()) return 0;
163
164
        // Score calculated based on enchantments, protection and toughness
165
        int score = 0;
166
167
        // Prefer blast protection on leggings if enabled
168
        ResourceKey<Enchantment> protection = preferredProtection.get().enchantment;
169
        if (isArmor(itemStack) && blastLeggings.get() && getItemSlotId(itemStack) == 1) {
170
            protection = Enchantments.BLAST_PROTECTION;
171
        }
172
173
        score += 3 * Utils.getEnchantmentLevel(enchantments, protection);
174
        score += Utils.getEnchantmentLevel(enchantments, Enchantments.PROTECTION);
175
        score += Utils.getEnchantmentLevel(enchantments, Enchantments.BLAST_PROTECTION);
176
        score += Utils.getEnchantmentLevel(enchantments, Enchantments.FIRE_PROTECTION);
177
        score += Utils.getEnchantmentLevel(enchantments, Enchantments.PROJECTILE_PROTECTION);
178
        score += Utils.getEnchantmentLevel(enchantments, Enchantments.UNBREAKING);
179
        score += 2 * Utils.getEnchantmentLevel(enchantments, Enchantments.MENDING);
180
181
        if (itemStack.has(DataComponents.ATTRIBUTE_MODIFIERS)) {
182
            ItemAttributeModifiers component = itemStack.get(DataComponents.ATTRIBUTE_MODIFIERS);
183
            for (ItemAttributeModifiers.Entry modifier : component.modifiers()) {
184
                if (modifier.attribute() == Attributes.ARMOR || modifier.attribute() == Attributes.ARMOR_TOUGHNESS) {
185
                    double e = modifier.modifier().amount();
186
187
                    score += (int) switch (modifier.modifier().operation()) {
188
                        case ADD_VALUE -> e;
189
                        case ADD_MULTIPLIED_BASE -> e * mc.player.getAttributeBaseValue(modifier.attribute());
190
                        case ADD_MULTIPLIED_TOTAL -> e * score;
191
                    };
192
                }
193
            }
194
        }
195
196
        return score;
197
    }
198
199
    private boolean cannotSwap() {
200
        return timer > 0;
201
    }
202
203
    private void swap(int from, int armorSlotId) {
204
        InvUtils.move().from(from).toArmor(armorSlotId);
205
206
        // Apply delay
207
        timer = delay.get();
208
    }
209
210
    private void moveToEmpty(int armorSlotId) {
211
        for (int i = 0; i < mc.player.getInventory().getNonEquipmentItems().size(); i++) {
212
            if (mc.player.getInventory().getItem(i).isEmpty()) {
213
                InvUtils.move().fromArmor(armorSlotId).to(i);
214
215
                // Apply delay
216
                timer = delay.get();
217
218
                break;
219
            }
220
        }
221
    }
222
223
    private boolean isArmor(ItemStack itemStack) {
224
        return itemStack.is(ItemTags.FOOT_ARMOR) || itemStack.is(ItemTags.LEG_ARMOR) || itemStack.is(ItemTags.CHEST_ARMOR) || itemStack.is(ItemTags.HEAD_ARMOR);
225
    }
226
227
    public enum Protection {
228
        Protection(Enchantments.PROTECTION),
229
        BlastProtection(Enchantments.BLAST_PROTECTION),
230
        FireProtection(Enchantments.FIRE_PROTECTION),
231
        ProjectileProtection(Enchantments.PROJECTILE_PROTECTION);
232
233
        private final ResourceKey<Enchantment> enchantment;
234
235
        Protection(ResourceKey<Enchantment> enchantment) {
236
            this.enchantment = enchantment;
237
        }
238
    }
239
240
    private class ArmorPiece {
241
        private final EquipmentSlot slot;
242
243
        private int bestSlot;
244
        private int bestScore;
245
246
        private int score;
247
        private int durability;
248
249
        public ArmorPiece(EquipmentSlot slot) {
250
            this.slot = slot;
251
        }
252
253
        public void reset() {
254
            bestSlot = -1;
255
            bestScore = -1;
256
            score = -1;
257
            durability = Integer.MAX_VALUE;
258
        }
259
260
        public void add(ItemStack itemStack, int slot) {
261
            // Calculate armor piece score and check if its higher than the last one
262
            int score = getScore(itemStack);
263
264
            if (score > bestScore) {
265
                bestScore = score;
266
                bestSlot = slot;
267
            }
268
        }
269
270
        public void calculate() {
271
            if (cannotSwap()) return;
272
273
            ItemStack itemStack = mc.player.getItemBySlot(slot);
274
275
            // Check if the item is an elytra
276
            if ((ignoreElytra.get() || Modules.get().isActive(ChestSwap.class)) && itemStack.getItem() == Items.ELYTRA) {
277
                score = Integer.MAX_VALUE; // Setting score to Integer.MAX_VALUE so its now swapped later
278
                return;
279
            }
280
281
            Utils.getEnchantments(itemStack, enchantments);
282
283
            // Return if current armor piece has Curse of Binding
284
            if (enchantments.keySet().stream().anyMatch(e -> e.is(Enchantments.BINDING_CURSE))) {
285
                score = Integer.MAX_VALUE; // Setting score to Integer.MAX_VALUE so its now swapped later
286
                return;
287
            }
288
289
            // Calculate current score
290
            score = getScore(itemStack);
291
            score = decreaseScoreByAvoidedEnchantments(score);
292
            score = applyAntiBreakScore(score, itemStack);
293
294
            // Calculate durability
295
            if (!itemStack.isEmpty()) {
296
                durability = itemStack.getMaxDamage() - itemStack.getDamageValue();
297
            }
298
        }
299
300
        public int getSortScore() {
301
            if (antiBreak.get() && durability <= 10) return -1;
302
            return bestScore;
303
        }
304
305
        public void apply() {
306
            // Integer.MAX_VALUE check is there because it indicates that the current piece shouldn't be moved
307
            if (cannotSwap() || score == Integer.MAX_VALUE) return;
308
309
            // Check if new score is better and swap if it is
310
            if (bestScore > score) swap(bestSlot, slot.getIndex());
311
            else if (antiBreak.get() && durability <= 10) {
312
                // If no better piece has been found but current piece is broken find an empty slot and move it there
313
                moveToEmpty(slot.getIndex());
314
            }
315
        }
316
317
        private int decreaseScoreByAvoidedEnchantments(int score) {
318
            for (ResourceKey<Enchantment> enchantment : avoidedEnchantments.get()) {
319
                score -= 2 * Utils.getEnchantmentLevel(enchantments, enchantment);
320
            }
321
322
            return score;
323
        }
324
325
        private int applyAntiBreakScore(int score, ItemStack itemStack) {
326
            if (antiBreak.get() && itemStack.isDamageableItem() && itemStack.getMaxDamage() - itemStack.getDamageValue() <= 10) {
327
                return -1;
328
            }
329
330
            return score;
331
        }
332
    }
333
}
334