@@ -12,9 +12,7 @@ import com.lambda.client.module.Module
12
12
import com.lambda.client.util.BaritoneUtils
13
13
import com.lambda.client.util.EntityUtils.isInOrAboveLiquid
14
14
import com.lambda.client.util.MovementUtils
15
- import com.lambda.client.util.MovementUtils.applySpeedPotionEffects
16
15
import com.lambda.client.util.MovementUtils.calcMoveYaw
17
- import com.lambda.client.util.threads.runSafe
18
16
import com.lambda.client.util.threads.safeListener
19
17
import net.minecraft.network.play.client.CPacketPlayer
20
18
import net.minecraft.network.play.server.SPacketPlayerPosLook
@@ -33,28 +31,39 @@ object Speed : Module(
33
31
modulePriority = 100
34
32
) {
35
33
// 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
+ }
37
39
38
40
// 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 })
42
50
43
51
// 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 })
50
59
51
- private const val TIMER_SPEED = 45.922115f
60
+ private const val NCP_BASE_SPEED = 0.2873
52
61
53
62
// yport stuff
54
- private var currentSpeed = . 2873
63
+ private var currentSpeed = NCP_BASE_SPEED
55
64
private var currentY = 0.0
56
65
57
- private var strafePhase = StrafePhase .ACCELERATING
66
+ private var strafePhase = StrafePhase .FALLING
58
67
59
68
private var yPortPhase = YPortPhase .WALKING
60
69
private var prevYPortPhase = YPortPhase .WALKING
@@ -76,57 +85,43 @@ object Speed : Module(
76
85
}
77
86
78
87
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 ,
81
92
// to fall to the ground
82
- SLOWDOWN ,
83
- // to slowly fall to the ground
84
93
FALLING
85
94
}
86
95
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) }),
94
99
}
95
100
96
101
init {
97
102
onEnable {
98
- currentSpeed = . 2873
99
- strafePhase = StrafePhase .ACCELERATING
103
+ currentSpeed = if (mode == Mode . Y_PORT ) NCP_BASE_SPEED else strafeBaseSpeed
104
+ strafePhase = StrafePhase .FALLING
100
105
yPortPhase = YPortPhase .WALKING
101
106
prevYPortPhase = YPortPhase .WALKING
102
107
goUp = false
103
108
currentY = 0.0
104
109
}
105
110
106
111
onDisable {
107
- runSafe {
108
- reset()
109
- }
112
+ resetTimer()
110
113
}
111
114
112
115
safeListener<TickEvent .ClientTickEvent > {
113
116
lastDistance = hypot(player.posX - player.prevPosX, player.posZ - player.prevPosZ)
114
117
}
115
118
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)
126
121
}
127
122
128
123
safeListener<PacketEvent .Send > {
129
- if (mode.value != SpeedMode . YPORT
124
+ if (mode != Mode . Y_PORT
130
125
|| it.packet !is CPacketPlayer
131
126
|| ! goUp
132
127
) return @safeListener
@@ -143,10 +138,9 @@ object Speed : Module(
143
138
144
139
val unModOffset = offset
145
140
146
- if (currentY + unModOffset > 0 )
141
+ if (currentY + unModOffset > 0 ) {
147
142
offset + = currentY
148
- else if (yPortAirStrict && yPortPhase == YPortPhase .FALLING && prevYPortPhase == YPortPhase .FALLING ) {
149
-
143
+ } else if (yPortAirStrict && yPortPhase == YPortPhase .FALLING && prevYPortPhase == YPortPhase .FALLING ) {
150
144
var predictedY = currentY
151
145
predictedY - = 0.08
152
146
predictedY * = 0.9800000190734863 // 0.333200006 vs 0.341599999
@@ -162,44 +156,29 @@ object Speed : Module(
162
156
}
163
157
164
158
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
166
160
167
161
currentSpeed = 0.0
168
162
currentY = 0.0
169
163
goUp = false
170
164
// 3 extra ticks at base speed
171
165
yPortPhase = YPortPhase .WAITING
172
166
}
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()
188
167
}
189
168
190
169
private fun SafeClientEvent.handleBoost (event : PlayerMoveEvent ) {
191
- if (player.movementInput.moveForward == 0f && player.movementInput.moveStrafe == 0f
170
+ if (! MovementUtils .isInputting
192
171
|| player.isInOrAboveLiquid
193
172
|| mc.gameSettings.keyBindJump.isKeyDown
194
173
|| ! player.onGround
195
174
|| ! world.collidesWithAnyBlock(player.entityBoundingBox.offset(0.0 , 0.42 , 0.0 )) && yPortStrict
196
175
) {
197
176
resetTimer()
198
- currentSpeed = . 2873
177
+ currentSpeed = NCP_BASE_SPEED
199
178
return
200
179
}
201
180
202
- modifyTimer(TIMER_SPEED )
181
+ modifyTimer(50f / yPortTimer )
203
182
204
183
prevYPortPhase = yPortPhase
205
184
@@ -215,9 +194,9 @@ object Speed : Module(
215
194
YPortPhase .SLOWDOWN -> {
216
195
// NCP says hDistDiff >= 0.66 * (lastMove.hDistance - hDistanceBaseRef)
217
196
currentSpeed = if (yPortAccelerate) {
218
- lastDistance - yPortDecay * (lastDistance - . 2873 )
197
+ lastDistance - yPortDecay * (lastDistance - NCP_BASE_SPEED )
219
198
} else {
220
- . 2873
199
+ NCP_BASE_SPEED
221
200
}
222
201
yPortPhase = YPortPhase .ACCELERATING
223
202
goUp = false
@@ -226,9 +205,9 @@ object Speed : Module(
226
205
YPortPhase .FALLING -> {
227
206
if (prevYPortPhase == YPortPhase .WALKING ) {
228
207
currentSpeed = if (yPortAccelerate) {
229
- lastDistance - yPortDecay * (lastDistance - . 2873 )
208
+ lastDistance - yPortDecay * (lastDistance - NCP_BASE_SPEED )
230
209
} else {
231
- . 2873
210
+ NCP_BASE_SPEED
232
211
}
233
212
}
234
213
@@ -241,8 +220,8 @@ object Speed : Module(
241
220
}
242
221
243
222
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]
246
225
goUp = false
247
226
}
248
227
}
@@ -261,47 +240,66 @@ object Speed : Module(
261
240
}
262
241
263
242
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
265
250
resetTimer()
266
- event.x = .0
267
- event.z = .0
268
- currentSpeed = .2873
269
251
return
270
252
}
271
253
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)
275
257
276
- modifyTimer(TIMER_SPEED )
258
+ if (player.onGround && shouldJump) {
259
+ strafePhase = StrafePhase .JUMP
260
+ }
277
261
278
- val base = applySpeedPotionEffects(.2873 )
262
+ strafePhase = when (strafePhase) {
263
+ StrafePhase .JUMP -> {
264
+ if (player.onGround) {
265
+ event.y = strafeJumpHeight
279
266
280
- if (player.onGround)
281
- strafePhase = StrafePhase . ACCELERATING
267
+ if (strafeResetOnJump) currentSpeed = strafeBaseSpeed
268
+ currentSpeed + = strafeJumpSpeed
282
269
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
290
272
}
291
273
292
- StrafePhase .SLOWDOWN -> {
293
- currentSpeed - = . 66 * base
294
- strafePhase = StrafePhase .FALLING
274
+ StrafePhase .JUMP_SLOWDOWN -> {
275
+ currentSpeed * = strafeJumpDecay
276
+ StrafePhase .FALLING
295
277
}
296
278
297
279
StrafePhase .FALLING -> {
298
- currentSpeed = lastDistance - lastDistance / 159
280
+ currentSpeed = lastDistance * strafeDecay
281
+ StrafePhase .FALLING
299
282
}
300
283
}
301
284
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
306
301
}
302
+
303
+ // For HoleSnap & Surround
304
+ fun isStrafing () = mode == Mode .STRAFE
307
305
}
0 commit comments