Skip to content

Commit

Permalink
feat(Velocity): Strafe OnlyFacing option (#5467)
Browse files Browse the repository at this point in the history
  • Loading branch information
EclipsesDev authored Jan 29, 2025
1 parent 3b49aac commit 8f4b686
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,16 +40,44 @@ 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<GameTickEvent> {
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<PacketEvent> { event ->
val packet = event.packet

// 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)

Expand Down

0 comments on commit 8f4b686

Please sign in to comment.