Skip to content

Commit e55747b

Browse files
committed
Strafe rewrite rewrite rewrite (improved grim speed)
1 parent 27a7b17 commit e55747b

File tree

4 files changed

+74
-43
lines changed

4 files changed

+74
-43
lines changed

common/src/main/kotlin/com/lambda/config/groups/RotationSettings.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class RotationSettings(
1616
override var mean by c.setting("Mean", 20.0, 1.0..80.0, 0.1, "Average rotation speed", unit = "°") { vis() && !instant }
1717
override var derivation by c.setting("Standard Deviation", 5.0, 0.0..20.0, 0.1, "Spread of rotation speeds", unit = "°") { vis() && !instant }
1818

19-
override val turnSpeed get() = abs(nextGaussian(mean, derivation))
19+
override val turnSpeed get() = if (instant) 360.0 else abs(nextGaussian(mean, derivation))
2020

2121
var speedMultiplier = 1.0
2222

common/src/main/kotlin/com/lambda/interaction/RotationManager.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,6 @@ object RotationManager : Loadable {
8080
currentRotation = currentContext?.let { context ->
8181
val rotationTo = if (keepTicks >= 0) context.rotation else player.rotation
8282

83-
if (context.config.instant) {
84-
return@let rotationTo
85-
}
86-
8783
var speedMultiplier = (context.config as? RotationSettings)?.speedMultiplier ?: 1.0
8884
if (keepTicks < 0) speedMultiplier = 1.0
8985

common/src/main/kotlin/com/lambda/module/modules/movement/Speed.kt

Lines changed: 70 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
package com.lambda.module.modules.movement
22

3-
import com.lambda.config.groups.RotationSettings
3+
import com.lambda.config.groups.IRotationConfig
44
import com.lambda.context.SafeContext
55
import com.lambda.event.events.ClientEvent
66
import com.lambda.event.events.MovementEvent
77
import com.lambda.event.events.RotationEvent
88
import com.lambda.event.listener.SafeListener.Companion.listener
99
import com.lambda.interaction.rotation.Rotation
10-
import com.lambda.interaction.rotation.Rotation.Companion.rotation
1110
import com.lambda.interaction.rotation.RotationContext
11+
import com.lambda.interaction.rotation.RotationMode
1212
import com.lambda.module.Module
1313
import com.lambda.module.tag.ModuleTag
14+
import com.lambda.util.player.MovementUtils.addSpeed
1415
import com.lambda.util.player.MovementUtils.isInputting
1516
import com.lambda.util.player.MovementUtils.motionY
1617
import com.lambda.util.player.MovementUtils.moveDelta
1718
import com.lambda.util.player.MovementUtils.setSpeed
19+
import com.lambda.util.primitives.extension.contains
20+
import com.lambda.util.world.WorldUtils.getFastEntities
21+
import net.minecraft.entity.LivingEntity
22+
import net.minecraft.entity.vehicle.BoatEntity
1823
import kotlin.math.atan2
1924

2025
object Speed : Module(
@@ -25,25 +30,34 @@ object Speed : Module(
2530
@JvmStatic val mode by setting("Mode", Mode.GRIM_STRAFE)
2631

2732
// Grim
28-
private val rotation = RotationSettings(this) { mode == Mode.GRIM_STRAFE }
33+
private val grimEntityBoost by setting("Entity Boost", 1.0, 0.0..2.0, 0.01) { mode == Mode.GRIM_STRAFE }
34+
private val grimCollideMultiplier by setting("Entity Collide Multiplier", 0.75, 0.0..1.0, 0.01) { mode == Mode.GRIM_STRAFE && grimEntityBoost > 0.0}
35+
private val grimBoatBoost by setting("Boat Boost", 0.4, 0.0..1.0, 0.01) { mode == Mode.GRIM_STRAFE }
2936

3037
// NCP
31-
private val ncpBaseSpeed by setting("Base Speed", 0.2873, 0.1..0.3, 0.0001, visibility = { mode == Mode.NCP_STRAFE })
32-
private val ncpMaxSpeed by setting("Max Speed", 1.0, 0.3..1.0, 0.0001, visibility = { mode == Mode.NCP_STRAFE })
33-
private val ncpDecay by setting("Decay", 0.9937, 0.98..1.0, 0.0001, visibility = { mode == Mode.NCP_STRAFE })
34-
private val ncpJumpSpeed by setting("Jump Speed", 0.3, 0.0..0.5, 0.001, visibility = { mode == Mode.NCP_STRAFE })
35-
private val ncpJumpDecay by setting("Jump Decay", 0.59, 0.1..1.0, 0.0001, visibility = { mode == Mode.NCP_STRAFE })
36-
private val ncpJumpHeight by setting("Jump Height", 0.4, 0.1..0.5, 0.00001, visibility = { mode == Mode.NCP_STRAFE })
37-
private val ncpResetOnJump by setting("Reset On Jump", true, visibility = { mode == Mode.NCP_STRAFE })
38-
private val ncpAutoJump by setting("Auto Jump", false, visibility = { mode == Mode.NCP_STRAFE })
39-
private val ncpTimerBoost by setting("Timer Boost", 1.08, 1.0..1.1, 0.01, visibility = { mode == Mode.NCP_STRAFE })
38+
private val strict by setting("Strict", true) { mode == Mode.NCP_STRAFE }
39+
private val lowerJump by setting("Lower Jump", true) { mode == Mode.NCP_STRAFE }
40+
private val ncpAutoJump by setting("Auto Jump", false) { mode == Mode.NCP_STRAFE }
41+
private val ncpTimerBoost by setting("Timer Boost", 1.08, 1.0..1.1, 0.01) { mode == Mode.NCP_STRAFE }
4042

4143
// Grim
42-
private var desiredRotation = Rotation.ZERO
44+
private var desiredRotation: Rotation? = null
45+
private val rotationConfig = object : IRotationConfig {
46+
override val rotationMode = RotationMode.SYNC
47+
override val turnSpeed = 360.0
48+
override val keepTicks = 1
49+
override val resetTicks = 1
50+
override val instant = true
51+
override val mean = 180.0
52+
override val derivation = 1.0
53+
}
4354

4455
// NCP
56+
private const val NCP_BASE_SPEED = 0.2873
57+
private const val NCP_AIR_DECAY = 0.9937
58+
4559
private var ncpPhase = NCPPhase.JUMP
46-
private var ncpSpeed = ncpBaseSpeed
60+
private var ncpSpeed = NCP_BASE_SPEED
4761
private var lastDistance = 0.0
4862

4963
enum class Mode {
@@ -66,32 +80,31 @@ object Speed : Module(
6680
desiredRotation = if (dx != 0 || dy != 0) {
6781
val angle = Math.toDegrees(atan2(dy.toDouble(), dx.toDouble()))
6882
Rotation(player.yaw + angle.toFloat(), player.pitch)
69-
} else {
70-
Rotation.ZERO
71-
}
83+
} else null
7284
}
7385
}
7486

75-
listener<RotationEvent.Pre> {
87+
listener<RotationEvent.Pre> { event ->
7688
if (!shouldWork()) return@listener
7789
if (mode != Mode.GRIM_STRAFE) return@listener
78-
if (desiredRotation == Rotation.ZERO) return@listener
7990

80-
it.context = RotationContext(
81-
desiredRotation,
82-
rotation
83-
)
91+
desiredRotation?.let { rot ->
92+
event.context = RotationContext(
93+
rot,
94+
rotationConfig
95+
)
96+
}
8497
}
8598

8699
listener<MovementEvent.Pre> {
87100
if (!shouldWork()) {
88-
ncpSpeed = ncpBaseSpeed
101+
ncpSpeed = NCP_BASE_SPEED
89102
return@listener
90103
}
91104

92105
when (mode) {
93-
Mode.NCP_STRAFE -> handleStrafe()
94106
Mode.GRIM_STRAFE -> handleGrim()
107+
Mode.NCP_STRAFE -> handleStrafe()
95108
}
96109
}
97110

@@ -110,18 +123,40 @@ object Speed : Module(
110123

111124
when (mode) {
112125
Mode.NCP_STRAFE -> it.cancel()
113-
Mode.GRIM_STRAFE -> {}
126+
else -> {}
114127
}
115128
}
116129

117130
onEnable {
118131
ncpPhase = NCPPhase.SLOWDOWN
119-
ncpSpeed = ncpBaseSpeed
132+
ncpSpeed = NCP_BASE_SPEED
120133
}
121134
}
122135

123136
private fun SafeContext.handleGrim() {
137+
if (!isInputting) return
138+
139+
var boostAmount = 0.0
124140

141+
getFastEntities<LivingEntity>(
142+
player.pos, 3.0,
143+
predicate = { player.boundingBox.expand(1.0) in it.boundingBox },
144+
iterator = { e, _ ->
145+
val colliding = player.boundingBox in e.boundingBox
146+
val multiplier = if (colliding) grimCollideMultiplier else 1.0
147+
boostAmount += 0.08 * grimEntityBoost * multiplier
148+
}
149+
)
150+
151+
if (grimBoatBoost > 0.0) {
152+
getFastEntities<BoatEntity>(
153+
player.pos, 4.0,
154+
predicate = { player.boundingBox in it.boundingBox.expand(0.01) },
155+
iterator = { _, _ -> boostAmount += grimBoatBoost }
156+
)
157+
}
158+
159+
addSpeed(boostAmount)
125160
}
126161

127162
private fun SafeContext.handleStrafe() {
@@ -134,35 +169,33 @@ object Speed : Module(
134169
ncpPhase = when (ncpPhase) {
135170
NCPPhase.JUMP -> {
136171
if (player.isOnGround) {
137-
if (ncpResetOnJump) ncpSpeed = ncpBaseSpeed
138-
139-
player.motionY = ncpJumpHeight
140-
ncpSpeed += ncpJumpSpeed
172+
player.motionY = if (lowerJump) 0.4 else 0.42
173+
ncpSpeed = NCP_BASE_SPEED + 0.3
141174
NCPPhase.JUMP_POST
142175
} else NCPPhase.SLOWDOWN
143176
}
144177

145178
NCPPhase.JUMP_POST -> {
146-
ncpSpeed *= ncpJumpDecay
179+
ncpSpeed *= if (strict) 0.59 else 0.62
147180
NCPPhase.SLOWDOWN
148181
}
149182

150183
NCPPhase.SLOWDOWN -> {
151-
ncpSpeed = lastDistance * ncpDecay
184+
ncpSpeed = lastDistance * NCP_AIR_DECAY
152185
NCPPhase.SLOWDOWN
153186
}
154187
}
155188

156189
if (player.isOnGround && !shouldJump) {
157-
ncpSpeed = ncpBaseSpeed
190+
ncpSpeed = NCP_BASE_SPEED
158191
}
159192

160193
ncpSpeed = ncpSpeed
161-
.coerceAtMost(ncpMaxSpeed)
162-
.coerceAtLeast(ncpBaseSpeed)
194+
.coerceAtMost(1.0)
195+
.coerceAtLeast(NCP_BASE_SPEED)
163196

164197
val moveSpeed = if (isInputting) ncpSpeed else {
165-
ncpSpeed = ncpBaseSpeed
198+
ncpSpeed = NCP_BASE_SPEED
166199
0.0
167200
}
168201

common/src/main/kotlin/com/lambda/util/primitives/extension/Box.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ import net.minecraft.util.math.Vec3d
55

66
val Box.min get() = Vec3d(minX, minY, minZ)
77

8-
val Box.max get() = Vec3d(maxX, maxY, maxZ)
8+
val Box.max get() = Vec3d(maxX, maxY, maxZ)
9+
10+
operator fun Box.contains(boundingBox: Box) = this.intersects(boundingBox)

0 commit comments

Comments
 (0)