@@ -4,10 +4,8 @@ import com.lambda.client.commons.interfaces.DisplayEnum
44import com.lambda.client.event.SafeClientEvent
55import com.lambda.client.event.events.PacketEvent
66import com.lambda.client.event.events.PlayerMoveEvent
7- import com.lambda.client.event.events.PlayerTravelEvent
87import com.lambda.client.manager.managers.TimerManager.modifyTimer
98import com.lambda.client.manager.managers.TimerManager.resetTimer
10- import com.lambda.client.mixin.extension.isInWeb
119import com.lambda.client.mixin.extension.playerY
1210import com.lambda.client.module.Category
1311import com.lambda.client.module.Module
@@ -16,13 +14,8 @@ import com.lambda.client.util.EntityUtils.isInOrAboveLiquid
1614import com.lambda.client.util.MovementUtils
1715import com.lambda.client.util.MovementUtils.applySpeedPotionEffects
1816import com.lambda.client.util.MovementUtils.calcMoveYaw
19- import com.lambda.client.util.MovementUtils.setSpeed
20- import com.lambda.client.util.MovementUtils.speed
21- import com.lambda.client.util.TickTimer
22- import com.lambda.client.util.TimeUnit
2317import com.lambda.client.util.threads.runSafe
2418import com.lambda.client.util.threads.safeListener
25- import net.minecraft.client.settings.KeyBinding
2619import net.minecraft.network.play.client.CPacketPlayer
2720import net.minecraft.network.play.server.SPacketPlayerPosLook
2821import net.minecraftforge.fml.common.gameevent.TickEvent
@@ -43,12 +36,9 @@ object Speed : Module(
4336 val mode = setting(" Mode" , SpeedMode .STRAFE )
4437
4538 // Strafe settings
46- private val strafeAirSpeedBoost by setting(" Air Speed Boost" , 0.028f , 0.01f .. 0.04f , 0.001f , { mode.value == SpeedMode .STRAFE })
47- private val strafeTimerBoost by setting(" Timer Boost" , true , { mode.value == SpeedMode .STRAFE })
48- private val strafeAutoJump by setting(" Auto Jump" , true , { mode.value == SpeedMode .STRAFE }, description = " WARNING: Food intensive!" )
49- private val strafeOnlyOverhead by setting(" Only strafe on overhead" , false , { mode.value == SpeedMode .STRAFE && strafeAutoJump })
39+ private val strafeAirSpeedBoost by setting(" Strafe Speed" , StrafeMode .Normal )
40+ private val strafeOnlyOverhead by setting(" Require Roof" , false , { mode.value == SpeedMode .STRAFE })
5041 private val strafeOnHoldingSprint by setting(" On Holding Sprint" , false , { mode.value == SpeedMode .STRAFE })
51- private val strafeCancelInertia by setting(" Cancel Inertia" , false , { mode.value == SpeedMode .STRAFE })
5242
5343 // YPort settings
5444 private val yPortAccelerate by setting(" Accelerate" , true , { mode.value == SpeedMode .YPORT })
@@ -58,17 +48,17 @@ object Speed : Module(
5848 private val yPortAcceleration by setting(" Acceleration Speed" , 2.149 , 1.0 .. 5.0 , 0.001 , { mode.value == SpeedMode .YPORT })
5949 private val yPortDecay by setting(" Decay Amount" , 0.66 , 0.0 .. 1.0 , 0.001 , { mode.value == SpeedMode .YPORT })
6050
61- private const val TIMER_SPEED = 45.955883f
62-
63- // Strafe Mode
64- private var jumpTicks = 0
65- private val strafeTimer = TickTimer (TimeUnit .TICKS )
51+ private const val TIMER_SPEED = 45.922115f
6652
6753 // yport stuff
6854 private var currentSpeed = .2873
6955 private var currentY = 0.0
70- private var phase: YPortPhase = YPortPhase .WALKING
71- private var prevPhase: YPortPhase = YPortPhase .WALKING
56+
57+ private var strafePhase = StrafePhase .ACCELERATING
58+
59+ private var yPortPhase = YPortPhase .WALKING
60+ private var prevYPortPhase = YPortPhase .WALKING
61+
7262 private var goUp = false
7363 private var lastDistance = 0.0
7464
@@ -85,16 +75,30 @@ object Speed : Module(
8575 FALLING
8676 }
8777
78+ private enum class StrafePhase {
79+ // to jump and accelerate
80+ ACCELERATING ,
81+ // to fall to the ground
82+ SLOWDOWN ,
83+ // to slowly fall to the ground
84+ FALLING
85+ }
86+
8887 enum class SpeedMode (override val displayName : String ) : DisplayEnum {
8988 STRAFE (" Strafe" ),
9089 YPORT (" YPort" )
9190 }
9291
92+ enum class StrafeMode {
93+ Normal , Strict
94+ }
95+
9396 init {
9497 onEnable {
9598 currentSpeed = .2873
96- phase = YPortPhase .WALKING
97- prevPhase = YPortPhase .WALKING
99+ strafePhase = StrafePhase .ACCELERATING
100+ yPortPhase = YPortPhase .WALKING
101+ prevYPortPhase = YPortPhase .WALKING
98102 goUp = false
99103 currentY = 0.0
100104 }
@@ -107,23 +111,12 @@ object Speed : Module(
107111
108112 safeListener<TickEvent .ClientTickEvent > {
109113 lastDistance = hypot(player.posX - player.prevPosX, player.posZ - player.prevPosZ)
110- if (mode.value == SpeedMode .STRAFE
111- && shouldStrafe()
112- ) strafe()
113114 }
114115
115116 safeListener<PlayerMoveEvent > {
116117 when (mode.value) {
117118 SpeedMode .STRAFE -> {
118- if (shouldStrafe()) {
119- setSpeed(max(player.speed, applySpeedPotionEffects(0.2873 )))
120- } else {
121- reset()
122- if (strafeCancelInertia && ! strafeTimer.tick(2L , false )) {
123- player.motionX = 0.0
124- player.motionZ = 0.0
125- }
126- }
119+ handleStrafe(it)
127120 }
128121
129122 SpeedMode .YPORT -> {
@@ -152,14 +145,14 @@ object Speed : Module(
152145
153146 if (currentY + unModOffset > 0 )
154147 offset + = currentY
155- else if (yPortAirStrict && phase == YPortPhase .FALLING && prevPhase == YPortPhase .FALLING ) {
148+ else if (yPortAirStrict && yPortPhase == YPortPhase .FALLING && prevYPortPhase == YPortPhase .FALLING ) {
156149
157150 var predictedY = currentY
158151 predictedY - = 0.08
159152 predictedY * = 0.9800000190734863 // 0.333200006 vs 0.341599999
160153
161154 if (predictedY + player.posY <= player.posY) {
162- phase = YPortPhase .WAITING
155+ yPortPhase = YPortPhase .WAITING
163156 }
164157 }
165158
@@ -175,55 +168,23 @@ object Speed : Module(
175168 currentY = 0.0
176169 goUp = false
177170 // 3 extra ticks at base speed
178- phase = YPortPhase .WAITING
171+ yPortPhase = YPortPhase .WAITING
179172 }
180173
181174 mode.listeners.add {
182175 runSafe { reset() }
183176 }
184177 }
185178
186- private fun SafeClientEvent.strafe () {
187- player.jumpMovementFactor = strafeAirSpeedBoost
188- // slightly slower timer speed bypasses better (1.088)
189- if (strafeTimerBoost) modifyTimer(TIMER_SPEED )
190-
191- if ((Step .isDisabled || player.onGround) && strafeAutoJump) jump()
192-
193- strafeTimer.reset()
194- }
195-
196179 private fun SafeClientEvent.shouldStrafe (): Boolean =
197180 ! player.capabilities.isFlying
198181 && ! player.isElytraFlying
199- && ! mc.gameSettings.keyBindSneak.isKeyDown
200- && (! strafeOnHoldingSprint || mc.gameSettings.keyBindSprint.isKeyDown)
201182 && ! BaritoneUtils .isPathing
202183 && MovementUtils .isInputting
203- && ! (player.isInOrAboveLiquid || player.isInWeb)
204- && (! strafeOnlyOverhead || world.collidesWithAnyBlock(player.entityBoundingBox.offset(.0 ,.42 ,.0 )))
205184
206185 private fun SafeClientEvent.reset () {
207186 player.jumpMovementFactor = 0.02f
208187 resetTimer()
209- jumpTicks = 0
210- }
211-
212- private fun SafeClientEvent.jump () {
213- if (player.onGround && jumpTicks <= 0 ) {
214- if (player.isSprinting) {
215- val yaw = calcMoveYaw()
216- player.motionX - = sin(yaw) * 0.2
217- player.motionZ + = cos(yaw) * 0.2
218- }
219-
220- KeyBinding .setKeyBindState(mc.gameSettings.keyBindJump.keyCode, false )
221- player.motionY = 0.4
222- player.isAirBorne = true
223- jumpTicks = 5
224- }
225-
226- jumpTicks--
227188 }
228189
229190 private fun SafeClientEvent.handleBoost (event : PlayerMoveEvent ) {
@@ -240,13 +201,13 @@ object Speed : Module(
240201
241202 modifyTimer(TIMER_SPEED )
242203
243- prevPhase = phase
204+ prevYPortPhase = yPortPhase
244205
245- when (phase ) {
206+ when (yPortPhase ) {
246207 YPortPhase .ACCELERATING -> {
247208 // NCP says hDistance < 2.15 * hDistanceBaseRef
248209 currentSpeed * = yPortAcceleration
249- phase = if (yPortAirStrict) YPortPhase .FALLING else YPortPhase .SLOWDOWN
210+ yPortPhase = if (yPortAirStrict) YPortPhase .FALLING else YPortPhase .SLOWDOWN
250211 goUp = true
251212 currentY = 0.0
252213 }
@@ -258,12 +219,12 @@ object Speed : Module(
258219 } else {
259220 .2873
260221 }
261- phase = YPortPhase .ACCELERATING
222+ yPortPhase = YPortPhase .ACCELERATING
262223 goUp = false
263224 }
264225
265226 YPortPhase .FALLING -> {
266- if (prevPhase == YPortPhase .WALKING ) {
227+ if (prevYPortPhase == YPortPhase .WALKING ) {
267228 currentSpeed = if (yPortAccelerate) {
268229 lastDistance - yPortDecay * (lastDistance - .2873 )
269230 } else {
@@ -281,7 +242,7 @@ object Speed : Module(
281242
282243 else -> {
283244 currentSpeed = max(currentSpeed, .2873 )
284- phase = YPortPhase .values()[phase .ordinal + 1 % YPortPhase .values().size]
245+ yPortPhase = YPortPhase .values()[yPortPhase .ordinal + 1 % YPortPhase .values().size]
285246 goUp = false
286247 }
287248 }
@@ -298,4 +259,49 @@ object Speed : Module(
298259
299260 player.setVelocity(event.x, event.y, event.z)
300261 }
262+
263+ private fun SafeClientEvent.handleStrafe (event : PlayerMoveEvent ) {
264+ if (! shouldStrafe()) {
265+ resetTimer()
266+ event.x = .0
267+ event.z = .0
268+ currentSpeed = .2873
269+ return
270+ }
271+
272+ if (strafeOnlyOverhead && ! world.collidesWithAnyBlock(player.entityBoundingBox.offset(.0 ,.42 ,.0 ))
273+ || strafeOnHoldingSprint && ! mc.gameSettings.keyBindSprint.isKeyDown)
274+ return
275+
276+ modifyTimer(TIMER_SPEED )
277+
278+ val base = applySpeedPotionEffects(.2873 )
279+
280+ if (player.onGround)
281+ strafePhase = StrafePhase .ACCELERATING
282+
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
290+ }
291+
292+ StrafePhase .SLOWDOWN -> {
293+ currentSpeed - = .66 * base
294+ strafePhase = StrafePhase .FALLING
295+ }
296+
297+ StrafePhase .FALLING -> {
298+ currentSpeed = lastDistance - lastDistance / 159
299+ }
300+ }
301+
302+ val yaw = calcMoveYaw()
303+ currentSpeed = currentSpeed.coerceAtLeast(.2873 )
304+ event.x = - sin(yaw) * currentSpeed
305+ event.z = cos(yaw) * currentSpeed
306+ }
301307}
0 commit comments