11package com.lambda.module.modules.movement
22
3+ import com.lambda.config.groups.RotationSettings
34import com.lambda.context.SafeContext
45import com.lambda.event.events.ClientEvent
56import com.lambda.event.events.MovementEvent
7+ import com.lambda.event.events.RotationEvent
68import 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
712import com.lambda.module.Module
813import com.lambda.module.tag.ModuleTag
914import com.lambda.util.player.MovementUtils.isInputting
1015import com.lambda.util.player.MovementUtils.motionY
1116import com.lambda.util.player.MovementUtils.moveDelta
1217import com.lambda.util.player.MovementUtils.setSpeed
18+ import kotlin.math.atan2
1319
1420// ToDo: Revisit and implement grim strafing
1521object 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