auto-replenish module

auto-replenish: 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/AutoReplenish.javaJava · 193 lines · 6.8 KB

Automatically refills items in your hotbar, main hand, or offhand.

Settingsmin-countdelayoffhandunstackablesame-enchantssearch-hotbarexcluded-items
AutoReplenish.javaJava · Minecraft 26.2 · 193 lines · 6.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 meteordevelopment.meteorclient.events.world.TickEvent;
9
import meteordevelopment.meteorclient.settings.*;
10
import meteordevelopment.meteorclient.systems.modules.Categories;
11
import meteordevelopment.meteorclient.systems.modules.Module;
12
import meteordevelopment.meteorclient.systems.modules.Modules;
13
import meteordevelopment.meteorclient.systems.modules.combat.AutoTotem;
14
import meteordevelopment.meteorclient.utils.player.InvUtils;
15
import meteordevelopment.meteorclient.utils.player.SlotUtils;
16
import meteordevelopment.orbit.EventHandler;
17
import net.minecraft.world.item.Item;
18
import net.minecraft.world.item.ItemStack;
19
20
import java.util.List;
21
22
public class AutoReplenish extends Module {
23
    private final SettingGroup sgGeneral = settings.getDefaultGroup();
24
25
    private final Setting<Integer> minCount = sgGeneral.add(new IntSetting.Builder()
26
        .name("min-count")
27
        .description("Replenish a slot when it reaches this item count.")
28
        .defaultValue(8)
29
        .min(1)
30
        .sliderRange(1, 63)
31
        .build()
32
    );
33
34
    private final Setting<Integer> tickDelay = sgGeneral.add(new IntSetting.Builder()
35
        .name("delay")
36
        .description("How long in ticks to wait between replenishing your hotbar.")
37
        .defaultValue(1)
38
        .min(0)
39
        .build()
40
    );
41
42
    private final Setting<Boolean> offhand = sgGeneral.add(new BoolSetting.Builder()
43
        .name("offhand")
44
        .description("Whether or not to replenish items in your offhand.")
45
        .defaultValue(true)
46
        .build()
47
    );
48
49
    private final Setting<Boolean> unstackable = sgGeneral.add(new BoolSetting.Builder()
50
        .name("unstackable")
51
        .description("Replenish unstackable items.")
52
        .defaultValue(true)
53
        .build()
54
    );
55
56
    private final Setting<Boolean> sameEnchants = sgGeneral.add(new BoolSetting.Builder()
57
        .name("same-enchants")
58
        .description("Only replace unstackables with items that have the same enchants.")
59
        .defaultValue(true)
60
        .visible(unstackable::get)
61
        .build()
62
    );
63
64
    private final Setting<Boolean> searchHotbar = sgGeneral.add(new BoolSetting.Builder()
65
        .name("search-hotbar")
66
        .description("Combine stacks in your hotbar/offhand as a last resort.")
67
        .defaultValue(false)
68
        .build()
69
    );
70
71
    private final Setting<List<Item>> excludedItems = sgGeneral.add(new ItemListSetting.Builder()
72
        .name("excluded-items")
73
        .description("Items that won't be replenished.")
74
        .build()
75
    );
76
77
    /**
78
     * Represents the items the player had last tick. Indices 0-8 represent the
79
     * hotbar from left to right, index 9 represents the player's offhand
80
     */
81
    private final ItemStack[] items = new ItemStack[10];
82
    private boolean prevHadOpenScreen;
83
    private int tickDelayLeft;
84
85
    public AutoReplenish() {
86
        super(Categories.Player, "auto-replenish", "Automatically refills items in your hotbar, main hand, or offhand.");
87
    }
88
89
    @Override
90
    public void onActivate() {
91
        fillItems();
92
        tickDelayLeft = tickDelay.get();
93
        prevHadOpenScreen = mc.gui.screen() != null;
94
    }
95
96
    @EventHandler
97
    private void onTick(TickEvent.Pre event) {
98
        if (mc.gui.screen() == null && prevHadOpenScreen) {
99
            fillItems();
100
        }
101
102
        prevHadOpenScreen = mc.gui.screen() != null;
103
        if (mc.player.containerMenu.getItems().size() != 46 || mc.gui.screen() != null) return;
104
105
        if (tickDelayLeft > 0) {
106
            tickDelayLeft--;
107
            return;
108
        }
109
110
        // Hotbar
111
        for (int i = 0; i < 9; i++) {
112
            ItemStack stack = mc.player.getInventory().getItem(i);
113
            checkSlot(i, stack);
114
        }
115
116
        // Offhand
117
        if (offhand.get() && !Modules.get().get(AutoTotem.class).isLocked()) {
118
            ItemStack stack = mc.player.getOffhandItem();
119
            checkSlot(9, stack);
120
        }
121
122
        tickDelayLeft = tickDelay.get();
123
    }
124
125
    private void checkSlot(int slot, ItemStack stack) {
126
        ItemStack prevStack = items[slot];
127
        items[slot] = stack.copy();
128
129
        if (slot == 9) slot = SlotUtils.OFFHAND;
130
131
        if (excludedItems.get().contains(stack.getItem())) return;
132
        if (excludedItems.get().contains(prevStack.getItem())) return;
133
134
        int fromSlot = -1;
135
136
        // If there are still items left in the stack, but it just crossed the threshold
137
        if (stack.isStackable() && !stack.isEmpty() && stack.getCount() <= minCount.get()) {
138
            fromSlot = findItem(stack, slot, minCount.get() - stack.getCount() + 1, true);
139
        }
140
141
        // If the stack just went from above the threshold to empty in a single tick
142
        // this can happen if the threshold is set low enough while using modules that
143
        // place many blocks per tick, like surround or holefiller
144
        if (prevStack.isStackable() && stack.isEmpty() && !prevStack.isEmpty()) {
145
            fromSlot = findItem(prevStack, slot, minCount.get() - stack.getCount() + 1, false);
146
        }
147
148
        // Unstackable items
149
        if (unstackable.get() && !prevStack.isStackable() && stack.isEmpty() && !prevStack.isEmpty()) {
150
            fromSlot = findItem(prevStack, slot, 1, false);
151
        }
152
153
        // eliminate occasional loops when moving items from hotbar to itself
154
        if (fromSlot == mc.player.getInventory().getSelectedSlot() || fromSlot == SlotUtils.OFFHAND) return;
155
        if (fromSlot < 9 && fromSlot < slot && slot != mc.player.getInventory().getSelectedSlot() && slot != SlotUtils.OFFHAND)
156
            return;
157
158
        InvUtils.move().from(fromSlot).to(slot);
159
    }
160
161
    private int findItem(ItemStack lookForStack, int excludedSlot, int goodEnoughCount, boolean mustCombine) {
162
        int slot = -1;
163
        int count = 0;
164
165
        for (int i = mc.player.getInventory().getContainerSize() - 2; i >= (searchHotbar.get() ? 0 : 9); i--) {
166
            if (i == excludedSlot) continue;
167
168
            ItemStack stack = mc.player.getInventory().getItem(i);
169
            if (stack.getItem() != lookForStack.getItem()) continue;
170
171
            if (mustCombine && !ItemStack.isSameItemSameComponents(lookForStack, stack)) continue;
172
            if (sameEnchants.get() && !stack.getEnchantments().equals(lookForStack.getEnchantments())) continue;
173
174
            if (stack.getCount() > count) {
175
                slot = i;
176
                count = stack.getCount();
177
178
                if (count >= goodEnoughCount) break;
179
            }
180
        }
181
182
        return slot;
183
    }
184
185
    private void fillItems() {
186
        for (int i = 0; i < 9; i++) {
187
            items[i] = mc.player.getInventory().getItem(i).copy();
188
        }
189
190
        items[9] = mc.player.getOffhandItem().copy();
191
    }
192
}
193