Skip to content

Commit

Permalink
refactor: Speed (#4767)
Browse files Browse the repository at this point in the history
- Yaw Offset can now be used with any speed mode
- AutoWalk not triggering Speed (fixes #4766)
- The Avoid Edge Bump option is now available as a general switch on [Speed]. It may not apply to every mode, but I think it is easier to understand and change if it applies globally.
  • Loading branch information
1zun4 authored Dec 1, 2024
1 parent a3480aa commit 2281316
Show file tree
Hide file tree
Showing 22 changed files with 192 additions and 193 deletions.
4 changes: 0 additions & 4 deletions config/detekt/baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,11 @@
<ID>BracesOnIfStatements:ModuleTimerRange.kt$ModuleTimerRange$if</ID>
<ID>BracesOnIfStatements:RenderShortcuts.kt$else</ID>
<ID>BracesOnIfStatements:RenderShortcuts.kt$if</ID>
<ID>BracesOnIfStatements:SpeedGeneric.kt$SpeedBHopBase$if</ID>
<ID>BracesOnIfStatements:SpeedGrimCollide.kt$SpeedGrimCollide$if</ID>
<ID>BracesOnIfStatements:SpeedHypixelBHop.kt$SpeedHypixelBHop$if</ID>
<ID>BracesOnIfStatements:SpeedPreventDeadlyJump.kt$SpeedPreventDeadlyJump$if</ID>
<ID>BracesOnIfStatements:TargetFinding.kt$BlockPlacementTarget$if</ID>
<ID>BracesOnIfStatements:TargetRenderer.kt$WorldTargetRenderer.GlowingCircle$else</ID>
<ID>BracesOnIfStatements:TargetRenderer.kt$WorldTargetRenderer.GlowingCircle$if</ID>
<ID>CognitiveComplexMethod:AStarMode.kt$AStarMode$override fun enable()</ID>
<ID>CognitiveComplexMethod:AStarMode.kt$AStarMode$private fun findPath(start: Vec3i, end: Vec3i, maxCost: Int, maxIterations: Int = 500): List&lt;Vec3i></ID>
<ID>CognitiveComplexMethod:AutoConfig.kt$AutoConfig$fun handlePossibleAutoConfig(jsonObject: JsonObject)</ID>
<ID>CognitiveComplexMethod:BlockExtensions.kt$fun Block?.isInteractable(blockState: BlockState?): Boolean</ID>
Expand Down Expand Up @@ -124,7 +121,6 @@
<ID>PrintStackTrace:CommandManager.kt$CommandManager$e</ID>
<ID>ReturnCount:IntegrationListener.kt$IntegrationListener$private fun handleScreenSituation(screen: Screen?): Boolean</ID>
<ID>ReturnCount:SpeedAntiCornerBump.kt$SpeedAntiCornerBump$fun getSuggestedJumpDelay( simulatedPlayer: SimulatedPlayer, n: Int = 2, ): Int?</ID>
<ID>SpreadOperator:AStarMode.kt$AStarMode$( Vec3i(-1, 0, 0), // left Vec3i(1, 0, 0), // right *(-9..9).map { Vec3i(0, it, 0) }.toTypedArray(), // up- and down Vec3i(0, 0, -1), // front Vec3i(0, 0, 1) // back )</ID>
<ID>SpreadOperator:ModuleVomit.kt$ModuleVomit$( *emptySlots.map { slot -> CreativeInventoryAction.performFillSlot(randomStack, slot) } .toTypedArray(), *emptySlots.map { slot -> ClickInventoryAction.performThrow(null, slot) } .toTypedArray() )</ID>
<ID>StringLiteralDuplication:AutoQueueGommeDuels.kt$AutoQueueGommeDuels$"AutoPlay"</ID>
<ID>StringLiteralDuplication:ScriptSetting.kt$ScriptSetting$"default"</ID>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ object CriticalsJump : Choice("Jump") {
return ticksTillFall + 1.0f < nextPossibleCrit
}

fun isActive(): Boolean {
private fun isActive(): Boolean {
if (!ModuleCriticals.running) {
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,12 @@ object ModuleSpeed : ClientModule("Speed", Category.MOVEMENT) {
private val notDuringScaffold by boolean("NotDuringScaffold", true)
private val notWhileSneaking by boolean("NotWhileSneaking", false)

private val avoidEdgeBump by boolean("AvoidEdgeBump", true)

init {
tree(OnlyInCombat)
tree(OnlyOnPotionEffect)
tree(SpeedYawOffset)
}

override val running: Boolean
Expand Down Expand Up @@ -133,9 +136,6 @@ object ModuleSpeed : ClientModule("Speed", Category.MOVEMENT) {
else -> true
}

fun shouldDelayJump() = !mc.options.jumpKey.isPressed && (SpeedAntiCornerBump.shouldDelayJump()
|| CriticalsJump.shouldWaitForJump())

private object OnlyInCombat : ToggleableConfigurable(this, "OnlyInCombat", false) {

val modes = choices(this, "Mode", { it.choices[0] },
Expand Down Expand Up @@ -184,4 +184,16 @@ object ModuleSpeed : ClientModule("Speed", Category.MOVEMENT) {
abstract fun checkPotionEffects(): Boolean
}

internal fun doOptimizationsPreventJump(): Boolean {
if (CriticalsJump.running && CriticalsJump.shouldWaitForJump(0.42f)) {
return true
}

if (avoidEdgeBump && SpeedAntiCornerBump.shouldDelayJump()) {
return true
}

return false
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce)
*
* Copyright (c) 2015 - 2024 CCBlueX
*
* LiquidBounce is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LiquidBounce is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>.
*/
package net.ccbluex.liquidbounce.features.module.modules.movement.speed

import net.ccbluex.liquidbounce.config.types.NamedChoice
import net.ccbluex.liquidbounce.config.types.ToggleableConfigurable
import net.ccbluex.liquidbounce.event.events.GameTickEvent
import net.ccbluex.liquidbounce.event.handler
import net.ccbluex.liquidbounce.utils.aiming.Rotation
import net.ccbluex.liquidbounce.utils.aiming.RotationManager
import net.ccbluex.liquidbounce.utils.aiming.RotationsConfigurable
import net.ccbluex.liquidbounce.utils.kotlin.Priority

/**
* Makes you go faster by strafing 45deg
*/
object SpeedYawOffset : ToggleableConfigurable(ModuleSpeed, "YawOffset", false) {

private val yawOffsetMode by enumChoice("YawOffsetMode", YawOffsetMode.AIR)
private val rotationsConfigurable = RotationsConfigurable(this)

private var yaw = 0f

@Suppress("unused")
private val yawOffsetHandler = handler<GameTickEvent> {
when (yawOffsetMode) {
YawOffsetMode.GROUND -> groundYawOffset() // makes you strafe more on ground
YawOffsetMode.AIR -> airYawOffset() // 45deg strafe on air
YawOffsetMode.NONE -> return@handler
}

val rotation = Rotation(player.yaw - yaw, player.pitch)

RotationManager.aimAt(
rotationsConfigurable.toAimPlan(rotation), Priority.NOT_IMPORTANT,
ModuleSpeed
)
}

private fun groundYawOffset(): Float {
yaw = if (player.isOnGround) {
when {
mc.options.forwardKey.isPressed && mc.options.leftKey.isPressed -> 45f
mc.options.forwardKey.isPressed && mc.options.rightKey.isPressed -> -45f
mc.options.backKey.isPressed && mc.options.leftKey.isPressed -> 135f
mc.options.backKey.isPressed && mc.options.rightKey.isPressed -> -135f
mc.options.backKey.isPressed -> 180f
mc.options.leftKey.isPressed -> 90f
mc.options.rightKey.isPressed -> -90f
else -> 0f
}
} else {
0f
}
return 0f
}

private fun airYawOffset(): Float {
yaw = when {
!player.isOnGround &&
mc.options.forwardKey.isPressed &&
!mc.options.leftKey.isPressed &&
!mc.options.rightKey.isPressed
-> -45f

else -> 0f
}
return 0f
}

private enum class YawOffsetMode(override val choiceName: String) : NamedChoice {
GROUND("Ground"),
AIR("Air"),
NONE("None")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,16 @@
*/
package net.ccbluex.liquidbounce.features.module.modules.movement.speed.modes

import net.ccbluex.liquidbounce.config.types.Choice
import net.ccbluex.liquidbounce.config.types.ChoiceConfigurable
import net.ccbluex.liquidbounce.config.types.ToggleableConfigurable
import net.ccbluex.liquidbounce.event.EventListener
import net.ccbluex.liquidbounce.event.events.MovementInputEvent
import net.ccbluex.liquidbounce.event.events.PacketEvent
import net.ccbluex.liquidbounce.event.events.PlayerAfterJumpEvent
import net.ccbluex.liquidbounce.event.events.PlayerJumpEvent
import net.ccbluex.liquidbounce.event.handler
import net.ccbluex.liquidbounce.event.sequenceHandler
import net.ccbluex.liquidbounce.event.tickHandler
import net.ccbluex.liquidbounce.features.module.modules.combat.criticals.modes.CriticalsJump
import net.ccbluex.liquidbounce.features.module.modules.movement.speed.ModuleSpeed
import net.ccbluex.liquidbounce.features.module.modules.movement.speed.SpeedAntiCornerBump
import net.ccbluex.liquidbounce.utils.client.Timer
import net.ccbluex.liquidbounce.utils.entity.moving
import net.ccbluex.liquidbounce.utils.entity.sqrtSpeed
Expand All @@ -54,7 +50,7 @@ import net.minecraft.network.packet.s2c.play.EntityVelocityUpdateS2CPacket
* - Avoid edge bump
*
*/
class SpeedCustom(override val parent: ChoiceConfigurable<*>) : Choice("Custom") {
class SpeedCustom(override val parent: ChoiceConfigurable<*>) : SpeedBHopBase("Custom", parent) {

private class HorizontalModification(parent: EventListener?) : ToggleableConfigurable(parent,
"HorizontalModification", true) {
Expand All @@ -67,7 +63,8 @@ class SpeedCustom(override val parent: ChoiceConfigurable<*>) : Choice("Custom")
*/
private val ticksToBoostOff by int("TicksToBoostOff", 0, 0..20, "ticks")

val repeatable = tickHandler {
@Suppress("unused")
private val tickHandler = tickHandler {
if (!player.moving) {
return@tickHandler
}
Expand All @@ -78,7 +75,8 @@ class SpeedCustom(override val parent: ChoiceConfigurable<*>) : Choice("Custom")
}
}

val onJump = sequenceHandler<PlayerAfterJumpEvent> {
@Suppress("unused")
private val jumpHandler = sequenceHandler<PlayerAfterJumpEvent> {
if (horizontalJumpOffModifier != 0f) {
waitTicks(ticksToBoostOff)

Expand All @@ -97,7 +95,8 @@ class SpeedCustom(override val parent: ChoiceConfigurable<*>) : Choice("Custom")
private val pullDown by float("Pulldown", 0f, 0f..1f)
private val pullDownDuringFall by float("PullDownDuringFall", 0f, 0f..1f)

val repeatable = tickHandler {
@Suppress("unused")
private val tickHandler = tickHandler {
if (!player.moving) {
return@tickHandler
}
Expand All @@ -106,9 +105,10 @@ class SpeedCustom(override val parent: ChoiceConfigurable<*>) : Choice("Custom")
player.velocity.y -= pullDown
}

val onJump = handler<PlayerJumpEvent> {
@Suppress("unused")
private val jumpHandler = handler<PlayerJumpEvent> { event ->
if (jumpHeight != 0.42f) {
it.motion = jumpHeight
event.motion = jumpHeight
}
}

Expand Down Expand Up @@ -143,7 +143,8 @@ class SpeedCustom(override val parent: ChoiceConfigurable<*>) : Choice("Custom")
}
}

val packetHandler = sequenceHandler<PacketEvent> {
@Suppress("unused")
private val packetHandler = sequenceHandler<PacketEvent> {
val packet = it.packet

if (packet is EntityVelocityUpdateS2CPacket && packet.entityId == player.id) {
Expand Down Expand Up @@ -176,9 +177,6 @@ class SpeedCustom(override val parent: ChoiceConfigurable<*>) : Choice("Custom")

private val timerSpeed by float("TimerSpeed", 1f, 0.1f..10f)

private val optimizeForCriticals by boolean("OptimizeForCriticals", true)
private val avoidEdgeBump by boolean("AvoidEdgeBump", true)

init {
tree(Strafe(this))
}
Expand All @@ -194,25 +192,4 @@ class SpeedCustom(override val parent: ChoiceConfigurable<*>) : Choice("Custom")
}
}

@Suppress("unused")
private val handleJump = handler<MovementInputEvent> {
if (!player.moving || doOptimizationsPreventJump()) {
return@handler
}

it.jumping = true
}

private fun doOptimizationsPreventJump(): Boolean {
if (optimizeForCriticals && CriticalsJump.shouldWaitForJump(0.42f)) {
return true
}

if (avoidEdgeBump && SpeedAntiCornerBump.shouldDelayJump()) {
return true
}

return false
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import net.ccbluex.liquidbounce.config.types.ChoiceConfigurable
import net.ccbluex.liquidbounce.event.events.MovementInputEvent
import net.ccbluex.liquidbounce.event.handler
import net.ccbluex.liquidbounce.event.tickHandler
import net.ccbluex.liquidbounce.features.module.modules.movement.speed.ModuleSpeed
import net.ccbluex.liquidbounce.features.module.modules.movement.speed.ModuleSpeed.doOptimizationsPreventJump
import net.ccbluex.liquidbounce.utils.entity.downwards
import net.ccbluex.liquidbounce.utils.entity.moving
import net.ccbluex.liquidbounce.utils.entity.strafe
Expand All @@ -47,16 +47,16 @@ class SpeedLegitHop(override val parent: ChoiceConfigurable<*>) : SpeedBHopBase(
open class SpeedBHopBase(name: String, override val parent: ChoiceConfigurable<*>) : Choice(name) {

@Suppress("unused")
val handleMovementInput = handler<MovementInputEvent> {
if (!player.isOnGround || !player.moving) {
private val handleMovementInput = handler<MovementInputEvent> { event ->
if (!player.isOnGround || !event.directionalInput.isMoving) {
return@handler
}

// We want the player to be able to jump if he wants to
if (!mc.options.jumpKey.isPressed && ModuleSpeed.shouldDelayJump())
if (doOptimizationsPreventJump()) {
return@handler
}

it.jumping = true
event.jumping = true
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ class SpeedBlocksMC(override val parent: ChoiceConfigurable<*>) : Choice("Blocks
player.strafe(speed = 0.0)
}

val repeatable = tickHandler {

@Suppress("unused")
private val tickHandler = tickHandler {
if (player.isOnGround) {
airTicks = 0
canSpeed = true
Expand Down Expand Up @@ -133,7 +133,8 @@ class SpeedBlocksMC(override val parent: ChoiceConfigurable<*>) : Choice("Blocks

}

val jumpEvent = handler<PlayerJumpEvent> {
@Suppress("unused")
private val jumpHandler = handler<PlayerJumpEvent> {
val atLeast = 0.281 + 0.2 * (player.getStatusEffect(StatusEffects.SPEED)?.amplifier ?: 0)
if (!canSpeed) {
return@handler
Expand All @@ -146,9 +147,10 @@ class SpeedBlocksMC(override val parent: ChoiceConfigurable<*>) : Choice("Blocks
player.strafe(speed = player.sqrtSpeed.coerceAtLeast(atLeast) - 0.01)
}

val movementInputEvent = handler<MovementInputEvent> {
if (player.moving) {
it.jumping = true
@Suppress("unused")
private val movementInputHandler = handler<MovementInputEvent> { event ->
if (event.directionalInput.isMoving) {
event.jumping = true
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class SpeedGrimCollide(override val parent: ChoiceConfigurable<*>) : Choice("Gri
*
* This only works on client version being 1.9+.
*/
val tickHandler = handler<PlayerTickEvent> {
@Suppress("unused")
private val tickHandler = handler<PlayerTickEvent> {
if (player.input.movementForward == 0.0f && player.input.movementSideways == 0.0f) { return@handler }
var collisions = 0
val box = player.boundingBox.expand(1.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class SpeedHylexGround(override val parent: ChoiceConfigurable<*>) : Choice("Hyl
super.enable()
}

val repeatable = tickHandler {
@Suppress("unused")
private val tickHandler = tickHandler {
if (!player.isOnGround) {
groundTicks = 0
return@tickHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ import net.ccbluex.liquidbounce.utils.entity.sqrtSpeed
*/
class SpeedHylexLowHop(override val parent: ChoiceConfigurable<*>) : SpeedBHopBase("HylexLowHop", parent) {

var airTicks = 0
val repeatable = tickHandler {
private var airTicks = 0

@Suppress("unused")
private val tickHandler = tickHandler {
if (player.isOnGround) {
airTicks = 0
if (player.moving && player.sqrtSpeed < 0.32) {
Expand Down Expand Up @@ -82,8 +84,8 @@ class SpeedHylexLowHop(override val parent: ChoiceConfigurable<*>) : SpeedBHopBa
}

@Suppress("unused")
private val jumpHandler = handler<PlayerJumpEvent> {
it.motion = 0.33f
private val jumpHandler = handler<PlayerJumpEvent> { event ->
event.motion = 0.33f
}

}
Loading

0 comments on commit 2281316

Please sign in to comment.