SpearKill module

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

1 implementationCOMBAT

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)COMBATsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/ModuleSpearKill.ktKotlin · 174 lines · 7.0 KB

Automatically attacks enemies using a charged spear.

SettingsMaxTargetDistanceMaxSpeedFillColorOutlineColor
ModuleSpearKill.ktKotlin · Minecraft 26.2 · 174 lines · 7.0 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 net.ccbluex.liquidbounce.config.types.group.ToggleableValueGroup
22
import net.ccbluex.liquidbounce.event.events.GameTickEvent
23
import net.ccbluex.liquidbounce.event.events.WorldRenderEvent
24
import net.ccbluex.liquidbounce.event.handler
25
import net.ccbluex.liquidbounce.features.module.ClientModule
26
import net.ccbluex.liquidbounce.features.module.ModuleCategories
27
import net.ccbluex.liquidbounce.render.drawBox
28
import net.ccbluex.liquidbounce.render.engine.type.Color4b
29
import net.ccbluex.liquidbounce.render.renderEnvironment
30
import net.ccbluex.liquidbounce.render.withPositionRelativeToCamera
31
import net.ccbluex.liquidbounce.utils.entity.PositionExtrapolation
32
import net.ccbluex.liquidbounce.utils.entity.isWithinWorldBorder
33
import net.ccbluex.liquidbounce.utils.item.isSpear
34
import net.ccbluex.liquidbounce.utils.raytracing.hasLineOfSight
35
import net.ccbluex.liquidbounce.utils.raytracing.traceFromPlayer
36
import net.minecraft.core.component.DataComponents
37
import net.minecraft.world.entity.LivingEntity
38
import net.minecraft.world.entity.boss.enderdragon.EnderDragon
39
import net.minecraft.world.level.ClipContext
40
import net.minecraft.world.phys.HitResult
41
import net.minecraft.world.phys.Vec3
42
import kotlin.math.ceil
43
import kotlin.math.sqrt
44
45
/**
46
 * Spear kill module
47
 *
48
 * Automatically attacks enemies using a charged spear.
49
 */
50
object ModuleSpearKill : ClientModule("SpearKill", ModuleCategories.COMBAT, aliases = listOf("AutoSpear")) {
51
52
    private val maxTargetDistance by float("MaxTargetDistance", 50f, 3f..200f)
53
    private val maxAllowedSpeed by float("MaxSpeed", 7f, 2f..10f)
54
55
    private object Preview : ToggleableValueGroup(this, "Preview", true) {
56
        val fillColor by color("FillColor", Color4b.RED.alpha(67))
57
        val outlineColor by color("OutlineColor", Color4b.WHITE.alpha(167))
58
    }
59
60
    init {
61
        tree(Preview)
62
    }
63
64
    private val attackMovements = ArrayDeque<Vec3>()
65
    private var previewTarget: LivingEntity? = null
66
67
    internal val currentAttackVelocity get() = currentMovement.length()
68
    internal val currentAttackDirection get() = currentMovement.normalize()
69
    private val currentMovement get() = attackMovements.firstOrNull() ?: Vec3.ZERO
70
71
    private val isUsingSpear get() = player.isUsingItem && player.useItem.isSpear
72
    private val holdingSpear get() = player.mainHandItem.isSpear || player.offhandItem.isSpear
73
74
    private fun resetAttack() {
75
        previewTarget = null
76
        if (attackMovements.isNotEmpty()) player.deltaMovement = Vec3.ZERO
77
        attackMovements.clear()
78
    }
79
80
    private fun findTarget(): Pair<LivingEntity, Double>? {
81
        val eye = player.eyePosition
82
        val lookEnd = eye.add(player.lookAngle.scale(maxTargetDistance.toDouble()))
83
        var best: Pair<LivingEntity, Double>? = null
84
        var bestDist = Double.MAX_VALUE
85
86
        for (entity in world.getEntitiesOfClass(
87
            LivingEntity::class.java,
88
            player.boundingBox.expandTowards(lookEnd.subtract(eye)).inflate(1.0)
89
        ) { it !== player && it.isAlive && it.isWithinWorldBorder && it.boundingBox.clip(eye, lookEnd).isPresent }) {
90
91
            val distSq = player.distanceToSqr(entity)
92
            if (distSq >= bestDist) continue
93
94
            val dist = sqrt(distSq)
95
            if (dist !in 3f..maxTargetDistance || !hasLineOfSight(eye, entity.boundingBox.center)) continue
96
97
            val ticks = ceil(dist / maxAllowedSpeed - 0.5).toInt().coerceAtLeast(1)
98
            val travel = 2.0 * dist * ticks / (2.0 * ticks + 1)
99
100
            val hit = traceFromPlayer(range = travel, block = ClipContext.Block.COLLIDER)
101
            if (hit.type == HitResult.Type.MISS || hit.location.distanceTo(eye) >= travel) {
102
                best = entity to travel
103
                bestDist = distSq
104
            }
105
        }
106
        return best
107
    }
108
109
    private fun createAttackMovement(target: LivingEntity, distance: Double) {
110
        val ticks = ceil(distance / maxAllowedSpeed).toInt().coerceAtLeast(1)
111
        val velocity = distance / ticks
112
113
        val direction = PositionExtrapolation.getBestForEntity(target)
114
            .getPositionInTicks(ticks.toDouble())
115
            .subtract(player.eyePosition)
116
            .normalize()
117
            .takeIf { it.lengthSqr() > 0 } ?: player.lookAngle.normalize()
118
119
        val movement = direction.scale(velocity)
120
        val reverse = movement.scale(-1.0)
121
122
        repeat(ticks) { attackMovements += movement }
123
        repeat(ticks) { attackMovements += reverse }
124
        attackMovements += Vec3.ZERO
125
    }
126
127
    @Suppress("unused")
128
    private val tickHandler = handler<GameTickEvent> {
129
        if (!holdingSpear || !isUsingSpear) {
130
            resetAttack()
131
            return@handler
132
        }
133
134
        val shouldFindTarget = Preview.enabled || (attackMovements.isEmpty() && mc.options.keyAttack.isDown)
135
        val target = if (shouldFindTarget) findTarget() else null
136
        previewTarget = target?.first
137
138
        val kineticWeapon = player.useItem.get(DataComponents.KINETIC_WEAPON) ?: run {
139
            resetAttack()
140
            return@handler
141
        }
142
        val chargeDuration = kineticWeapon.computeDamageUseDuration() - kineticWeapon.delayTicks
143
144
        if (player.ticksUsingItem <= kineticWeapon.delayTicks) {
145
            attackMovements.clear()
146
            return@handler
147
        }
148
149
        if (attackMovements.isEmpty()) {
150
            val (entity, dist) = target ?: return@handler
151
            if (player.ticksUsingItem >= chargeDuration || !mc.options.keyAttack.isDown) return@handler
152
            createAttackMovement(entity, dist)
153
        } else {
154
            player.deltaMovement = attackMovements.removeFirst()
155
        }
156
    }
157
158
    @Suppress("unused")
159
    private val renderHandler = handler<WorldRenderEvent> { event ->
160
        if (!Preview.enabled || !isUsingSpear) return@handler
161
        previewTarget?.let { target ->
162
            event.renderEnvironment {
163
                withPositionRelativeToCamera {
164
                    if (target is EnderDragon) {
165
                        target.subEntities.forEach { drawBox(it.boundingBox, Preview.fillColor, Preview.outlineColor) }
166
                    } else {
167
                        drawBox(target.boundingBox, Preview.fillColor, Preview.outlineColor)
168
                    }
169
                }
170
            }
171
        }
172
    }
173
}
174