AutoClicker module

AutoClicker: Minecraft 26.3 cheat module, full source for every implementation (2 clients: OfflineClient, LiquidBounce (Kotlin)).

2 implementationsCOMBAT

Full module source: 2 implementations

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

OfflineClientCOMBATsrc/main/java/com/jellypudding/offlineclient/modules/combat/AutoClicker.javaJava · 164 lines · 5.8 KB

Clicks the mouse buttons for you.

SettingsLeft clickLeft delayRight clickRight delayIn screens
AutoClicker.javaJava · Minecraft 26.2 · 164 lines · 5.8 KB · complete file, verbatimOriginal ↗
1
package com.jellypudding.offlineclient.modules.combat;
2
3
import com.jellypudding.offlineclient.event.Subscribe;
4
import com.jellypudding.offlineclient.event.events.TickEvent;
5
import com.jellypudding.offlineclient.module.Category;
6
import com.jellypudding.offlineclient.module.Module;
7
import com.jellypudding.offlineclient.setting.BoolSetting;
8
import com.jellypudding.offlineclient.setting.EnumSetting;
9
import com.jellypudding.offlineclient.setting.NumberSetting;
10
import com.jellypudding.offlineclient.util.EntityUtil;
11
import com.jellypudding.offlineclient.util.InputUtil;
12
import com.jellypudding.offlineclient.util.Modules;
13
import net.minecraft.client.KeyMapping;
14
import net.minecraft.world.InteractionHand;
15
import net.minecraft.world.entity.LivingEntity;
16
import net.minecraft.world.phys.EntityHitResult;
17
18
public final class AutoClicker extends Module {
19
20
    public enum Left { OFF, HOLD, PRESS, CROSSHAIR }
21
22
    public enum Right { OFF, HOLD, PRESS }
23
24
    private final EnumSetting<Left> left = new EnumSetting<>("Left click",
25
        "What happens to the attack button.", Left.PRESS)
26
        .describe(Left.OFF, "Leaves the attack button alone.")
27
        .describe(Left.HOLD, "Keeps the attack button held down. Blocks are mined as if you held it yourself.")
28
        .describe(Left.PRESS, "Taps the attack button on a timer.")
29
        .describe(Left.CROSSHAIR,
30
            "Hits the mob or player under your crosshair whilst you hold the attack button. "
31
                + "Waits for the full attack cooldown between hits and never hits a friend.");
32
    private final NumberSetting leftDelay = new NumberSetting("Left delay",
33
        "Ticks between taps of the attack button.", 2, 0, 60, 1, " ticks").min(0)
34
        .under(left, Left.PRESS);
35
    private final EnumSetting<Right> right = new EnumSetting<>("Right click",
36
        "What happens to the use button.", Right.OFF)
37
        .describe(Right.OFF, "Leaves the use button alone.")
38
        .describe(Right.HOLD, "Keeps the use button held down. Blocks are placed and food eaten as if you held it yourself.")
39
        .describe(Right.PRESS, "Taps the use button on a timer.");
40
    private final NumberSetting rightDelay = new NumberSetting("Right delay",
41
        "Ticks between taps of the use button.", 2, 0, 60, 1, " ticks").min(0)
42
        .under(right, Right.PRESS);
43
    private final BoolSetting inScreens = new BoolSetting("In screens",
44
        "Keeps clicking whilst an inventory or another screen is open.", true);
45
46
    private int leftTimer;
47
    private int rightTimer;
48
    private boolean holdingAttack;
49
    private boolean holdingUse;
50
51
    public AutoClicker() {
52
        super("AutoClicker", "Clicks the mouse buttons for you.", Category.COMBAT);
53
        addSettings(left, leftDelay, right, rightDelay, inScreens);
54
        searchTags("auto click", "clicker", "spam click");
55
    }
56
57
    @Override
58
    public String getSuffix() {
59
        return left.getValueString() + " " + right.getValueString();
60
    }
61
62
    @Override
63
    protected void onEnable() {
64
        leftTimer = 0;
65
        rightTimer = 0;
66
    }
67
68
    @Override
69
    protected void onDisable() {
70
        letGo();
71
    }
72
73
    @Subscribe
74
    private void onTick(TickEvent event) {
75
        if (!inGame() || mc.player.isSpectator()) {
76
            letGo();
77
            return;
78
        }
79
        if (!inScreens.isOn() && mc.gui.screen() != null) {
80
            letGo();
81
            return;
82
        }
83
        tickLeft();
84
        tickRight();
85
    }
86
87
    private void tickLeft() {
88
        if (!left.is(Left.HOLD)) {
89
            holdingAttack = release(mc.options.keyAttack, holdingAttack);
90
        }
91
        switch (left.getValue()) {
92
            case OFF -> {
93
            }
94
            case HOLD -> {
95
                InputUtil.hold(mc.options.keyAttack);
96
                holdingAttack = true;
97
            }
98
            case PRESS -> {
99
                if (++leftTimer > leftDelay.getInt()) {
100
                    leftTimer = 0;
101
                    mc.startAttack();
102
                }
103
            }
104
            case CROSSHAIR -> hitCrosshair();
105
        }
106
    }
107
108
    private void tickRight() {
109
        if (!right.is(Right.HOLD)) {
110
            holdingUse = release(mc.options.keyUse, holdingUse);
111
        }
112
        switch (right.getValue()) {
113
            case OFF -> {
114
            }
115
            case HOLD -> {
116
                InputUtil.hold(mc.options.keyUse);
117
                holdingUse = true;
118
            }
119
            case PRESS -> {
120
                if (++rightTimer > rightDelay.getInt()) {
121
                    rightTimer = 0;
122
                    mc.startUseItem();
123
                }
124
            }
125
        }
126
    }
127
128
    // The old helper. Swings on every full cooldown whilst the button is held
129
    // and lands the hit only on a living target that is not a friend.
130
    private void hitCrosshair() {
131
        if (!mc.options.keyAttack.isDown()) {
132
            return;
133
        }
134
        if (mc.player.isUsingItem() || mc.gameMode.isDestroying() || Modules.eating()) {
135
            return;
136
        }
137
        if (mc.player.getAttackStrengthScale(0.5f) < 1) {
138
            return;
139
        }
140
        LivingEntity target = null;
141
        if (mc.hitResult instanceof EntityHitResult hit
142
            && hit.getEntity() instanceof LivingEntity living && living.isAlive()) {
143
            target = living;
144
        }
145
        if (target != null && !EntityUtil.isFriend(target)) {
146
            mc.gameMode.attack(mc.player, target);
147
        }
148
        mc.player.swing(InteractionHand.MAIN_HAND);
149
    }
150
151
    private void letGo() {
152
        holdingAttack = release(mc.options.keyAttack, holdingAttack);
153
        holdingUse = release(mc.options.keyUse, holdingUse);
154
    }
155
156
    // Always false afterwards. Only a key this module pressed is let go of.
157
    private static boolean release(KeyMapping key, boolean held) {
158
        if (held) {
159
            InputUtil.release(key);
160
        }
161
        return false;
162
    }
163
}
164
LiquidBounce (Kotlin)COMBATsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/ModuleAutoClicker.ktKotlin · 280 lines · 9.8 KB

Clicks automatically when holding down the attack button.

SettingsRequiresNoInputDelayOnBrokenObjectiveOnItemUseWeaponCriticalsDelayPostStopUseHoldingItemsForIgnoreBlocksForIgnoreDelayStartOnlyBlock
ModuleAutoClicker.ktKotlin · Minecraft 26.2 · 280 lines · 9.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.combat
20
21
import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet
22
import net.ccbluex.fastutil.enumSetOf
23
import net.ccbluex.liquidbounce.config.types.group.ToggleableValueGroup
24
import net.ccbluex.liquidbounce.config.types.list.Tagged
25
import net.ccbluex.liquidbounce.event.events.PacketEvent
26
import net.ccbluex.liquidbounce.event.events.SprintEvent
27
import net.ccbluex.liquidbounce.event.handler
28
import net.ccbluex.liquidbounce.event.tickHandler
29
import net.ccbluex.liquidbounce.event.tickUntil
30
import net.ccbluex.liquidbounce.event.waitTicks
31
import net.ccbluex.liquidbounce.features.module.ClientModule
32
import net.ccbluex.liquidbounce.features.module.ModuleCategories
33
import net.ccbluex.liquidbounce.features.module.modules.combat.criticals.ModuleCriticals.CriticalsSelectionMode
34
import net.ccbluex.liquidbounce.utils.clicking.Clicker
35
import net.ccbluex.liquidbounce.utils.collection.blockSortedSetOf
36
import net.ccbluex.liquidbounce.utils.collection.itemSortedSetOf
37
import net.ccbluex.liquidbounce.utils.combat.shouldBeAttacked
38
import net.ccbluex.liquidbounce.utils.input.InputTracker.isPressedOnAny
39
import net.ccbluex.liquidbounce.utils.item.WeaponType
40
import net.ccbluex.liquidbounce.utils.kotlin.matchesAny
41
import net.minecraft.client.KeyMapping
42
import net.minecraft.core.registries.BuiltInRegistries
43
import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket
44
import net.minecraft.world.entity.Entity
45
import net.minecraft.world.item.BlockItem
46
import net.minecraft.world.item.Items
47
import net.minecraft.world.level.block.DoorBlock
48
import net.minecraft.world.level.block.FenceGateBlock
49
import net.minecraft.world.level.block.TrapDoorBlock
50
import net.minecraft.world.phys.BlockHitResult
51
import net.minecraft.world.phys.EntityHitResult
52
53
/**
54
 * AutoClicker module
55
 *
56
 * Clicks automatically when holding down a mouse button.
57
 */
58
59
object ModuleAutoClicker : ClientModule("AutoClicker", ModuleCategories.COMBAT, aliases = listOf("TriggerBot")) {
60
61
    object AttackButton : ToggleableValueGroup(this, "Attack", true) {
62
63
        val clicker = tree(Clicker(this, mc.options.keyAttack, simulateAttackKeyDown = true))
64
65
        internal val requiresNoInput by boolean("RequiresNoInput", false)
66
        internal val delayOnBroken by boolean("DelayOnBroken", true)
67
        private val objectiveType by enumChoice("Objective", ObjectiveType.ANY)
68
        private val onItemUse by enumChoice("OnItemUse", Use.WAIT)
69
        private val weapon by multiEnumChoice("Weapon", enumSetOf(WeaponType.ANY), canBeNone = false)
70
        private val criticalsSelectionMode by enumChoice("Criticals", CriticalsSelectionMode.SMART)
71
        private val delayPostStopUse by int("DelayPostStopUse", 0, 0..20, "ticks")
72
73
        private enum class ObjectiveType(override val tag: String) : Tagged {
74
            ENEMY("Enemy"),
75
            ENTITY("Entity"),
76
            BLOCK("Block"),
77
            ANY("Any")
78
        }
79
80
        private enum class Use(override val tag: String) : Tagged {
81
            WAIT("Wait"),
82
            STOP("Stop"),
83
            IGNORE("Ignore")
84
        }
85
86
        fun isOnObjective(): Boolean {
87
            val crosshair = mc.hitResult
88
89
            return when (objectiveType) {
90
                ObjectiveType.ENEMY -> crosshair is EntityHitResult && crosshair.entity.shouldBeAttacked()
91
                ObjectiveType.ENTITY -> crosshair is EntityHitResult
92
                ObjectiveType.BLOCK -> crosshair is BlockHitResult
93
                ObjectiveType.ANY -> true
94
            }
95
        }
96
97
        fun isWeaponSelected(): Boolean = weapon.matchesAny(player.mainHandItem)
98
99
        fun isCriticalHit(entity: Entity): Boolean {
100
            return criticalsSelectionMode.isCriticalHit(entity)
101
        }
102
103
        suspend fun encounterItemUse(): Boolean {
104
            return when (onItemUse) {
105
                Use.WAIT -> {
106
                    tickUntil { !player.isUsingItem }
107
                    waitTicks(delayPostStopUse)
108
                    true
109
                }
110
111
                Use.STOP -> {
112
                    interaction.releaseUsingItem(player)
113
                    waitTicks(delayPostStopUse)
114
                    true
115
                }
116
117
                Use.IGNORE -> false
118
            }
119
        }
120
121
        @Suppress("unused")
122
        private val sprintHandler = handler<SprintEvent> { event ->
123
            if (event.source == SprintEvent.Source.MOVEMENT_TICK || event.source == SprintEvent.Source.INPUT) {
124
                if (!attack || !isOnObjective() || !isWeaponSelected()) {
125
                    return@handler
126
                }
127
128
                val target = mc.hitResult as? EntityHitResult ?: return@handler
129
                if (criticalsSelectionMode.shouldStopSprinting(clicker, target.entity)) {
130
                    event.sprint = false
131
                }
132
            }
133
        }
134
135
    }
136
137
    object UseButton : ToggleableValueGroup(this, "Use", false) {
138
        val clicker = tree(Clicker(this, mc.options.keyUse, null))
139
        internal val holdingItemsForIgnore by items(
140
            "HoldingItemsForIgnore",
141
            default = itemSortedSetOf(
142
                Items.WATER_BUCKET,
143
                Items.LAVA_BUCKET,
144
                Items.ENDER_PEARL,
145
                Items.ENDER_EYE,
146
                Items.PLAYER_HEAD,
147
            ),
148
        )
149
        internal val blocksForIgnore by blocks(
150
            "BlocksForIgnore",
151
            default = BuiltInRegistries.BLOCK.filterTo(blockSortedSetOf()) {
152
                it is DoorBlock || it is FenceGateBlock || it is TrapDoorBlock
153
            },
154
        )
155
        internal val delayStart by boolean("DelayStart", false)
156
        internal val onlyBlock by boolean("OnlyBlock", false)
157
        internal val requiresNoInput by boolean("RequiresNoInput", false)
158
159
        internal var needToWait = true
160
    }
161
162
    private val SPECIAL_ITEMS_FOR_IGNORE = ReferenceOpenHashSet.of(
163
        Items.BED.red,
164
        Items.PLAYER_HEAD,
165
        Items.COMPASS,
166
        Items.EMERALD,
167
        Items.LAPIS_LAZULI,
168
        Items.DYE.green,
169
        Items.DYE.gray,
170
        Items.DYE.pink,
171
        Items.SLIME_BALL,
172
    )
173
174
    init {
175
        tree(AttackButton)
176
        tree(UseButton)
177
    }
178
179
    val attack: Boolean
180
        get() = mc.options.keyAttack.isPressedOnAny || AttackButton.requiresNoInput
181
182
    val use: Boolean
183
        get() = mc.options.keyUse.isPressedOnAny || UseButton.requiresNoInput
184
185
    @Volatile
186
    private var lastFinishBreak = 0L
187
188
    @Suppress("unused")
189
    private val packetHandler = handler<PacketEvent> { event ->
190
        val packet = event.packet
191
        if (packet is ServerboundPlayerActionPacket
192
            && packet.action == ServerboundPlayerActionPacket.Action.STOP_DESTROY_BLOCK
193
        ) {
194
            lastFinishBreak = System.currentTimeMillis()
195
        }
196
    }
197
198
    @Suppress("unused")
199
    private val tickHandler = tickHandler {
200
        AttackButton.run {
201
            if (!enabled || !attack || !isWeaponSelected() || !isOnObjective()) {
202
                return@run
203
            }
204
205
            // Check if the player is breaking a block, if so, return
206
            if (interaction.isDestroying) {
207
                return@run
208
            }
209
210
            if ((System.currentTimeMillis() - lastFinishBreak < 300L) && delayOnBroken) {
211
                return@run
212
            }
213
214
            val crosshairTarget = mc.hitResult
215
            if (crosshairTarget is EntityHitResult) {
216
                ModuleAutoWeapon.onTarget(crosshairTarget.entity)
217
218
                if (!isCriticalHit(crosshairTarget.entity)) {
219
                    return@run
220
                }
221
            }
222
223
            if (player.isUsingItem) {
224
                val encounterItemUse = encounterItemUse()
225
226
                if (encounterItemUse) {
227
                    return@tickHandler
228
                }
229
            }
230
231
            clicker.click {
232
                KeyMapping.click(mc.options.keyAttack.key)
233
                true
234
            }
235
        }
236
237
        UseButton.run {
238
            if (!enabled) return@run
239
240
            if (!use) {
241
                needToWait = true
242
                return@run
243
            }
244
245
            val mainHandStack = player.mainHandItem
246
            val offHandStack = player.offhandItem
247
            if (mainHandStack.item in SPECIAL_ITEMS_FOR_IGNORE && mainHandStack.customName != null) {
248
                return@run
249
            }
250
251
            if (mainHandStack.item in holdingItemsForIgnore || offHandStack.item in holdingItemsForIgnore) {
252
                return@run
253
            }
254
255
            if (onlyBlock && mainHandStack.item !is BlockItem && offHandStack.item !is BlockItem) {
256
                return@run
257
            }
258
259
            val crosshairTarget = mc.hitResult
260
            if (crosshairTarget is BlockHitResult) {
261
                val blockState = mc.level?.getBlockState(crosshairTarget.blockPos)
262
                if (blockState?.block in blocksForIgnore) {
263
                    return@run
264
                }
265
            }
266
267
            if (delayStart && needToWait) {
268
                needToWait = false
269
                waitTicks(2)
270
                return@run
271
            }
272
273
            clicker.click {
274
                KeyMapping.click(mc.options.keyUse.key)
275
                true
276
            }
277
        }
278
    }
279
}
280