AutoCrafter module

AutoCrafter: 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/ModuleAutoCrafter.ktKotlin · 163 lines · 6.8 KB

Automatically crafts items using the Recipe Book.

SettingsItemsToCraftDelayStackCraftingSequentialCraftingOnFullAllowedContainers
ModuleAutoCrafter.ktKotlin · Minecraft 26.2 · 163 lines · 6.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
20
21
import net.ccbluex.liquidbounce.config.types.list.Tagged
22
import net.ccbluex.liquidbounce.event.tickHandler
23
import net.ccbluex.liquidbounce.event.waitTicks
24
import net.ccbluex.liquidbounce.features.module.ClientModule
25
import net.ccbluex.liquidbounce.features.module.ModuleCategories
26
import net.ccbluex.liquidbounce.utils.inventory.Slots
27
import net.ccbluex.liquidbounce.utils.inventory.mergeableCapacityFor
28
import net.minecraft.client.gui.screens.recipebook.SearchRecipeBookCategory
29
import net.minecraft.world.inventory.AbstractFurnaceMenu
30
import net.minecraft.world.inventory.BlastFurnaceMenu
31
import net.minecraft.world.inventory.ContainerInput
32
import net.minecraft.world.inventory.CraftingMenu
33
import net.minecraft.world.inventory.FurnaceMenu
34
import net.minecraft.world.inventory.InventoryMenu
35
import net.minecraft.world.inventory.RecipeBookMenu
36
import net.minecraft.world.inventory.RecipeBookType
37
import net.minecraft.world.inventory.SmokerMenu
38
import net.minecraft.world.item.Items
39
import net.minecraft.world.item.crafting.display.SlotDisplayContext
40
41
/**
42
 * AutoCrafter module
43
 *
44
 * Automatically crafts items using the Recipe Book.
45
 */
46
object ModuleAutoCrafter : ClientModule("AutoCrafter", ModuleCategories.PLAYER) {
47
48
    private val itemsToCraft by itemList(
49
        "ItemsToCraft", mutableListOf(
50
            Items.POLISHED_DEEPSLATE, Items.DEEPSLATE_BRICKS, Items.DEEPSLATE_TILES
51
        )
52
    )
53
54
    private val delay by intRange("Delay", 2..3, 1..20, "ticks")
55
    private val stackCrafting by boolean("StackCrafting", true)
56
    private val sequentialCrafting by boolean("SequentialCrafting", true)
57
    private val onFull by enumChoice("OnFull", OnFull.WAIT)
58
    private val allowedContainers by multiEnumChoice("AllowedContainers", RecipeBookMenuType.CRAFTING_TABLE)
59
60
    @Suppress("unused")
61
    private val tickHandler = tickHandler {
62
        val menu = player.containerMenu
63
        if (menu !is RecipeBookMenu) return@tickHandler
64
        val menuType = RecipeBookMenuType.fromMenu(menu) ?: return@tickHandler
65
        if (menuType !in allowedContainers) return@tickHandler
66
67
        if (!player.recipeBook.bookSettings.isOpen(menuType.recipeBookType)) {
68
            return@tickHandler
69
        }
70
71
        val context = SlotDisplayContext.fromLevel(mc.level ?: return@tickHandler)
72
        val collections = player.recipeBook.getCollection(menuType.searchCategory)
73
74
        for ((index, targetItem) in itemsToCraft.withIndex()) {
75
            val currentMenu = player.containerMenu
76
            if (currentMenu !== menu) break
77
78
            val remainingItems = itemsToCraft.subList(index + 1, itemsToCraft.size)
79
80
            val recipe = collections.firstNotNullOfOrNull { collection ->
81
                collection.recipes.firstOrNull { recipe ->
82
                    recipe.resultItems(context).any { it.item == targetItem } &&
83
                        collection.isCraftable(recipe.id)
84
85
                        // Prevent crafting loops (ingot->block->ingot)
86
                        // by rejecting recipes that use items that appear later in the list
87
                        && (recipe.craftingRequirements.isEmpty ||
88
                        recipe.craftingRequirements.get()
89
                            .none { req -> remainingItems.any { req.test(it.defaultInstance) } })
90
                }
91
            } ?: continue
92
93
            val resultSlotId = if (menu is AbstractFurnaceMenu) 2 else 0
94
            val resultSlot = menu.slots[resultSlotId]
95
            if (resultSlot.item.isEmpty) {
96
                interaction.handlePlaceRecipe(menu.containerId, recipe.id, stackCrafting)
97
            } else {
98
                if (Slots.HotbarAndInventory.mergeableCapacityFor(resultSlot.item) >= resultSlot.item.count) {
99
                    interaction.handleContainerInput(
100
                        menu.containerId, resultSlotId, 0, ContainerInput.QUICK_MOVE, player
101
                    )
102
                } else {
103
                    when (onFull) {
104
                        OnFull.DISABLE -> {
105
                            enabled = false
106
                            return@tickHandler
107
                        }
108
109
                        OnFull.CLOSE_SCREEN -> {
110
                            player.closeContainer()
111
                            return@tickHandler
112
                        }
113
114
                        OnFull.WAIT -> {
115
                            waitTicks(delay.random())
116
                            return@tickHandler
117
                        }
118
119
                        OnFull.THROW -> {
120
                            interaction.handleContainerInput(
121
                                menu.containerId, resultSlotId, 1, ContainerInput.THROW, player
122
                            )
123
                        }
124
                    }
125
                }
126
            }
127
            waitTicks(delay.random())
128
            if (sequentialCrafting || menu is AbstractFurnaceMenu) return@tickHandler
129
        }
130
131
    }
132
133
    private enum class OnFull(override val tag: String) : Tagged {
134
        DISABLE("Disable"),
135
        CLOSE_SCREEN("CloseScreen"),
136
        WAIT("Wait"),
137
        THROW("Throw"),
138
    }
139
140
    private enum class RecipeBookMenuType(
141
        override val tag: String,
142
        val recipeBookType: RecipeBookType,
143
        val searchCategory: SearchRecipeBookCategory,
144
    ) : Tagged {
145
        INVENTORY("Inventory", RecipeBookType.CRAFTING, SearchRecipeBookCategory.CRAFTING),
146
        CRAFTING_TABLE("CraftingTable", RecipeBookType.CRAFTING, SearchRecipeBookCategory.CRAFTING),
147
        FURNACE("Furnace", RecipeBookType.FURNACE, SearchRecipeBookCategory.FURNACE),
148
        BLAST_FURNACE("BlastFurnace", RecipeBookType.BLAST_FURNACE, SearchRecipeBookCategory.BLAST_FURNACE),
149
        SMOKER("Smoker", RecipeBookType.SMOKER, SearchRecipeBookCategory.SMOKER);
150
151
        companion object {
152
            fun fromMenu(menu: RecipeBookMenu) = when (menu) {
153
                is InventoryMenu -> INVENTORY
154
                is CraftingMenu -> CRAFTING_TABLE
155
                is FurnaceMenu -> FURNACE
156
                is BlastFurnaceMenu -> BLAST_FURNACE
157
                is SmokerMenu -> SMOKER
158
                else -> null
159
            }
160
        }
161
    }
162
}
163