Macros module

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

1 implementationMISC

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)MISCsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/misc/ModuleMacros.ktKotlin · 163 lines · 5.7 KB

Lets you execute chat messages or item actions using custom keybinds.

SettingsTriggerDelayMessagesUseClientCommandActionSwingModeHoldTime
ModuleMacros.ktKotlin · Minecraft 26.2 · 163 lines · 5.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
20
package net.ccbluex.liquidbounce.features.module.modules.misc
21
22
import kotlinx.coroutines.delay
23
import kotlinx.coroutines.launch
24
import net.ccbluex.liquidbounce.config.types.group.ValueGroup
25
import net.ccbluex.liquidbounce.config.types.list.Tagged
26
import net.ccbluex.liquidbounce.config.utils.asRefreshable
27
import net.ccbluex.liquidbounce.event.events.KeyEvent
28
import net.ccbluex.liquidbounce.event.suspendHandler
29
import net.ccbluex.liquidbounce.features.command.CommandManager
30
import net.ccbluex.liquidbounce.features.module.ClientModule
31
import net.ccbluex.liquidbounce.features.module.ModuleCategories
32
import net.ccbluex.liquidbounce.utils.aiming.RotationManager
33
import net.ccbluex.liquidbounce.utils.block.SwingMode
34
import net.ccbluex.liquidbounce.utils.block.doPlacement
35
import net.ccbluex.liquidbounce.utils.client.SilentHotbar
36
import net.ccbluex.liquidbounce.utils.client.clientStartDurationMs
37
import net.ccbluex.liquidbounce.utils.network.sendChatOrCommand
38
import net.ccbluex.liquidbounce.utils.inventory.SingleItemStackPickMode
39
import net.ccbluex.liquidbounce.utils.inventory.Slots
40
import net.ccbluex.liquidbounce.utils.entity.useItem
41
import net.ccbluex.liquidbounce.utils.entity.rotation
42
import net.minecraft.world.phys.BlockHitResult
43
import kotlin.time.Duration.Companion.milliseconds
44
45
/**
46
 * Macros module
47
 *
48
 * Lets you execute chat messages or item actions using custom keybinds.
49
 */
50
object ModuleMacros : ClientModule("Macros", ModuleCategories.MISC) {
51
52
    /** We don't have mutable value group list yet */
53
    private const val COUNT = 5
54
55
    private val macros: List<Macro>
56
57
    init {
58
        doNotIncludeAlways()
59
60
        val macros = ArrayList<Macro>()
61
        repeat(COUNT) {
62
            macros += tree(Macro.Chat("Chat-${it + 1}"))
63
        }
64
        repeat(COUNT) {
65
            macros += tree(Macro.UseItem("Item-${it + 1}"))
66
        }
67
        this.macros = macros
68
    }
69
70
    @Suppress("unused")
71
    private val keyboardKeyHandler = suspendHandler<KeyEvent> { event ->
72
        val now = clientStartDurationMs
73
        for (macro in macros) {
74
            if (macro.trigger == event.key && now - macro.lastTriggerTime > macro.triggerDelayMs.current) {
75
                macro.lastTriggerTime = now
76
                macro.triggerDelayMs.refresh()
77
                launch {
78
                    macro.execute()
79
                }
80
            }
81
        }
82
    }
83
84
    private sealed class Macro(name: String) : ValueGroup(name) {
85
86
        var lastTriggerTime = 0L
87
88
        val triggerDelayMs = intRange("TriggerDelay", 0..0, 0..15000, "ms").asRefreshable()
89
90
        val trigger by key("Trigger")
91
92
        abstract suspend fun execute()
93
94
        class Chat(name: String) : Macro(name) {
95
96
            private val delay by intRange("Delay", 0..0, 0..5000, "ms")
97
98
            private val messages by textList("Messages", ArrayList())
99
100
            private val useClientCommand by boolean("UseClientCommand", false)
101
102
            override suspend fun execute() {
103
                for (message in messages) {
104
                    if (useClientCommand && message.startsWith(CommandManager.GlobalSettings.prefix)) {
105
                        CommandManager.execute(message.substring(CommandManager.GlobalSettings.prefix.length))
106
                    } else {
107
                        network.sendChatOrCommand(message)
108
                    }
109
110
                    delay(delay.random().milliseconds)
111
                }
112
            }
113
114
        }
115
116
        class UseItem(name: String) : Macro(name) {
117
118
            private val action by enumChoice("Action", Action.USE_ONLY)
119
120
            private val pickMode = modes(ModuleMacros, "PickMode", 0) {
121
                arrayOf(
122
                    SingleItemStackPickMode.ByName(it),
123
                    SingleItemStackPickMode.ByItem(it),
124
                )
125
            }
126
127
            private val swingMode by enumChoice("SwingMode", SwingMode.DO_NOT_HIDE)
128
            private val holdTime by intRange("HoldTime", 1..1, 1..20, "ticks")
129
130
            private enum class Action(override val tag: String) : Tagged {
131
                USE_ONLY("UseOnly"),
132
                PLACE_OR_USE("PlaceOrUse"),
133
            }
134
135
            override suspend fun execute() {
136
                val slot = Slots.OffhandWithHotbar.findSlot(pickMode.activeMode) ?: return
137
138
                SilentHotbar.selectSlotSilently(ModuleMacros, slot, ticksUntilReset = holdTime.random())
139
                when (action) {
140
                    Action.USE_ONLY -> useItem(slot.useHand, swingMode = swingMode)
141
142
                    Action.PLACE_OR_USE -> {
143
                        val hitResult = mc.hitResult as? BlockHitResult ?: return
144
                        doPlacement(
145
                            hitResult,
146
                            RotationManager.currentRotation ?: player.rotation,
147
                            hand = slot.useHand,
148
                            swingMode = swingMode,
149
                        )
150
                    }
151
                }
152
            }
153
154
        }
155
    }
156
157
    override fun onDisabled() {
158
        SilentHotbar.resetSlot(this)
159
        super.onDisabled()
160
    }
161
162
}
163