Skip to content

Commit d91b12f

Browse files
committed
Skidded speed module
1 parent 208a872 commit d91b12f

File tree

2 files changed

+195
-0
lines changed

2 files changed

+195
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.lambda.module.modules
2+
3+
import com.lambda.event.events.ClientEvent
4+
import com.lambda.event.listener.SafeListener.Companion.listener
5+
import com.lambda.module.Module
6+
import com.lambda.module.tag.ModuleTag
7+
8+
object TimerTest : Module(
9+
name = "TimerTest",
10+
description = "Test module for timer",
11+
defaultTags = setOf(ModuleTag.CLIENT)
12+
) {
13+
private val timer by setting("Timer", 0.5, 0.1..10.0, 0.1)
14+
15+
init {
16+
listener<ClientEvent.Timer> {
17+
it.speed = timer
18+
}
19+
}
20+
}
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
package com.lambda.module.modules.movement
2+
3+
import com.lambda.context.SafeContext
4+
import com.lambda.event.events.ClientEvent
5+
import com.lambda.event.events.MovementEvent
6+
import com.lambda.event.events.PlayerPacketEvent
7+
import com.lambda.event.listener.SafeListener.Companion.listener
8+
import com.lambda.module.Module
9+
import com.lambda.module.tag.ModuleTag
10+
import com.lambda.util.math.MathUtils.toRadian
11+
import com.lambda.util.player.MovementUtils.addSpeed
12+
import com.lambda.util.player.MovementUtils.isInputting
13+
import com.lambda.util.player.MovementUtils.motionDelta
14+
import com.lambda.util.player.MovementUtils.motionY
15+
import com.lambda.util.player.MovementUtils.moveDelta
16+
import com.lambda.util.player.MovementUtils.moveYaw
17+
import com.lambda.util.player.MovementUtils.setSpeed
18+
import kotlin.math.max
19+
20+
object Speed : Module(
21+
name = "Speed",
22+
description = "Fastest module",
23+
defaultTags = setOf(ModuleTag.MOVEMENT)
24+
) {
25+
private val mode by setting("Mode", Mode.MATRIX_STRAFE_1)
26+
27+
// NCP
28+
private val ncpBaseSpeed by setting("Base Speed", 0.2873, 0.1..0.3, 0.0001, visibility = { mode == Mode.NCP_STRAFE })
29+
private val ncpMaxSpeed by setting("Max Speed", 1.0, 0.3..1.0, 0.0001, visibility = { mode == Mode.NCP_STRAFE })
30+
private val ncpDecay by setting("Decay", 0.9937, 0.98..1.0, 0.0001, visibility = { mode == Mode.NCP_STRAFE })
31+
private val ncpJumpSpeed by setting("Jump Speed", 0.3, 0.0..0.5, 0.001, visibility = { mode == Mode.NCP_STRAFE })
32+
private val ncpJumpDecay by setting("Jump Decay", 0.59, 0.1..1.0, 0.0001, visibility = { mode == Mode.NCP_STRAFE })
33+
private val ncpJumpHeight by setting("Jump Height", 0.4, 0.1..0.5, 0.00001, visibility = { mode == Mode.NCP_STRAFE })
34+
private val ncpResetOnJump by setting("Reset On Jump", true, visibility = { mode == Mode.NCP_STRAFE })
35+
private val ncpAutoJump by setting("Auto Jump", false, visibility = { mode == Mode.NCP_STRAFE })
36+
private val ncpTimerBoost by setting("Timer Boost", 1.08, 1.0..1.1, 0.01, visibility = { mode == Mode.NCP_STRAFE })
37+
38+
// NCP
39+
private var ncpPhase = NCPPhase.JUMP
40+
private var ncpSpeed = ncpBaseSpeed
41+
private var lastDistance = 0.0
42+
43+
// Matrix
44+
private var matrixSprint = false
45+
46+
private enum class Mode {
47+
NCP_STRAFE,
48+
MATRIX_STRAFE_1,
49+
MATRIX_STRAFE_2,
50+
}
51+
52+
private enum class NCPPhase {
53+
JUMP,
54+
JUMP_POST,
55+
SLOWDOWN
56+
}
57+
58+
init {
59+
listener<MovementEvent.Pre> {
60+
if (!shouldWork()) {
61+
ncpSpeed = ncpBaseSpeed
62+
return@listener
63+
}
64+
65+
when (mode) {
66+
Mode.NCP_STRAFE -> {
67+
val shouldJump = player.input.jumping || (ncpAutoJump && isInputting)
68+
69+
if (player.isOnGround && shouldJump) {
70+
ncpPhase = NCPPhase.JUMP
71+
}
72+
73+
ncpPhase = when (ncpPhase) {
74+
NCPPhase.JUMP -> {
75+
if (player.isOnGround) {
76+
if (ncpResetOnJump) ncpSpeed = ncpBaseSpeed
77+
78+
player.motionY = ncpJumpHeight
79+
ncpSpeed += ncpJumpSpeed
80+
NCPPhase.JUMP_POST
81+
} else NCPPhase.SLOWDOWN
82+
}
83+
84+
NCPPhase.JUMP_POST -> {
85+
ncpSpeed *= ncpJumpDecay
86+
NCPPhase.SLOWDOWN
87+
}
88+
89+
NCPPhase.SLOWDOWN -> {
90+
ncpSpeed = lastDistance * ncpDecay
91+
NCPPhase.SLOWDOWN
92+
}
93+
}
94+
95+
if (player.isOnGround && !shouldJump) {
96+
ncpSpeed = ncpBaseSpeed
97+
}
98+
99+
ncpSpeed = ncpSpeed
100+
.coerceAtMost(ncpMaxSpeed)
101+
.coerceAtLeast(ncpBaseSpeed)
102+
103+
val moveSpeed = if (isInputting) ncpSpeed else {
104+
ncpSpeed = ncpBaseSpeed
105+
0.0
106+
}
107+
108+
setSpeed(moveSpeed)
109+
}
110+
111+
Mode.MATRIX_STRAFE_1, Mode.MATRIX_STRAFE_2 -> {
112+
if (!isInputting) return@listener
113+
114+
var speed = player.motionDelta
115+
116+
if (speed > 0.21) {
117+
if (mode == Mode.MATRIX_STRAFE_2) return@listener
118+
speed *= 0.9999 // Memetrix
119+
}
120+
121+
if (!player.horizontalCollision)
122+
speed = max(speed, 0.1)
123+
124+
setSpeed(speed)
125+
}
126+
}
127+
}
128+
129+
listener<MovementEvent.Post> {
130+
lastDistance = player.moveDelta
131+
}
132+
133+
listener<ClientEvent.Timer> {
134+
if (!shouldWork() || !isInputting) return@listener
135+
if (mode != Mode.NCP_STRAFE) return@listener
136+
it.speed = ncpTimerBoost
137+
}
138+
139+
listener<MovementEvent.Jump> {
140+
if (!shouldWork()) return@listener
141+
142+
when (mode) {
143+
Mode.NCP_STRAFE -> it.cancel()
144+
Mode.MATRIX_STRAFE_1, Mode.MATRIX_STRAFE_2 -> {
145+
if (!isInputting) return@listener
146+
147+
if (player.isSprinting) {
148+
addSpeed(-0.2, player.moveYaw.toRadian().toDouble())
149+
}
150+
151+
addSpeed(0.2)
152+
}
153+
}
154+
}
155+
156+
listener<PlayerPacketEvent.Pre> {
157+
if (!shouldWork()) return@listener
158+
if (mode != Mode.MATRIX_STRAFE_1 || !isInputting) return@listener
159+
it.isSprinting = matrixSprint
160+
matrixSprint = !matrixSprint
161+
}
162+
163+
onEnable {
164+
ncpPhase = NCPPhase.SLOWDOWN
165+
ncpSpeed = ncpBaseSpeed
166+
}
167+
}
168+
169+
private fun SafeContext.shouldWork() =
170+
!player.abilities.flying
171+
&& !player.isFallFlying
172+
&& !player.input.sneaking
173+
&& !player.isTouchingWater
174+
&& !player.isInLava
175+
}

0 commit comments

Comments
 (0)