Skip to content

Commit dfe0018

Browse files
committed
Speed strafe grim bypass
1 parent 6dea7e8 commit dfe0018

File tree

3 files changed

+95
-53
lines changed

3 files changed

+95
-53
lines changed

common/src/main/java/com/lambda/mixin/input/KeyBindingMixin.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.lambda.mixin.input;
22

3+
import com.lambda.module.modules.movement.Speed;
34
import com.lambda.module.modules.movement.Sprint;
45
import net.minecraft.client.option.KeyBinding;
56
import org.spongepowered.asm.mixin.Mixin;
@@ -17,5 +18,6 @@ void autoSprint(CallbackInfoReturnable<Boolean> cir) {
1718
if (!Objects.equals(instance.getTranslationKey(), "key.sprint")) return;
1819

1920
if (Sprint.INSTANCE.isEnabled()) cir.setReturnValue(true);
21+
if (Speed.INSTANCE.isEnabled() && Speed.getMode() == Speed.Mode.GRIM_STRAFE) cir.setReturnValue(true);
2022
}
2123
}

common/src/main/kotlin/com/lambda/module/modules/movement/SafeWalk.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ object SafeWalk : Module(
1212
defaultTags = setOf(ModuleTag.MOVEMENT, ModuleTag.GRIM)
1313
) {
1414
private val sneakOnLedge by setting("Sneak On Ledge", true)
15-
private val ledgeDistance by setting("Ledge Distance", 0.25, 0.0..0.5, 0.05, unit = " blocks")
16-
private val stepHeight by setting("Minimum Step Height", 1.0, 0.0..4.0, 0.1, unit = " blocks")
15+
private val ledgeDistance by setting("Ledge Distance", 0.2, 0.0..0.5, 0.01, unit = " blocks")
16+
private val stepHeight by setting("Step Height", 1.1, 0.0..4.0, 0.05, unit = " blocks")
1717

1818
init {
1919
listener<MovementEvent.InputUpdate> {

common/src/main/kotlin/com/lambda/module/modules/movement/Speed.kt

Lines changed: 91 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
11
package com.lambda.module.modules.movement
22

3+
import com.lambda.config.groups.RotationSettings
34
import com.lambda.context.SafeContext
45
import com.lambda.event.events.ClientEvent
56
import com.lambda.event.events.MovementEvent
7+
import com.lambda.event.events.RotationEvent
68
import com.lambda.event.listener.SafeListener.Companion.listener
9+
import com.lambda.interaction.rotation.Rotation
10+
import com.lambda.interaction.rotation.Rotation.Companion.rotation
11+
import com.lambda.interaction.rotation.RotationContext
712
import com.lambda.module.Module
813
import com.lambda.module.tag.ModuleTag
914
import com.lambda.util.player.MovementUtils.isInputting
1015
import com.lambda.util.player.MovementUtils.motionY
1116
import com.lambda.util.player.MovementUtils.moveDelta
1217
import com.lambda.util.player.MovementUtils.setSpeed
18+
import kotlin.math.atan2
1319

1420
// ToDo: Revisit and implement grim strafing
1521
object Speed : Module(
1622
name = "Speed",
1723
description = "Fastest module",
1824
defaultTags = setOf(ModuleTag.MOVEMENT)
1925
) {
20-
private val mode by setting("Mode", Mode.NCP_STRAFE)
26+
@JvmStatic val mode by setting("Mode", Mode.GRIM_STRAFE)
27+
28+
// Grim
29+
private val rotation = RotationSettings(this)
2130

2231
// NCP
2332
private val ncpBaseSpeed by setting("Base Speed", 0.2873, 0.1..0.3, 0.0001, visibility = { mode == Mode.NCP_STRAFE })
@@ -30,14 +39,17 @@ object Speed : Module(
3039
private val ncpAutoJump by setting("Auto Jump", false, visibility = { mode == Mode.NCP_STRAFE })
3140
private val ncpTimerBoost by setting("Timer Boost", 1.08, 1.0..1.1, 0.01, visibility = { mode == Mode.NCP_STRAFE })
3241

42+
// Grim
43+
private var desiredRotation = Rotation.ZERO
44+
3345
// NCP
3446
private var ncpPhase = NCPPhase.JUMP
3547
private var ncpSpeed = ncpBaseSpeed
3648
private var lastDistance = 0.0
3749

38-
private enum class Mode {
39-
NCP_STRAFE,
50+
enum class Mode {
4051
GRIM_STRAFE,
52+
NCP_STRAFE,
4153
}
4254

4355
private enum class NCPPhase {
@@ -47,61 +59,40 @@ object Speed : Module(
4759
}
4860

4961
init {
62+
listener<MovementEvent.InputUpdate> {
63+
it.input.let { input ->
64+
val dx = if (input.pressingForward) 1 else if (input.pressingBack) -1 else 0
65+
val dy = if (input.pressingRight) 1 else if (input.pressingLeft) -1 else 0
66+
67+
desiredRotation = if (dx != 0 || dy != 0) {
68+
val angle = Math.toDegrees(atan2(dy.toDouble(), dx.toDouble()))
69+
Rotation(player.yaw + angle.toFloat(), player.pitch)
70+
} else {
71+
Rotation.ZERO
72+
}
73+
}
74+
}
75+
76+
listener<RotationEvent.Pre> {
77+
if (!shouldWork()) return@listener
78+
if (mode != Mode.GRIM_STRAFE) return@listener
79+
if (desiredRotation == Rotation.ZERO) return@listener
80+
81+
it.context = RotationContext(
82+
desiredRotation,
83+
rotation
84+
)
85+
}
86+
5087
listener<MovementEvent.Pre> {
5188
if (!shouldWork()) {
5289
ncpSpeed = ncpBaseSpeed
5390
return@listener
5491
}
5592

5693
when (mode) {
57-
Mode.NCP_STRAFE -> {
58-
val shouldJump = player.input.jumping || (ncpAutoJump && isInputting)
59-
60-
if (player.isOnGround && shouldJump) {
61-
ncpPhase = NCPPhase.JUMP
62-
}
63-
64-
ncpPhase = when (ncpPhase) {
65-
NCPPhase.JUMP -> {
66-
if (player.isOnGround) {
67-
if (ncpResetOnJump) ncpSpeed = ncpBaseSpeed
68-
69-
player.motionY = ncpJumpHeight
70-
ncpSpeed += ncpJumpSpeed
71-
NCPPhase.JUMP_POST
72-
} else NCPPhase.SLOWDOWN
73-
}
74-
75-
NCPPhase.JUMP_POST -> {
76-
ncpSpeed *= ncpJumpDecay
77-
NCPPhase.SLOWDOWN
78-
}
79-
80-
NCPPhase.SLOWDOWN -> {
81-
ncpSpeed = lastDistance * ncpDecay
82-
NCPPhase.SLOWDOWN
83-
}
84-
}
85-
86-
if (player.isOnGround && !shouldJump) {
87-
ncpSpeed = ncpBaseSpeed
88-
}
89-
90-
ncpSpeed = ncpSpeed
91-
.coerceAtMost(ncpMaxSpeed)
92-
.coerceAtLeast(ncpBaseSpeed)
93-
94-
val moveSpeed = if (isInputting) ncpSpeed else {
95-
ncpSpeed = ncpBaseSpeed
96-
0.0
97-
}
98-
99-
setSpeed(moveSpeed)
100-
}
101-
102-
Mode.GRIM_STRAFE -> {
103-
// ToDo: Implement
104-
}
94+
Mode.NCP_STRAFE -> handleStrafe()
95+
Mode.GRIM_STRAFE -> handleGrim()
10596
}
10697
}
10798

@@ -130,6 +121,55 @@ object Speed : Module(
130121
}
131122
}
132123

124+
private fun SafeContext.handleGrim() {
125+
126+
}
127+
128+
private fun SafeContext.handleStrafe() {
129+
val shouldJump = player.input.jumping || (ncpAutoJump && isInputting)
130+
131+
if (player.isOnGround && shouldJump) {
132+
ncpPhase = NCPPhase.JUMP
133+
}
134+
135+
ncpPhase = when (ncpPhase) {
136+
NCPPhase.JUMP -> {
137+
if (player.isOnGround) {
138+
if (ncpResetOnJump) ncpSpeed = ncpBaseSpeed
139+
140+
player.motionY = ncpJumpHeight
141+
ncpSpeed += ncpJumpSpeed
142+
NCPPhase.JUMP_POST
143+
} else NCPPhase.SLOWDOWN
144+
}
145+
146+
NCPPhase.JUMP_POST -> {
147+
ncpSpeed *= ncpJumpDecay
148+
NCPPhase.SLOWDOWN
149+
}
150+
151+
NCPPhase.SLOWDOWN -> {
152+
ncpSpeed = lastDistance * ncpDecay
153+
NCPPhase.SLOWDOWN
154+
}
155+
}
156+
157+
if (player.isOnGround && !shouldJump) {
158+
ncpSpeed = ncpBaseSpeed
159+
}
160+
161+
ncpSpeed = ncpSpeed
162+
.coerceAtMost(ncpMaxSpeed)
163+
.coerceAtLeast(ncpBaseSpeed)
164+
165+
val moveSpeed = if (isInputting) ncpSpeed else {
166+
ncpSpeed = ncpBaseSpeed
167+
0.0
168+
}
169+
170+
setSpeed(moveSpeed)
171+
}
172+
133173
private fun SafeContext.shouldWork() =
134174
!player.abilities.flying
135175
&& !player.isFallFlying

0 commit comments

Comments
 (0)