diff --git a/src/main/kotlin/com/lambda/client/module/modules/combat/HoleSnap.kt b/src/main/kotlin/com/lambda/client/module/modules/combat/HoleSnap.kt index f590ca671..822595039 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/combat/HoleSnap.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/combat/HoleSnap.kt @@ -94,7 +94,7 @@ object HoleSnap : Module( } getHole()?.let { - if (disableStrafe && Speed.mode.value == Speed.SpeedMode.STRAFE) Speed.disable() + if (disableStrafe && Speed.isStrafing()) Speed.disable() if ((airStrafe || player.onGround) && !player.isCentered(it)) { val playerPos = player.positionVector val targetPos = Vec3d(it.x + 0.5, player.posY, it.z + 0.5) diff --git a/src/main/kotlin/com/lambda/client/module/modules/combat/Surround.kt b/src/main/kotlin/com/lambda/client/module/modules/combat/Surround.kt index f8dde7012..827cd1b4c 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/combat/Surround.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/combat/Surround.kt @@ -101,7 +101,7 @@ object Surround : Module( // Centered check if (!player.centerPlayer()) return@safeListener - if (disableStrafe && Speed.mode.value == Speed.SpeedMode.STRAFE) { + if (disableStrafe && Speed.isStrafing()) { Speed.disable() } diff --git a/src/main/kotlin/com/lambda/client/module/modules/movement/Speed.kt b/src/main/kotlin/com/lambda/client/module/modules/movement/Speed.kt index e9efe31c9..7fce3a503 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/movement/Speed.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/movement/Speed.kt @@ -12,9 +12,7 @@ import com.lambda.client.module.Module import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.EntityUtils.isInOrAboveLiquid import com.lambda.client.util.MovementUtils -import com.lambda.client.util.MovementUtils.applySpeedPotionEffects import com.lambda.client.util.MovementUtils.calcMoveYaw -import com.lambda.client.util.threads.runSafe import com.lambda.client.util.threads.safeListener import net.minecraft.network.play.client.CPacketPlayer import net.minecraft.network.play.server.SPacketPlayerPosLook @@ -33,28 +31,39 @@ object Speed : Module( modulePriority = 100 ) { // General settings - val mode = setting("Mode", SpeedMode.STRAFE) + private val mode by setting("Mode", Mode.STRAFE).apply { + listeners.add { + resetTimer() + } + } // Strafe settings - private val strafeAirSpeedBoost by setting("Strafe Speed", StrafeMode.Normal) - private val strafeOnlyOverhead by setting("Require Roof", false, { mode.value == SpeedMode.STRAFE }) - private val strafeOnHoldingSprint by setting("On Holding Sprint", false, { mode.value == SpeedMode.STRAFE }) + private val strafeBaseSpeed by setting("Base Speed", 0.2873, 0.1..0.3, 0.0001, { mode == Mode.STRAFE }) + private val strafeMaxSpeed by setting("Max Speed", 1.0, 0.3..1.0, 0.0001, { mode == Mode.STRAFE }) + private val strafeDecay by setting("Strafe Decay", 0.9937, 0.9..1.0, 0.0001, { mode == Mode.STRAFE }) + private val strafeJumpSpeed by setting("Jump Speed", 0.3, 0.0..1.0, 0.0001, { mode == Mode.STRAFE }) + private val strafeJumpHeight by setting("Jump Height", 0.42, 0.1..0.5, 0.0001, { mode == Mode.STRAFE }) + private val strafeJumpDecay by setting("Jump Decay", 0.59, 0.1..1.0, 0.0001, { mode == Mode.STRAFE }) + private val strafeResetOnJump by setting("Reset On Jump", true, { mode == Mode.STRAFE }) + private val strafeTimer by setting("Strafe Timer", 1.09f, 1.0f..1.1f, 0.01f, { mode == Mode.STRAFE }) + private val strafeAutoJump by setting("Auto Jump", false, { mode == Mode.STRAFE }) // YPort settings - private val yPortAccelerate by setting("Accelerate", true, { mode.value == SpeedMode.YPORT }) - private val yPortStrict by setting("Head Strict", false, { mode.value == SpeedMode.YPORT }, description = "Only allow YPort when you are under a block") - private val yPortAirStrict by setting("Air Strict", false, { mode.value == SpeedMode.YPORT }, description = "Force YPort to handle Y movement differently, slows this down A LOT") - private val yPortMaxSpeed by setting("Maximum Speed", 0.0, 0.0..2.0, 0.001, { mode.value == SpeedMode.YPORT }) - private val yPortAcceleration by setting("Acceleration Speed", 2.149, 1.0..5.0, 0.001, { mode.value == SpeedMode.YPORT }) - private val yPortDecay by setting("Decay Amount", 0.66, 0.0..1.0, 0.001, { mode.value == SpeedMode.YPORT }) + private val yPortAccelerate by setting("Accelerate", true, { mode == Mode.Y_PORT }) + private val yPortStrict by setting("Head Strict", false, { mode == Mode.Y_PORT }, description = "Only allow YPort when you are under a block") + private val yPortAirStrict by setting("Air Strict", false, { mode == Mode.Y_PORT }, description = "Force YPort to handle Y movement differently, slows this down A LOT") + private val yPortMaxSpeed by setting("Maximum Speed", 0.0, 0.0..2.0, 0.001, { mode == Mode.Y_PORT }) + private val yPortAcceleration by setting("Acceleration Speed", 2.149, 1.0..5.0, 0.001, { mode == Mode.Y_PORT }) + private val yPortDecay by setting("YPort Decay", 0.66, 0.0..1.0, 0.001, { mode == Mode.Y_PORT }) + private val yPortTimer by setting("YPort Timer", 1.09f, 1.0f..1.1f, 0.01f, { mode == Mode.Y_PORT }) - private const val TIMER_SPEED = 45.922115f + private const val NCP_BASE_SPEED = 0.2873 // yport stuff - private var currentSpeed = .2873 + private var currentSpeed = NCP_BASE_SPEED private var currentY = 0.0 - private var strafePhase = StrafePhase.ACCELERATING + private var strafePhase = StrafePhase.FALLING private var yPortPhase = YPortPhase.WALKING private var prevYPortPhase = YPortPhase.WALKING @@ -76,27 +85,23 @@ object Speed : Module( } private enum class StrafePhase { - // to jump and accelerate - ACCELERATING, + // to jump + JUMP, + // to slowdown on the next tick after jump + JUMP_SLOWDOWN, // to fall to the ground - SLOWDOWN, - // to slowly fall to the ground FALLING } - enum class SpeedMode(override val displayName: String) : DisplayEnum { - STRAFE("Strafe"), - YPORT("YPort") - } - - enum class StrafeMode { - Normal, Strict + private enum class Mode(override val displayName: String, val move: SafeClientEvent.(e: PlayerMoveEvent) -> Unit) : DisplayEnum { + STRAFE("Strafe", { handleStrafe(it) }), + Y_PORT("YPort", { handleBoost(it) }), } init { onEnable { - currentSpeed = .2873 - strafePhase = StrafePhase.ACCELERATING + currentSpeed = if (mode == Mode.Y_PORT) NCP_BASE_SPEED else strafeBaseSpeed + strafePhase = StrafePhase.FALLING yPortPhase = YPortPhase.WALKING prevYPortPhase = YPortPhase.WALKING goUp = false @@ -104,29 +109,19 @@ object Speed : Module( } onDisable { - runSafe { - reset() - } + resetTimer() } safeListener { lastDistance = hypot(player.posX - player.prevPosX, player.posZ - player.prevPosZ) } - safeListener { - when (mode.value) { - SpeedMode.STRAFE -> { - handleStrafe(it) - } - - SpeedMode.YPORT -> { - handleBoost(it) - } - } + safeListener { event -> + mode.move(this, event) } safeListener { - if (mode.value != SpeedMode.YPORT + if (mode != Mode.Y_PORT || it.packet !is CPacketPlayer || !goUp ) return@safeListener @@ -143,10 +138,9 @@ object Speed : Module( val unModOffset = offset - if (currentY + unModOffset > 0) + if (currentY + unModOffset > 0) { offset += currentY - else if (yPortAirStrict && yPortPhase == YPortPhase.FALLING && prevYPortPhase == YPortPhase.FALLING) { - + } else if (yPortAirStrict && yPortPhase == YPortPhase.FALLING && prevYPortPhase == YPortPhase.FALLING) { var predictedY = currentY predictedY -= 0.08 predictedY *= 0.9800000190734863 // 0.333200006 vs 0.341599999 @@ -162,7 +156,7 @@ object Speed : Module( } safeListener { - if (mode.value != SpeedMode.YPORT || it.packet !is SPacketPlayerPosLook) return@safeListener + if (mode != Mode.Y_PORT || it.packet !is SPacketPlayerPosLook) return@safeListener currentSpeed = 0.0 currentY = 0.0 @@ -170,36 +164,21 @@ object Speed : Module( // 3 extra ticks at base speed yPortPhase = YPortPhase.WAITING } - - mode.listeners.add { - runSafe { reset() } - } - } - - private fun SafeClientEvent.shouldStrafe(): Boolean = - !player.capabilities.isFlying - && !player.isElytraFlying - && !BaritoneUtils.isPathing - && MovementUtils.isInputting - - private fun SafeClientEvent.reset() { - player.jumpMovementFactor = 0.02f - resetTimer() } private fun SafeClientEvent.handleBoost(event: PlayerMoveEvent) { - if (player.movementInput.moveForward == 0f && player.movementInput.moveStrafe == 0f + if (!MovementUtils.isInputting || player.isInOrAboveLiquid || mc.gameSettings.keyBindJump.isKeyDown || !player.onGround || !world.collidesWithAnyBlock(player.entityBoundingBox.offset(0.0, 0.42, 0.0)) && yPortStrict ) { resetTimer() - currentSpeed = .2873 + currentSpeed = NCP_BASE_SPEED return } - modifyTimer(TIMER_SPEED) + modifyTimer(50f / yPortTimer) prevYPortPhase = yPortPhase @@ -215,9 +194,9 @@ object Speed : Module( YPortPhase.SLOWDOWN -> { // NCP says hDistDiff >= 0.66 * (lastMove.hDistance - hDistanceBaseRef) currentSpeed = if (yPortAccelerate) { - lastDistance - yPortDecay * (lastDistance - .2873) + lastDistance - yPortDecay * (lastDistance - NCP_BASE_SPEED) } else { - .2873 + NCP_BASE_SPEED } yPortPhase = YPortPhase.ACCELERATING goUp = false @@ -226,9 +205,9 @@ object Speed : Module( YPortPhase.FALLING -> { if (prevYPortPhase == YPortPhase.WALKING) { currentSpeed = if (yPortAccelerate) { - lastDistance - yPortDecay * (lastDistance - .2873) + lastDistance - yPortDecay * (lastDistance - NCP_BASE_SPEED) } else { - .2873 + NCP_BASE_SPEED } } @@ -241,8 +220,8 @@ object Speed : Module( } else -> { - currentSpeed = max(currentSpeed, .2873) - yPortPhase = YPortPhase.values()[yPortPhase.ordinal + 1 % YPortPhase.values().size] + currentSpeed = max(currentSpeed, NCP_BASE_SPEED) + yPortPhase = YPortPhase.entries.toTypedArray()[yPortPhase.ordinal + 1 % YPortPhase.entries.size] goUp = false } } @@ -261,47 +240,66 @@ object Speed : Module( } private fun SafeClientEvent.handleStrafe(event: PlayerMoveEvent) { - if (!shouldStrafe()) { + val inputting = MovementUtils.isInputting + + if (player.capabilities.isFlying + || player.isElytraFlying + || BaritoneUtils.isPathing + ) { + currentSpeed = strafeBaseSpeed resetTimer() - event.x = .0 - event.z = .0 - currentSpeed = .2873 return } - if (strafeOnlyOverhead && !world.collidesWithAnyBlock(player.entityBoundingBox.offset(.0,.42,.0)) - || strafeOnHoldingSprint && !mc.gameSettings.keyBindSprint.isKeyDown) - return + modifyTimer(50f / strafeTimer) + + val shouldJump = player.movementInput.jump || (inputting && strafeAutoJump) - modifyTimer(TIMER_SPEED) + if (player.onGround && shouldJump) { + strafePhase = StrafePhase.JUMP + } - val base = applySpeedPotionEffects(.2873) + strafePhase = when (strafePhase) { + StrafePhase.JUMP -> { + if (player.onGround) { + event.y = strafeJumpHeight - if (player.onGround) - strafePhase = StrafePhase.ACCELERATING + if (strafeResetOnJump) currentSpeed = strafeBaseSpeed + currentSpeed += strafeJumpSpeed - when (strafePhase) { - StrafePhase.ACCELERATING -> { - if (player.onGround) - event.y = .42 - currentSpeed = base - currentSpeed *= if (strafeAirSpeedBoost == StrafeMode.Strict) 1.87 else 1.93 - strafePhase = StrafePhase.SLOWDOWN + StrafePhase.JUMP_SLOWDOWN + } else StrafePhase.FALLING } - StrafePhase.SLOWDOWN -> { - currentSpeed -= .66 * base - strafePhase = StrafePhase.FALLING + StrafePhase.JUMP_SLOWDOWN -> { + currentSpeed *= strafeJumpDecay + StrafePhase.FALLING } StrafePhase.FALLING -> { - currentSpeed = lastDistance - lastDistance / 159 + currentSpeed = lastDistance * strafeDecay + StrafePhase.FALLING } } - val yaw = calcMoveYaw() - currentSpeed = currentSpeed.coerceAtLeast(.2873) - event.x = -sin(yaw) * currentSpeed - event.z = cos(yaw) * currentSpeed + if (player.onGround && !shouldJump) { + currentSpeed = strafeBaseSpeed + } + + currentSpeed = currentSpeed.coerceAtLeast(strafeBaseSpeed).coerceAtMost(strafeMaxSpeed) + + val moveSpeed = if (!inputting) { + currentSpeed = strafeBaseSpeed + resetTimer() + + 0.0 + } else currentSpeed + + val dir = calcMoveYaw() + event.x = -sin(dir) * moveSpeed + event.z = cos(dir) * moveSpeed } + + // For HoleSnap & Surround + fun isStrafing() = mode == Mode.STRAFE }