InventoryCleaner module

InventoryCleaner: Minecraft 26.3 cheat module, full source for every implementation (2 clients: MelaHack (ThunderHack fork), LiquidBounce (Kotlin)).

2 implementationsPLAYER

Full module source: 2 implementations

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

MelaHack (ThunderHack fork)PLAYERsrc/main/java/thunder/hack/features/modules/player/InventoryCleaner.javaJava · 73 lines · 3.1 KB

Throws out unnecessary items from the inventory.

SettingsItemsDropWhenDelayCleanChests
InventoryCleaner.javaJava · Minecraft 26.2 · 73 lines · 3.1 KB · complete file, verbatimOriginal ↗
1
package thunder.hack.features.modules.player;
2
3
import thunder.hack.features.modules.Module;
4
import thunder.hack.setting.Setting;
5
import thunder.hack.setting.impl.ItemSelectSetting;
6
import thunder.hack.utility.Timer;
7
import com.mojang.blaze3d.vertex.PoseStack;
8
import java.util.ArrayList;
9
import net.minecraft.client.gui.screens.inventory.InventoryScreen;
10
import net.minecraft.network.protocol.game.ServerboundContainerClosePacket;
11
import net.minecraft.world.inventory.ChestMenu;
12
import net.minecraft.world.inventory.ContainerInput;
13
import net.minecraft.world.inventory.Slot;
14
import net.minecraft.world.item.ItemStack;
15
16
public class InventoryCleaner extends Module {
17
    public InventoryCleaner() {
18
        super("InventoryCleaner", Category.PLAYER);
19
    }
20
21
    public final Setting<ItemSelectSetting> items = new Setting<>("Items", new ItemSelectSetting(new ArrayList<>()));
22
    private final Setting<DropWhen> dropWhen = new Setting<>("DropWhen", DropWhen.NotInInventory);
23
    private final Setting<Integer> delay = new Setting<>("Delay", 50, 0, 500);
24
    private final Setting<Boolean> cleanChests = new Setting<>("CleanChests", false);
25
26
    private final Timer delayTimer = new Timer();
27
    private boolean dirty;
28
29
    public void onRender3D(PoseStack stack) {
30
        boolean inInv = mc.gui.screen() instanceof InventoryScreen;
31
32
        if (mc.player.containerMenu instanceof ChestMenu chest && cleanChests.getValue())
33
            for (int i = 0; i < chest.getContainer().getContainerSize(); i++) {
34
                Slot slot = chest.getSlot(i);
35
                if (slot.hasItem() && dropThisShit(slot.getItem()) && !(mc.gui.screen().getTitle().getString().contains("Аукцион") || mc.gui.screen().getTitle().getString().contains("покупки")))
36
                    if (delayTimer.every(delay.getValue())) {
37
                        mc.gameMode.handleContainerInput(mc.player.containerMenu.containerId, i, 1, ContainerInput.THROW, mc.player);
38
                        dirty = true;
39
                    }
40
            }
41
42
        if (dropWhen.getValue() == DropWhen.Inventory && !inInv) return;
43
        if (dropWhen.getValue() == DropWhen.NotInInventory && inInv) return;
44
45
        for (int slot = 0; slot < 36; slot++) {
46
            ItemStack itemFromslot = mc.player.getInventory().getItem(slot);
47
            if (dropThisShit(itemFromslot))
48
                drop(slot);
49
        }
50
51
        if (dirty && delayTimer.passedMs(delay.getValue() + 100)) {
52
            sendPacket(new ServerboundContainerClosePacket(mc.player.containerMenu.containerId));
53
            debug("after click cleaning...");
54
            dirty = false;
55
        }
56
    }
57
58
    private void drop(int slot) {
59
        if (delayTimer.every(delay.getValue())) {
60
            mc.gameMode.handleContainerInput(mc.player.containerMenu.containerId, slot < 9 ? slot + 36 : slot, 1, ContainerInput.THROW, mc.player);
61
            dirty = true;
62
        }
63
    }
64
65
    private boolean dropThisShit(ItemStack stack) {
66
        return items.getValue().getItemsById().contains(stack.getItem().getDescriptionId().replace("block.minecraft.", "").replace("item.minecraft.", ""));
67
    }
68
69
    public enum DropWhen {
70
        Inventory, Always, NotInInventory
71
    }
72
}
73
LiquidBounce (Kotlin)PLAYERsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/ModuleInventoryCleaner.ktKotlin · 258 lines · 10.8 KB

Automatically sorts your inventory and drops unnecessary items.

SettingsMaximumBlocksMaximumArrowsMaximumThrowablesMaximumFoodPointsMaximumWaterBucketsMaximumLavaBucketsMaximumMilkBucketsItemsBlacklistGreedyOffHandItemSlotItem-1SlotItem-2SlotItem-3SlotItem-4SlotItem-5SlotItem-6SlotItem-7SlotItem-8SlotItem-9
ModuleInventoryCleaner.ktKotlin · Minecraft 26.2 · 258 lines · 10.8 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce)
3
 *
4
 * Copyright (c) 2015 - 2026 CCBlueX
5
 *
6
 * LiquidBounce is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * LiquidBounce is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>.
18
 */
19
package net.ccbluex.liquidbounce.features.module.modules.player.invcleaner
20
21
import it.unimi.dsi.fastutil.objects.Object2IntMap
22
import it.unimi.dsi.fastutil.objects.Reference2IntMap
23
import net.ccbluex.fastutil.component1
24
import net.ccbluex.fastutil.component2
25
import net.ccbluex.fastutil.enumMapOf
26
import net.ccbluex.fastutil.objectIntArrayMapOf
27
import net.ccbluex.fastutil.referenceIntArrayMapOf
28
import net.ccbluex.liquidbounce.event.events.ScheduleInventoryActionEvent
29
import net.ccbluex.liquidbounce.event.handler
30
import net.ccbluex.liquidbounce.features.module.ClientModule
31
import net.ccbluex.liquidbounce.features.module.ModuleCategories
32
import net.ccbluex.liquidbounce.features.module.modules.player.invcleaner.items.ItemFacet
33
import net.ccbluex.liquidbounce.features.module.modules.player.offhand.ModuleOffhand
34
import net.ccbluex.liquidbounce.utils.collection.itemSortedSetOf
35
import net.ccbluex.liquidbounce.utils.inventory.ArmorItemSlot
36
import net.ccbluex.liquidbounce.utils.inventory.HotbarItemSlot
37
import net.ccbluex.liquidbounce.utils.inventory.InventoryAction
38
import net.ccbluex.liquidbounce.utils.inventory.ItemSlot
39
import net.ccbluex.liquidbounce.utils.inventory.PlayerInventoryConstraints
40
import net.ccbluex.liquidbounce.utils.inventory.findNonEmptySlotsInInventory
41
import net.ccbluex.liquidbounce.utils.kotlin.Priority
42
43
/**
44
 * InventoryCleaner module
45
 *
46
 * Automatically throws away useless items and sorts them.
47
 */
48
object ModuleInventoryCleaner : ClientModule(
49
    "InventoryCleaner", ModuleCategories.PLAYER,
50
    aliases = listOf("InventoryManager")
51
) {
52
53
    private val inventoryConstraints = tree(PlayerInventoryConstraints())
54
55
56
    private val maxBlocks by int("MaximumBlocks", 512, 0..2500)
57
    private val maxArrows by int("MaximumArrows", 128, 0..2500)
58
    private val maxThrowables by int("MaximumThrowables", 64, 0..600)
59
    private val maxFoods by int("MaximumFoodPoints", 200, 0..2000)
60
    private val maxWaterBuckets by int("MaximumWaterBuckets", 2, 0..16)
61
    private val maxLavaBuckets by int("MaximumLavaBuckets", 2, 0..16)
62
    private val maxMilkBuckets by int("MaximumMilkBuckets", 2, 0..16)
63
64
    private val itemsBlackList by items("ItemsBlacklist", itemSortedSetOf())
65
66
    private val isGreedy by boolean("Greedy", true)
67
68
    private val offHandItem by enumChoice("OffHandItem", ItemSortChoice.SHIELD)
69
    private val slotItem1 by enumChoice("SlotItem-1", ItemSortChoice.WEAPON)
70
    private val slotItem2 by enumChoice("SlotItem-2", ItemSortChoice.BOW)
71
    private val slotItem3 by enumChoice("SlotItem-3", ItemSortChoice.PICKAXE)
72
    private val slotItem4 by enumChoice("SlotItem-4", ItemSortChoice.AXE)
73
    private val slotItem5 by enumChoice("SlotItem-5", ItemSortChoice.NONE)
74
    private val slotItem6 by enumChoice("SlotItem-6", ItemSortChoice.POTION)
75
    private val slotItem7 by enumChoice("SlotItem-7", ItemSortChoice.FOOD)
76
    private val slotItem8 by enumChoice("SlotItem-8", ItemSortChoice.BLOCK)
77
    private val slotItem9 by enumChoice("SlotItem-9", ItemSortChoice.BLOCK)
78
79
    private fun buildSlotTargetMap(): Map<HotbarItemSlot, ItemSortChoice> {
80
        val slotTargets = enumMapOf<HotbarItemSlot, ItemSortChoice>()
81
82
        if (HotbarItemSlot.OFFHAND.canBeSwapTarget) slotTargets[HotbarItemSlot.OFFHAND] = offHandItem
83
        slotTargets[HotbarItemSlot.SLOT_0] = slotItem1
84
        slotTargets[HotbarItemSlot.SLOT_1] = slotItem2
85
        slotTargets[HotbarItemSlot.SLOT_2] = slotItem3
86
        slotTargets[HotbarItemSlot.SLOT_3] = slotItem4
87
        slotTargets[HotbarItemSlot.SLOT_4] = slotItem5
88
        slotTargets[HotbarItemSlot.SLOT_5] = slotItem6
89
        slotTargets[HotbarItemSlot.SLOT_6] = slotItem7
90
        slotTargets[HotbarItemSlot.SLOT_7] = slotItem8
91
        slotTargets[HotbarItemSlot.SLOT_8] = slotItem9
92
        return slotTargets
93
    }
94
95
    val cleanupTemplateFromSettings: CleanupPlanPlacementTemplate
96
        get() {
97
            val slotTargets = buildSlotTargetMap()
98
99
            val forbiddenSlots = buildSet<ItemSlot> {
100
                for ((slot, choice) in slotTargets) {
101
                    if (choice == ItemSortChoice.IGNORE) this += slot
102
                }
103
104
                // Disallow tampering with armor slots since auto armor already handles them
105
                this += ArmorItemSlot.entries
106
107
                if (ModuleOffhand.isOperating()) {
108
                    // Disallow tampering with off-hand slot when AutoTotem is active
109
                    this.add(HotbarItemSlot.OFFHAND)
110
                }
111
            }
112
113
            val forbiddenSlotsToFill = setOfNotNull(
114
                // Disallow tampering with off-hand slot when AutoTotem is active
115
                if (ModuleOffhand.isOperating()) HotbarItemSlot.OFFHAND else null
116
            )
117
118
            val constraintProvider = AmountConstraintProvider(
119
                desiredItemsPerCategory = objectIntArrayMapOf(
120
                    ItemType.BLOCK.defaultCategory, maxBlocks,
121
                    ItemType.THROWABLE.defaultCategory, maxThrowables,
122
                    ItemType.ARROW.defaultCategory, maxArrows,
123
                    ItemSortChoice.WATER.category, maxWaterBuckets,
124
                    ItemSortChoice.LAVA.category, maxLavaBuckets,
125
                    ItemSortChoice.MILK.category, maxMilkBuckets,
126
                ),
127
                desiredValuePerFunction = referenceIntArrayMapOf(
128
                    ItemFunction.FOOD, maxFoods,
129
                    ItemFunction.WEAPON_LIKE, 1,
130
                )
131
            )
132
133
            return CleanupPlanPlacementTemplate(
134
                slotTargets,
135
                itemAmountConstraintProvider = constraintProvider::getConstraints,
136
                itemBlacklist = itemsBlackList,
137
                forbiddenSlots = forbiddenSlots,
138
                forbiddenSlotsToFill = forbiddenSlotsToFill,
139
                isGreedy = isGreedy,
140
            )
141
        }
142
143
    @Suppress("unused")
144
    private val handleInventorySchedule = handler<ScheduleInventoryActionEvent> { event ->
145
        val currentInventorySlots = findNonEmptySlotsInInventory()
146
        val cleanupPlan = CleanupPlanGenerator(cleanupTemplateFromSettings, currentInventorySlots)
147
            .generatePlan()
148
149
        // Process inventory actions in priority order
150
        when {
151
            // Step 1: Prioritize hotbar swaps
152
            processHotbarSwaps(event, cleanupPlan) -> return@handler
153
            // Step 2: Merge stackable items to optimize space
154
            processStackMerging(event, cleanupPlan) -> return@handler
155
            // Step 3: Remove unwanted items (lowest priority)
156
            processItemDisposal(event, cleanupPlan, currentInventorySlots) -> return@handler
157
        }
158
    }
159
160
    /**
161
     * Handles swapping items to correct hotbar positions
162
     * @return true if a swap was scheduled, false otherwise
163
     */
164
    private fun processHotbarSwaps(event: ScheduleInventoryActionEvent, cleanupPlan: InventoryCleanupPlan): Boolean {
165
        val hotbarSwap = cleanupPlan.swaps.firstOrNull() ?: return false
166
167
        require(hotbarSwap.to is HotbarItemSlot) {
168
            "Invalid swap target: ${hotbarSwap.to}. Only hotbar slots are supported."
169
        }
170
171
        event.schedule(
172
            inventoryConstraints,
173
            InventoryAction.Click.performSwap(null, hotbarSwap.from, hotbarSwap.to)
174
        )
175
176
        return true
177
    }
178
179
    /**
180
     * Handles merging stackable items to optimize inventory space
181
     * @return true if a merge was scheduled, false otherwise
182
     */
183
    private fun processStackMerging(event: ScheduleInventoryActionEvent, cleanupPlan: InventoryCleanupPlan): Boolean {
184
        val stacksToMerge = cleanupPlan.findSlotsToMerge()
185
        val slotToMerge = stacksToMerge.firstOrNull() ?: return false
186
187
        // pickup -> pickup all -> pickup to handle remaining items
188
        event.schedule(
189
            inventoryConstraints,
190
            InventoryAction.Click.performMergeStack(slot = slotToMerge),
191
        )
192
193
        return true
194
    }
195
196
    private fun processItemDisposal(
197
        event: ScheduleInventoryActionEvent,
198
        cleanupPlan: InventoryCleanupPlan,
199
        currentInventorySlots: List<ItemSlot>
200
    ): Boolean {
201
        val planDisposalItems = cleanupPlan.findItemsToThrowOut(currentInventorySlots)
202
        val blacklistedItems = currentInventorySlots.filter { it.itemStack.item in itemsBlackList }
203
204
        // Blacklisted items
205
        val itemsToDispose = (blacklistedItems + planDisposalItems).distinct()
206
        val itemToThrow = itemsToDispose.firstOrNull() ?: return false
207
208
        event.schedule(
209
            inventoryConstraints,
210
            InventoryAction.Click.performThrow(screen = null, itemToThrow),
211
            Priority.NOT_IMPORTANT
212
        )
213
214
        return true
215
    }
216
217
    private class AmountConstraintProvider(
218
        val desiredItemsPerCategory: Object2IntMap<ItemCategory>,
219
        val desiredValuePerFunction: Reference2IntMap<ItemFunction>,
220
    ) {
221
        fun getConstraints(facet: ItemFacet): MutableList<ItemConstraintInfo> {
222
            val constraints = mutableListOf<ItemConstraintInfo>()
223
224
            if (facet.providedItemFunctions.isEmpty()) {
225
                val defaultDesiredAmount = if (facet.category.type.oneIsSufficient) 1 else Integer.MAX_VALUE
226
                val desiredAmount = this.desiredItemsPerCategory.getOrDefault(facet.category, defaultDesiredAmount)
227
228
                val info = ItemConstraintInfo(
229
                    group = ItemCategoryConstraintGroup(
230
                        desiredAmount..Integer.MAX_VALUE,
231
                        10,
232
                        facet.category
233
                    ),
234
                    amountAddedByItem = facet.itemStack.count
235
                )
236
237
                constraints.add(info)
238
            } else {
239
                for ((function, amountAdded) in facet.providedItemFunctions) {
240
                    val info = ItemConstraintInfo(
241
                        group = ItemFunctionCategoryConstraintGroup(
242
                            desiredValuePerFunction.getOrDefault(function, 1)..Integer.MAX_VALUE,
243
                            10,
244
                            function
245
                        ),
246
                        amountAddedByItem = amountAdded
247
                    )
248
249
                    constraints.add(info)
250
                }
251
            }
252
253
            return constraints
254
        }
255
    }
256
257
}
258