From 8f4b68638b14f4ce9f0b76c7f28e063290791b71 Mon Sep 17 00:00:00 2001 From: Eclipses <99494277+EclipsesDev@users.noreply.github.com> Date: Wed, 29 Jan 2025 20:11:51 +0700 Subject: [PATCH] feat(Velocity): Strafe OnlyFacing option (#5467) --- .../combat/velocity/mode/VelocityStrafe.kt | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityStrafe.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityStrafe.kt index 83fff6824f6..b3943f25a94 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityStrafe.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityStrafe.kt @@ -18,10 +18,16 @@ */ package net.ccbluex.liquidbounce.features.module.modules.combat.velocity.mode +import net.ccbluex.liquidbounce.config.types.ToggleableConfigurable +import net.ccbluex.liquidbounce.event.events.GameTickEvent import net.ccbluex.liquidbounce.event.events.PacketEvent import net.ccbluex.liquidbounce.event.events.PlayerMoveEvent import net.ccbluex.liquidbounce.event.handler import net.ccbluex.liquidbounce.event.sequenceHandler +import net.ccbluex.liquidbounce.utils.aiming.RotationManager +import net.ccbluex.liquidbounce.utils.aiming.facingEnemy +import net.ccbluex.liquidbounce.utils.combat.findEnemy +import net.ccbluex.liquidbounce.utils.entity.rotation import net.ccbluex.liquidbounce.utils.entity.sqrtSpeed import net.ccbluex.liquidbounce.utils.entity.withStrafe import net.minecraft.network.packet.s2c.play.EntityVelocityUpdateS2CPacket @@ -34,9 +40,33 @@ internal object VelocityStrafe : VelocityMode("Strafe") { private val delay by int("Delay", 2, 0..10, "ticks") private val strength by float("Strength", 1f, 0.1f..2f) + + object OnlyFacing: ToggleableConfigurable(this, "OnlyFacing", false) { + val range by float("Range", 3.5f, 0.1f..6f) + } + + init { + tree(OnlyFacing) + } + private val untilGround by boolean("UntilGround", false) private var applyStrafe = false + private var shouldStrafe = false + + @Suppress("unused") + private val tickHandler = handler { + if (!OnlyFacing.enabled) return@handler + val target = world.findEnemy(0f..OnlyFacing.range) ?: return@handler + + val isFacingEnemy = facingEnemy( + target, + OnlyFacing.range.toDouble(), + RotationManager.currentRotation ?: player.rotation + ) + + shouldStrafe = isFacingEnemy + } @Suppress("unused") private val packetHandler = sequenceHandler { event -> @@ -44,6 +74,10 @@ internal object VelocityStrafe : VelocityMode("Strafe") { // Check if this is a regular velocity update if ((packet is EntityVelocityUpdateS2CPacket && packet.entityId == player.id) || packet is ExplosionS2CPacket) { + if (OnlyFacing.enabled && !shouldStrafe) { + return@sequenceHandler + } + // A few anti-cheats can be easily tricked by applying the velocity a few ticks after being damaged waitTicks(delay)