TargetLock module

TargetLock: 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/ModuleTargetLock.ktKotlin · 190 lines · 6.4 KB

Makes you attack only one specific enemy.

SettingsCombatUsernamesFilterTypeMaximumTimeMaximumRangeWhenNoLock
ModuleTargetLock.ktKotlin · Minecraft 26.2 · 190 lines · 6.4 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.misc
20
21
import it.unimi.dsi.fastutil.ints.Int2LongLinkedOpenHashMap
22
import net.ccbluex.liquidbounce.config.types.group.Mode
23
import net.ccbluex.liquidbounce.config.types.group.ModeValueGroup
24
import net.ccbluex.liquidbounce.config.types.list.Tagged
25
import net.ccbluex.liquidbounce.event.events.AttackEntityEvent
26
import net.ccbluex.liquidbounce.event.events.NotificationEvent
27
import net.ccbluex.liquidbounce.event.events.TagEntityEvent
28
import net.ccbluex.liquidbounce.event.handler
29
import net.ccbluex.liquidbounce.event.tickHandler
30
import net.ccbluex.liquidbounce.features.module.ClientModule
31
import net.ccbluex.liquidbounce.features.module.ModuleCategories
32
import net.ccbluex.liquidbounce.utils.client.notification
33
import net.ccbluex.liquidbounce.utils.math.sq
34
import net.minecraft.client.player.AbstractClientPlayer
35
36
/**
37
 * TargetLock module
38
 *
39
 * Locks on to a target and prevents targeting other entities,
40
 * either [Temporary]ly on attack or by [Filter]ing by username.
41
 */
42
object ModuleTargetLock : ClientModule("TargetLock", ModuleCategories.MISC) {
43
44
    init {
45
        doNotIncludeAlways()
46
    }
47
48
    private val mode = choices("Mode", Temporary, arrayOf(Temporary, Filter))
49
50
    /**
51
     * This option will only lock the enemy on combat modules
52
     */
53
    private val combatOnly by boolean("Combat", false)
54
55
    private sealed class LockMode(name: String) : Mode(name) {
56
        override val parent: ModeValueGroup<*>
57
            get() = mode
58
        abstract fun isLockedOn(playerEntity: AbstractClientPlayer): Boolean
59
    }
60
61
    private object Filter : LockMode("Filter") {
62
63
        private val usernames by textList("Usernames", mutableListOf("Notch"))
64
        private val filterType by enumChoice("FilterType", FilterType.WHITELIST)
65
66
        enum class FilterType(override val tag: String) : Tagged {
67
            WHITELIST("Whitelist"),
68
            BLACKLIST("Blacklist")
69
        }
70
71
        override fun isLockedOn(playerEntity: AbstractClientPlayer): Boolean {
72
            val name = playerEntity.gameProfile.name
73
74
            return when (filterType) {
75
                FilterType.WHITELIST -> usernames.any { it.equals(name, true) }
76
                FilterType.BLACKLIST -> usernames.none {
77
                    it.equals(name, true)
78
                }
79
            }
80
81
        }
82
    }
83
84
    private object Temporary : LockMode("Temporary") {
85
86
        private val timeUntilReset by int("MaximumTime", 30, 0..120, "s")
87
        private val outOfRange by float("MaximumRange", 20f, 8f..40f)
88
89
        private val whenNoLock by enumChoice("WhenNoLock", NoLockMode.ALLOW_ALL)
90
91
        // Combination of [entityId] and [time]
92
        private val lockList = Int2LongLinkedOpenHashMap()
93
94
        enum class NoLockMode(override val tag: String) : Tagged {
95
            ALLOW_ALL("AllowAll"),
96
            ALLOW_NONE("AllowNone")
97
        }
98
99
        @Suppress("unused")
100
        private val attackHandler = handler<AttackEntityEvent> { event ->
101
            val target = event.entity as? AbstractClientPlayer ?: return@handler
102
103
            if (!lockList.containsKey(target.id)) {
104
                notification(
105
                    "TargetLock",
106
                    message("lockedOn", target.gameProfile.name, timeUntilReset),
107
                    NotificationEvent.Severity.INFO
108
                )
109
            }
110
            lockList.put(target.id, System.currentTimeMillis() + timeUntilReset * 1000L)
111
        }
112
113
        @Suppress("unused")
114
        private val cleanUpTask = tickHandler {
115
            if (player.isDeadOrDying) {
116
                lockList.clear()
117
                return@tickHandler
118
            }
119
120
            val currentTime = System.currentTimeMillis()
121
            lockList.int2LongEntrySet().removeIf {
122
                val entityId = it.intKey
123
                val time = it.longValue
124
                // Remove if entity is out of range
125
                val entity = world.getEntity(entityId) as? AbstractClientPlayer ?: return@removeIf true
126
127
                if (entity.isRemoved || entity.distanceToSqr(player) > outOfRange.sq()) {
128
                    notification(
129
                        "TargetLock",
130
                        message("outOfRange", entity.gameProfile.name),
131
                        NotificationEvent.Severity.INFO
132
                    )
133
                    return@removeIf true
134
                }
135
136
                // Remove if time is up
137
                if (time < currentTime) {
138
                    notification(
139
                        "TargetLock",
140
                        message("timeUp", entity.gameProfile.name),
141
                        NotificationEvent.Severity.INFO
142
                    )
143
                    return@removeIf true
144
                }
145
146
                false
147
            }
148
        }
149
150
        override fun isLockedOn(playerEntity: AbstractClientPlayer): Boolean {
151
            val entityId = playerEntity.id
152
153
            if (lockList.isEmpty()) {
154
                return when (whenNoLock) {
155
                    NoLockMode.ALLOW_ALL -> true
156
                    NoLockMode.ALLOW_NONE -> false
157
                }
158
            }
159
160
            return lockList.containsKey(entityId)
161
        }
162
163
    }
164
165
    @Suppress("unused")
166
    private val tagEntityEvent = handler<TagEntityEvent> { event ->
167
        if (event.entity !is AbstractClientPlayer || this@ModuleTargetLock.isLockedOn(event.entity)) {
168
            return@handler
169
        }
170
171
        if (combatOnly) {
172
            event.dontTarget()
173
        } else {
174
           event.ignore()
175
        }
176
    }
177
178
    /**
179
     * Check if [entity] is in your focus
180
     */
181
    private fun isLockedOn(entity: AbstractClientPlayer): Boolean {
182
        if (!running) {
183
            return false
184
        }
185
186
        return mode.activeMode.isLockedOn(entity)
187
    }
188
189
}
190