Skip to content

Commit

Permalink
fix(Step): check can step on motion-type modes (#4684)
Browse files Browse the repository at this point in the history
  • Loading branch information
1zun4 authored Nov 25, 2024
1 parent a61584b commit e019e17
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ import net.ccbluex.liquidbounce.event.repeatable
import net.ccbluex.liquidbounce.event.sequenceHandler
import net.ccbluex.liquidbounce.features.module.Category
import net.ccbluex.liquidbounce.features.module.Module
import net.ccbluex.liquidbounce.features.module.modules.movement.speed.ModuleSpeed
import net.ccbluex.liquidbounce.features.module.modules.render.ModuleDebug
import net.ccbluex.liquidbounce.utils.client.MovePacketType
import net.ccbluex.liquidbounce.utils.client.Timer
import net.ccbluex.liquidbounce.utils.entity.canStep
import net.ccbluex.liquidbounce.utils.entity.strafe
import net.ccbluex.liquidbounce.utils.kotlin.Priority
import net.minecraft.stat.Stats
Expand Down Expand Up @@ -102,21 +104,24 @@ object ModuleStep : Module("Step", Category.MOVEMENT) {

private var ticksWait = 0

val repeatable = repeatable {
@Suppress("unused")
private val tickHandler = repeatable {
if (ticksWait > 0) {
ticksWait--
}
}

val stepHandler = handler<PlayerStepEvent> {
@Suppress("unused")
private val stepHandler = handler<PlayerStepEvent> {
if (ticksWait > 0) {
return@handler
}

it.height = height
}

val stepSuccessEvent = handler<PlayerStepSuccessEvent> { event ->
@Suppress("unused")
private val stepSuccessEvent = handler<PlayerStepSuccessEvent> { event ->
val stepHeight = event.adjustedVec.y

ModuleDebug.debugParameter(ModuleStep, "StepHeight", stepHeight)
Expand Down Expand Up @@ -169,9 +174,10 @@ object ModuleStep : Module("Step", Category.MOVEMENT) {
private var stepCounter = 0
private var stepping = false

val movementInputHandler = sequenceHandler<MovementInputEvent> {
if (player.isOnGround && player.horizontalCollision && !stepping) {
it.jumping = true
@Suppress("unused")
private val movementInputHandler = sequenceHandler<MovementInputEvent> { event ->
if (player.canStep(1.0) && !stepping) {
event.jumping = true
stepCounter++

stepping = true
Expand Down Expand Up @@ -202,7 +208,7 @@ object ModuleStep : Module("Step", Category.MOVEMENT) {
/**
* BlocksMC Step
* for 1.9+
*
*
* @author @liquidsquid1
*/
object BlocksMC : Choice("BlocksMC") {
Expand All @@ -215,9 +221,10 @@ object ModuleStep : Module("Step", Category.MOVEMENT) {

var stepping = false

val movementInputHandler = sequenceHandler<MovementInputEvent> {
if (player.isOnGround && player.horizontalCollision && !stepping) {
it.jumping = true
@Suppress("unused")
private val movementInputHandler = sequenceHandler<MovementInputEvent> { event ->
if (player.canStep(1.0) && !stepping) {
event.jumping = true

stepping = true
Timer.requestTimerSpeed(baseTimer, Priority.IMPORTANT_FOR_USAGE_1, ModuleStep, 3)
Expand All @@ -239,6 +246,7 @@ object ModuleStep : Module("Step", Category.MOVEMENT) {
super.disable()
}

override fun handleEvents() = super.handleEvents() && !ModuleSpeed.enabled

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import kotlin.math.floor
import kotlin.math.sin
import kotlin.math.sqrt


val ClientPlayerEntity.moving
get() = input.movementForward != 0.0f || input.movementSideways != 0.0f

Expand Down Expand Up @@ -131,7 +132,36 @@ val ClientPlayerEntity.directionYaw: Float
get() = getMovementDirectionOfInput(this.yaw, DirectionalInput(this.input))

val ClientPlayerEntity.isBlockAction: Boolean
get() = player.isUsingItem && player.activeItem.useAction == UseAction.BLOCK
get() = isUsingItem && activeItem.useAction == UseAction.BLOCK

/**
* Check if the player can step up by [height] blocks.
*
* TODO: Use Minecraft Step logic instead of this basic collision check.
*/
fun ClientPlayerEntity.canStep(height: Double = 1.0): Boolean {
if (!horizontalCollision || isDescending || !isOnGround) {
// If we are not colliding with anything, we are not meant to step
return false
}

val box = this.boundingBox
val direction = this.directionYaw

val angle = Math.toRadians(direction.toDouble())
val xOffset = -sin(angle) * 0.1
val zOffset = cos(angle) * 0.1

val offsetBox = box.offset(xOffset, 0.0, zOffset)
val stepBox = offsetBox.offset(0.0, height, 0.0)

return world.getBlockCollisions(this, stepBox).all { shape ->
shape == VoxelShapes.empty()
} && world.getBlockCollisions(this, offsetBox).all { shape ->
shape != VoxelShapes.empty()
}
}


fun getMovementDirectionOfInput(facingYaw: Float, input: DirectionalInput): Float {
var actualYaw = facingYaw
Expand Down

0 comments on commit e019e17

Please sign in to comment.