@@ -12,9 +12,7 @@ import com.lambda.client.module.Module
1212import com.lambda.client.util.BaritoneUtils
1313import com.lambda.client.util.EntityUtils.isInOrAboveLiquid
1414import com.lambda.client.util.MovementUtils
15- import com.lambda.client.util.MovementUtils.applySpeedPotionEffects
1615import com.lambda.client.util.MovementUtils.calcMoveYaw
17- import com.lambda.client.util.threads.runSafe
1816import com.lambda.client.util.threads.safeListener
1917import net.minecraft.network.play.client.CPacketPlayer
2018import net.minecraft.network.play.server.SPacketPlayerPosLook
@@ -33,28 +31,39 @@ object Speed : Module(
3331 modulePriority = 100
3432) {
3533 // General settings
36- val mode = setting(" Mode" , SpeedMode .STRAFE )
34+ private val mode by setting(" Mode" , Mode .STRAFE ).apply {
35+ listeners.add {
36+ resetTimer()
37+ }
38+ }
3739
3840 // Strafe settings
39- private val strafeAirSpeedBoost by setting(" Strafe Speed" , StrafeMode .Normal )
40- private val strafeOnlyOverhead by setting(" Require Roof" , false , { mode.value == SpeedMode .STRAFE })
41- private val strafeOnHoldingSprint by setting(" On Holding Sprint" , false , { mode.value == SpeedMode .STRAFE })
41+ private val strafeBaseSpeed by setting(" Base Speed" , 0.2873 , 0.1 .. 0.3 , 0.0001 , { mode == Mode .STRAFE })
42+ private val strafeMaxSpeed by setting(" Max Speed" , 1.0 , 0.3 .. 1.0 , 0.0001 , { mode == Mode .STRAFE })
43+ private val strafeDecay by setting(" Strafe Decay" , 0.9937 , 0.9 .. 1.0 , 0.0001 , { mode == Mode .STRAFE })
44+ private val strafeJumpSpeed by setting(" Jump Speed" , 0.3 , 0.0 .. 1.0 , 0.0001 , { mode == Mode .STRAFE })
45+ private val strafeJumpHeight by setting(" Jump Height" , 0.42 , 0.1 .. 0.5 , 0.0001 , { mode == Mode .STRAFE })
46+ private val strafeJumpDecay by setting(" Jump Decay" , 0.59 , 0.1 .. 1.0 , 0.0001 , { mode == Mode .STRAFE })
47+ private val strafeResetOnJump by setting(" Reset On Jump" , true , { mode == Mode .STRAFE })
48+ private val strafeTimer by setting(" Strafe Timer" , 1.09f , 1.0f .. 1.1f , 0.01f , { mode == Mode .STRAFE })
49+ private val strafeAutoJump by setting(" Auto Jump" , false , { mode == Mode .STRAFE })
4250
4351 // YPort settings
44- private val yPortAccelerate by setting(" Accelerate" , true , { mode.value == SpeedMode .YPORT })
45- private val yPortStrict by setting(" Head Strict" , false , { mode.value == SpeedMode .YPORT }, description = " Only allow YPort when you are under a block" )
46- private val yPortAirStrict by setting(" Air Strict" , false , { mode.value == SpeedMode .YPORT }, description = " Force YPort to handle Y movement differently, slows this down A LOT" )
47- private val yPortMaxSpeed by setting(" Maximum Speed" , 0.0 , 0.0 .. 2.0 , 0.001 , { mode.value == SpeedMode .YPORT })
48- private val yPortAcceleration by setting(" Acceleration Speed" , 2.149 , 1.0 .. 5.0 , 0.001 , { mode.value == SpeedMode .YPORT })
49- private val yPortDecay by setting(" Decay Amount" , 0.66 , 0.0 .. 1.0 , 0.001 , { mode.value == SpeedMode .YPORT })
52+ private val yPortAccelerate by setting(" Accelerate" , true , { mode == Mode .Y_PORT })
53+ private val yPortStrict by setting(" Head Strict" , false , { mode == Mode .Y_PORT }, description = " Only allow YPort when you are under a block" )
54+ private val yPortAirStrict by setting(" Air Strict" , false , { mode == Mode .Y_PORT }, description = " Force YPort to handle Y movement differently, slows this down A LOT" )
55+ private val yPortMaxSpeed by setting(" Maximum Speed" , 0.0 , 0.0 .. 2.0 , 0.001 , { mode == Mode .Y_PORT })
56+ private val yPortAcceleration by setting(" Acceleration Speed" , 2.149 , 1.0 .. 5.0 , 0.001 , { mode == Mode .Y_PORT })
57+ private val yPortDecay by setting(" YPort Decay" , 0.66 , 0.0 .. 1.0 , 0.001 , { mode == Mode .Y_PORT })
58+ private val yPortTimer by setting(" YPort Timer" , 1.09f , 1.0f .. 1.1f , 0.01f , { mode == Mode .Y_PORT })
5059
51- private const val TIMER_SPEED = 45.922115f
60+ private const val NCP_BASE_SPEED = 0.2873
5261
5362 // yport stuff
54- private var currentSpeed = . 2873
63+ private var currentSpeed = NCP_BASE_SPEED
5564 private var currentY = 0.0
5665
57- private var strafePhase = StrafePhase .ACCELERATING
66+ private var strafePhase = StrafePhase .FALLING
5867
5968 private var yPortPhase = YPortPhase .WALKING
6069 private var prevYPortPhase = YPortPhase .WALKING
@@ -76,57 +85,43 @@ object Speed : Module(
7685 }
7786
7887 private enum class StrafePhase {
79- // to jump and accelerate
80- ACCELERATING ,
88+ // to jump
89+ JUMP ,
90+ // to slowdown on the next tick after jump
91+ JUMP_SLOWDOWN ,
8192 // to fall to the ground
82- SLOWDOWN ,
83- // to slowly fall to the ground
8493 FALLING
8594 }
8695
87- enum class SpeedMode (override val displayName : String ) : DisplayEnum {
88- STRAFE (" Strafe" ),
89- YPORT (" YPort" )
90- }
91-
92- enum class StrafeMode {
93- Normal , Strict
96+ private enum class Mode (override val displayName : String , val move : SafeClientEvent .(e: PlayerMoveEvent ) -> Unit ) : DisplayEnum {
97+ STRAFE (" Strafe" , { handleStrafe(it) }),
98+ Y_PORT (" YPort" , { handleBoost(it) }),
9499 }
95100
96101 init {
97102 onEnable {
98- currentSpeed = . 2873
99- strafePhase = StrafePhase .ACCELERATING
103+ currentSpeed = if (mode == Mode . Y_PORT ) NCP_BASE_SPEED else strafeBaseSpeed
104+ strafePhase = StrafePhase .FALLING
100105 yPortPhase = YPortPhase .WALKING
101106 prevYPortPhase = YPortPhase .WALKING
102107 goUp = false
103108 currentY = 0.0
104109 }
105110
106111 onDisable {
107- runSafe {
108- reset()
109- }
112+ resetTimer()
110113 }
111114
112115 safeListener<TickEvent .ClientTickEvent > {
113116 lastDistance = hypot(player.posX - player.prevPosX, player.posZ - player.prevPosZ)
114117 }
115118
116- safeListener<PlayerMoveEvent > {
117- when (mode.value) {
118- SpeedMode .STRAFE -> {
119- handleStrafe(it)
120- }
121-
122- SpeedMode .YPORT -> {
123- handleBoost(it)
124- }
125- }
119+ safeListener<PlayerMoveEvent > { event ->
120+ mode.move(this , event)
126121 }
127122
128123 safeListener<PacketEvent .Send > {
129- if (mode.value != SpeedMode . YPORT
124+ if (mode != Mode . Y_PORT
130125 || it.packet !is CPacketPlayer
131126 || ! goUp
132127 ) return @safeListener
@@ -143,10 +138,9 @@ object Speed : Module(
143138
144139 val unModOffset = offset
145140
146- if (currentY + unModOffset > 0 )
141+ if (currentY + unModOffset > 0 ) {
147142 offset + = currentY
148- else if (yPortAirStrict && yPortPhase == YPortPhase .FALLING && prevYPortPhase == YPortPhase .FALLING ) {
149-
143+ } else if (yPortAirStrict && yPortPhase == YPortPhase .FALLING && prevYPortPhase == YPortPhase .FALLING ) {
150144 var predictedY = currentY
151145 predictedY - = 0.08
152146 predictedY * = 0.9800000190734863 // 0.333200006 vs 0.341599999
@@ -162,44 +156,29 @@ object Speed : Module(
162156 }
163157
164158 safeListener<PacketEvent .Receive > {
165- if (mode.value != SpeedMode . YPORT || it.packet !is SPacketPlayerPosLook ) return @safeListener
159+ if (mode != Mode . Y_PORT || it.packet !is SPacketPlayerPosLook ) return @safeListener
166160
167161 currentSpeed = 0.0
168162 currentY = 0.0
169163 goUp = false
170164 // 3 extra ticks at base speed
171165 yPortPhase = YPortPhase .WAITING
172166 }
173-
174- mode.listeners.add {
175- runSafe { reset() }
176- }
177- }
178-
179- private fun SafeClientEvent.shouldStrafe (): Boolean =
180- ! player.capabilities.isFlying
181- && ! player.isElytraFlying
182- && ! BaritoneUtils .isPathing
183- && MovementUtils .isInputting
184-
185- private fun SafeClientEvent.reset () {
186- player.jumpMovementFactor = 0.02f
187- resetTimer()
188167 }
189168
190169 private fun SafeClientEvent.handleBoost (event : PlayerMoveEvent ) {
191- if (player.movementInput.moveForward == 0f && player.movementInput.moveStrafe == 0f
170+ if (! MovementUtils .isInputting
192171 || player.isInOrAboveLiquid
193172 || mc.gameSettings.keyBindJump.isKeyDown
194173 || ! player.onGround
195174 || ! world.collidesWithAnyBlock(player.entityBoundingBox.offset(0.0 , 0.42 , 0.0 )) && yPortStrict
196175 ) {
197176 resetTimer()
198- currentSpeed = . 2873
177+ currentSpeed = NCP_BASE_SPEED
199178 return
200179 }
201180
202- modifyTimer(TIMER_SPEED )
181+ modifyTimer(50f / yPortTimer )
203182
204183 prevYPortPhase = yPortPhase
205184
@@ -215,9 +194,9 @@ object Speed : Module(
215194 YPortPhase .SLOWDOWN -> {
216195 // NCP says hDistDiff >= 0.66 * (lastMove.hDistance - hDistanceBaseRef)
217196 currentSpeed = if (yPortAccelerate) {
218- lastDistance - yPortDecay * (lastDistance - . 2873 )
197+ lastDistance - yPortDecay * (lastDistance - NCP_BASE_SPEED )
219198 } else {
220- . 2873
199+ NCP_BASE_SPEED
221200 }
222201 yPortPhase = YPortPhase .ACCELERATING
223202 goUp = false
@@ -226,9 +205,9 @@ object Speed : Module(
226205 YPortPhase .FALLING -> {
227206 if (prevYPortPhase == YPortPhase .WALKING ) {
228207 currentSpeed = if (yPortAccelerate) {
229- lastDistance - yPortDecay * (lastDistance - . 2873 )
208+ lastDistance - yPortDecay * (lastDistance - NCP_BASE_SPEED )
230209 } else {
231- . 2873
210+ NCP_BASE_SPEED
232211 }
233212 }
234213
@@ -241,8 +220,8 @@ object Speed : Module(
241220 }
242221
243222 else -> {
244- currentSpeed = max(currentSpeed, . 2873 )
245- yPortPhase = YPortPhase .values ()[yPortPhase.ordinal + 1 % YPortPhase .values() .size]
223+ currentSpeed = max(currentSpeed, NCP_BASE_SPEED )
224+ yPortPhase = YPortPhase .entries.toTypedArray ()[yPortPhase.ordinal + 1 % YPortPhase .entries .size]
246225 goUp = false
247226 }
248227 }
@@ -261,47 +240,66 @@ object Speed : Module(
261240 }
262241
263242 private fun SafeClientEvent.handleStrafe (event : PlayerMoveEvent ) {
264- if (! shouldStrafe()) {
243+ val inputting = MovementUtils .isInputting
244+
245+ if (player.capabilities.isFlying
246+ || player.isElytraFlying
247+ || BaritoneUtils .isPathing
248+ ) {
249+ currentSpeed = strafeBaseSpeed
265250 resetTimer()
266- event.x = .0
267- event.z = .0
268- currentSpeed = .2873
269251 return
270252 }
271253
272- if (strafeOnlyOverhead && ! world.collidesWithAnyBlock(player.entityBoundingBox.offset(. 0 ,. 42 ,. 0 ) )
273- || strafeOnHoldingSprint && ! mc.gameSettings.keyBindSprint.isKeyDown)
274- return
254+ modifyTimer( 50f / strafeTimer )
255+
256+ val shouldJump = player.movementInput.jump || (inputting && strafeAutoJump)
275257
276- modifyTimer(TIMER_SPEED )
258+ if (player.onGround && shouldJump) {
259+ strafePhase = StrafePhase .JUMP
260+ }
277261
278- val base = applySpeedPotionEffects(.2873 )
262+ strafePhase = when (strafePhase) {
263+ StrafePhase .JUMP -> {
264+ if (player.onGround) {
265+ event.y = strafeJumpHeight
279266
280- if (player.onGround)
281- strafePhase = StrafePhase . ACCELERATING
267+ if (strafeResetOnJump) currentSpeed = strafeBaseSpeed
268+ currentSpeed + = strafeJumpSpeed
282269
283- when (strafePhase) {
284- StrafePhase .ACCELERATING -> {
285- if (player.onGround)
286- event.y = .42
287- currentSpeed = base
288- currentSpeed * = if (strafeAirSpeedBoost == StrafeMode .Strict ) 1.87 else 1.93
289- strafePhase = StrafePhase .SLOWDOWN
270+ StrafePhase .JUMP_SLOWDOWN
271+ } else StrafePhase .FALLING
290272 }
291273
292- StrafePhase .SLOWDOWN -> {
293- currentSpeed - = . 66 * base
294- strafePhase = StrafePhase .FALLING
274+ StrafePhase .JUMP_SLOWDOWN -> {
275+ currentSpeed * = strafeJumpDecay
276+ StrafePhase .FALLING
295277 }
296278
297279 StrafePhase .FALLING -> {
298- currentSpeed = lastDistance - lastDistance / 159
280+ currentSpeed = lastDistance * strafeDecay
281+ StrafePhase .FALLING
299282 }
300283 }
301284
302- val yaw = calcMoveYaw()
303- currentSpeed = currentSpeed.coerceAtLeast(.2873 )
304- event.x = - sin(yaw) * currentSpeed
305- event.z = cos(yaw) * currentSpeed
285+ if (player.onGround && ! shouldJump) {
286+ currentSpeed = strafeBaseSpeed
287+ }
288+
289+ currentSpeed = currentSpeed.coerceAtLeast(strafeBaseSpeed).coerceAtMost(strafeMaxSpeed)
290+
291+ val moveSpeed = if (! inputting) {
292+ currentSpeed = strafeBaseSpeed
293+ resetTimer()
294+
295+ 0.0
296+ } else currentSpeed
297+
298+ val dir = calcMoveYaw()
299+ event.x = - sin(dir) * moveSpeed
300+ event.z = cos(dir) * moveSpeed
306301 }
302+
303+ // For HoleSnap & Surround
304+ fun isStrafing () = mode == Mode .STRAFE
307305}
0 commit comments