Replenish module

Replenish: Minecraft 26.3 cheat module, full source for every implementation (1 client: LiquidBounce (Kotlin)).

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.

LiquidBounce (Kotlin)PLAYERsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/ModuleReplenish.ktKotlin · 215 lines · 7.7 KB

Automatically refills your hotbar with items from your inventory when the count drops to a certain threshold.

SettingsItemThresholdDelayReplenishEmptyFeatures
ModuleReplenish.ktKotlin · Minecraft 26.2 · 215 lines · 7.7 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
20
21
import net.ccbluex.fastutil.enumMapOf
22
import net.ccbluex.liquidbounce.config.types.list.Tagged
23
import net.ccbluex.liquidbounce.event.events.ScheduleInventoryActionEvent
24
import net.ccbluex.liquidbounce.event.events.ScreenEvent
25
import net.ccbluex.liquidbounce.event.events.WorldChangeEvent
26
import net.ccbluex.liquidbounce.event.handler
27
import net.ccbluex.liquidbounce.features.module.ClientModule
28
import net.ccbluex.liquidbounce.features.module.ModuleCategories
29
import net.ccbluex.liquidbounce.features.module.modules.player.invcleaner.ItemAndComponents
30
import net.ccbluex.liquidbounce.utils.client.Chronometer
31
import net.ccbluex.liquidbounce.utils.inventory.HotbarItemSlot
32
import net.ccbluex.liquidbounce.utils.inventory.InventoryAction.Click
33
import net.ccbluex.liquidbounce.utils.inventory.InventoryItemSlot
34
import net.ccbluex.liquidbounce.utils.inventory.ItemSlot
35
import net.ccbluex.liquidbounce.utils.inventory.PlayerInventoryConstraints
36
import net.ccbluex.liquidbounce.utils.inventory.Slots
37
import net.ccbluex.liquidbounce.utils.item.isMergeable
38
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen
39
import net.minecraft.client.gui.screens.inventory.InventoryScreen
40
import net.minecraft.world.item.ItemStack
41
import net.minecraft.world.item.Items
42
43
/**
44
 * Module Replenish
45
 *
46
 * Automatically refills your hotbar with items from your inventory when the count drops to a certain threshold.
47
 *
48
 * @author ccetl
49
 */
50
object ModuleReplenish : ClientModule("Replenish", ModuleCategories.PLAYER, aliases = listOf("Refill")) {
51
    private val constraints = tree(PlayerInventoryConstraints())
52
    private val itemThreshold by int("ItemThreshold", 5, 0..63)
53
    private val delay by int("Delay", 40, 0..1000, "ms")
54
    private val replenishEmpty by boolean("ReplenishEmpty", true)
55
    private val features by multiEnumChoice("Features", Features.CLEANUP)
56
    private val insideOf by multiEnumChoice<InsideOf>("InsideOf")
57
58
    private val trackedHotbarItems = enumMapOf<HotbarItemSlot, ItemAndComponents>()
59
    private val chronometer = Chronometer()
60
61
    private fun clear() {
62
        trackedHotbarItems.clear()
63
    }
64
65
    override fun onEnabled() {
66
        clear()
67
    }
68
69
    @Suppress("unused")
70
    private val worldChangeHandler = handler<WorldChangeEvent> {
71
        clear()
72
    }
73
74
    @Suppress("unused")
75
    private val screenHandler = handler<ScreenEvent> { event ->
76
        if (event.screen is AbstractContainerScreen<*>) {
77
            clear()
78
        }
79
    }
80
81
    @Suppress("unused")
82
    private val inventoryScheduleHandler = handler<ScheduleInventoryActionEvent> { event ->
83
        if (!chronometer.hasElapsed(delay.toLong()) || !player.containerMenu.carried.isEmpty) {
84
            return@handler
85
        }
86
87
        chronometer.reset()
88
89
        HotbarItemSlot.entries.forEach { slot ->
90
            val currentStack = slot.itemStack
91
            val currentStackNotEmpty = !currentStack.isEmpty
92
93
            if (!currentStackNotEmpty && !replenishEmpty) {
94
                trackedHotbarItems.remove(slot)
95
                return@forEach
96
            }
97
98
            // find the desired item
99
            val itemStack = if (currentStackNotEmpty) {
100
                currentStack
101
            } else {
102
                val trackedItem = trackedHotbarItems[slot]
103
                if (trackedItem == null || trackedItem.item == Items.AIR) {
104
                    return@forEach
105
                }
106
107
                trackedItem.toItemStack(1)
108
            }
109
110
            // check if the current stack, if not empty, is allowed to be refilled
111
            val unsupportedStackSize = itemStack.maxStackSize <= itemThreshold
112
            if (currentStackNotEmpty && (unsupportedStackSize || itemStack.count > itemThreshold)) {
113
                trackedHotbarItems[slot] = ItemAndComponents(itemStack)
114
                return@forEach
115
            }
116
117
            // find replacement items
118
            val inventorySlots = Slots.Inventory
119
                .filterTo(mutableListOf()) { it.itemStack.isMergeable(itemStack) }
120
121
            // no stack to refill found
122
            if (inventorySlots.isEmpty()) {
123
                trackedHotbarItems[slot] = ItemAndComponents(itemStack)
124
                return@forEach
125
            }
126
127
            inventorySlots.sortWith(ItemSlot.PREFER_MORE_ITEM)
128
            val slotWithMaxCount = inventorySlots.first()
129
130
            if (Features.CLEANUP in features) {
131
                // clean up small stacks first when cleanUp is enabled otherwise prioritize larger stacks
132
                inventorySlots.reverse()
133
            }
134
135
            // refill
136
            when {
137
                Features.USE_SWAP in features &&
138
                    slot.canBeSwapTarget &&
139
                    slotWithMaxCount.itemStack.count.let { it > itemStack.count && it > itemThreshold } ->
140
                    event.schedule(
141
                        constraints,
142
                        Click.performSwap(from = slotWithMaxCount, to = slot)
143
                    )
144
145
                Features.USE_PICKUP_ALL in features && currentStackNotEmpty ->
146
                    event.schedule(
147
                        constraints,
148
                        Click.performMergeStack(slot = slot),
149
                    )
150
151
                else -> event.scheduleNormalRefill(
152
                    itemStack,
153
                    if (currentStackNotEmpty) itemStack.count else 0,
154
                    inventorySlots,
155
                    slot,
156
                )
157
            }
158
159
            trackedHotbarItems[slot] = ItemAndComponents(itemStack)
160
            return@handler
161
        }
162
    }
163
164
    private fun ScheduleInventoryActionEvent.scheduleNormalRefill(
165
        itemStack: ItemStack,
166
        count: Int,
167
        inventorySlots: List<InventoryItemSlot>,
168
        slot: HotbarItemSlot,
169
    ) {
170
        var neededToRefill = itemStack.maxStackSize - count
171
        for (inventorySlot in inventorySlots) {
172
            neededToRefill -= inventorySlot.itemStack.count
173
            val actions = ArrayList<Click>(3)
174
            actions += Click.performPickup(slot = inventorySlot)
175
            actions += Click.performPickup(slot = slot)
176
177
            if (neededToRefill < 0) {
178
                actions += Click.performPickup(slot = slot)
179
            }
180
181
            schedule(constraints, actions)
182
183
            if (neededToRefill <= 0) {
184
                break
185
            }
186
        }
187
    }
188
189
    override val running: Boolean
190
        get() = super.running &&
191
            (InsideOf.CHESTS in insideOf
192
                || (mc.gui.screen() !is AbstractContainerScreen<*>
193
                || mc.gui.screen() is InventoryScreen)
194
                ) &&
195
            (InsideOf.INVENTORIES in insideOf
196
                || mc.gui.screen() !is InventoryScreen
197
                )
198
199
    private enum class Features(
200
        override val tag: String
201
    ) : Tagged {
202
        CLEANUP("CleanUp"),
203
        USE_PICKUP_ALL("UsePickupAll"),
204
        USE_SWAP("UseSwap"),
205
    }
206
207
    @Suppress("unused")
208
    private enum class InsideOf(
209
        override val tag: String
210
    ) : Tagged {
211
        CHESTS("Chests"),
212
        INVENTORIES("Inventories")
213
    }
214
}
215