Skip to content

Commit 6542571

Browse files
committed
cleanup and fix grim control being buggy with grim rocket boost
1 parent 3c48997 commit 6542571

4 files changed

Lines changed: 37 additions & 46 deletions

File tree

src/main/kotlin/com/lambda/module/modules/movement/elytrafly/ElytraFly.kt

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import com.lambda.util.Timer
4040
import com.lambda.util.extension.isElytraFlying
4141
import com.lambda.util.extension.prevPos
4242
import com.lambda.util.player.MovementUtils.addSpeed
43-
import com.lambda.util.player.PlayerUtils.hasFirework
4443
import net.minecraft.component.DataComponentTypes
4544
import net.minecraft.entity.MovementType
4645
import net.minecraft.item.Items
@@ -68,7 +67,7 @@ object ElytraFly : Module(
6867
private val boostSpeed by setting("Boost", 0.0, 0.0..0.5, 0.005, description = "Speed to add when flying")
6968
private val rocketSpeed by setting("Rocket Speed", 1.0, 0.0..2.0, 0.01, description = "Speed multiplier that the rocket gives you")
7069
private val grimRocketBoost by setting("Grim Rocket Boost", true, description = "Automatically scale the firework rocket boost based on your pitch angle")
71-
private val maxGrimBoost by setting("Max Grim Boost", 10.0, 0.0..10.0, 0.01, description = "Maximum additional speed the firework boost can add on top of the base rocket speed") { grimRocketBoost }
70+
private val maxGrimBoost by setting("Max Grim Boost", 3.0, 0.0..3.0, 0.01, description = "Maximum additional speed the firework boost can add on top of the base rocket speed") { grimRocketBoost }
7271
private val safetyMargin by setting("Safety Margin", 0.2, 0.0..2.0, 0.01, "The time (in seconds) to shorten the firework use delay to account for ping variation", "s")
7372
private val mute by setting("Mute Elytra", false, "Mutes the elytra sound when gliding")
7473
@JvmStatic val fakeFly by setting("Fake Fly", false, "Rapidly swaps the chestplate and elytra to give the appearance the player is flying without an elytra. May also reduce durability loss")
@@ -91,17 +90,14 @@ object ElytraFly : Module(
9190

9291
// Last sent movement packet state, used to rebuild Grim's firework prediction box.
9392
private var lastMovementIncludedPosition = true
94-
private var lastKnownClientVelocity = Vec3d.ZERO
95-
private var hasMovementState = false
93+
private var prevVelocity = Vec3d.ZERO
9694
private var targetVelocity: Vec3d? = null
9795

9896
// Shared firework tracking. Vanilla can briefly drop the firework entity for a tick,
99-
// so once a firework is used we hold this true until its flight duration runs out.
97+
// so once a firework is used, we hold this true until its flight duration runs out.
10098
private val fireworkTimer = Timer()
10199
private var lastFireworkDuration = -1.0
102100
@JvmStatic var hasFirework = false
103-
private var fireworkConfirmed = false
104-
private var fireworkReady = false
105101

106102
init {
107103
setDefaultAutomationConfig()
@@ -112,12 +108,9 @@ object ElytraFly : Module(
112108

113109
onEnable {
114110
mode.elytraFly.onEnableListeners.forEach { it() }
115-
lastKnownClientVelocity = Vec3d.ZERO
116-
hasMovementState = false
111+
prevVelocity = Vec3d.ZERO
117112
targetVelocity = null
118113
hasFirework = false
119-
fireworkConfirmed = false
120-
fireworkReady = false
121114
fireworkTimer.reset()
122115
lastFireworkDuration = -1.0
123116
}
@@ -126,16 +119,10 @@ object ElytraFly : Module(
126119
listen<TickEvent.Pre>(priority = { 1 }) {
127120
if (!player.isGliding) {
128121
hasFirework = false
129-
fireworkConfirmed = false
130-
fireworkReady = false
131122
return@listen
132123
}
133124
if (fireworkTimer.timePassed((lastFireworkDuration - safetyMargin).seconds)) {
134125
hasFirework = false
135-
fireworkConfirmed = false
136-
fireworkReady = false
137-
} else if (player.hasFirework) {
138-
fireworkConfirmed = true
139126
}
140127
}
141128

@@ -151,22 +138,19 @@ object ElytraFly : Module(
151138

152139
listen<TickEvent.Pre> {
153140
if (!grimRocketBoost) return@listen
154-
if (!player.isGliding || !hasFirework || !fireworkConfirmed || !fireworkReady || !hasMovementState) return@listen
141+
if (!player.isGliding || !hasFirework || mode.elytraFly.pausingMovement()) return@listen
155142

156143
val aiming = Vec3d.fromPolar(
157144
RotationManager.movementPitch ?: player.pitch,
158145
RotationManager.movementYaw ?: player.yaw,
159146
)
160-
val serverRot = RotationManager.serverRotation
161-
val bounds = GrimFireworkBox.computeFireworksBounds(
162-
lastKnownClientVelocity,
163-
aiming,
164-
serverRot.pitchF,
165-
serverRot.yawF,
166-
lastMovementIncludedPosition,
167-
EXPLOIT_RESCALE,
168-
player.finalGravity,
169-
) ?: return@listen
147+
val bounds =
148+
GrimFireworkBox.getFireworkBounds(
149+
prevVelocity,
150+
aiming,
151+
lastMovementIncludedPosition,
152+
EXPLOIT_RESCALE
153+
) ?: return@listen
170154
val claimed = farthestPointInBox(bounds, aiming)?.let { limitSpeed(it) } ?: return@listen
171155

172156
targetVelocity = claimed
@@ -179,11 +163,9 @@ object ElytraFly : Module(
179163
val prevPos = player.prevPos
180164
val next = Vec3d(packet.getX(prevPos.x), packet.getY(prevPos.y), packet.getZ(prevPos.z))
181165
val delta = next.subtract(prevPos)
182-
if (hasMovementState) lastKnownClientVelocity = delta
183-
if (fireworkConfirmed) fireworkReady = true
166+
prevVelocity = delta
184167
}
185168
lastMovementIncludedPosition = packet.changesPosition()
186-
hasMovementState = true
187169
}
188170

189171
listen<MovementEvent.Entity.Pre> { event ->

src/main/kotlin/com/lambda/module/modules/movement/elytrafly/ElytraFlyMode.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,6 @@ abstract class ElytraFlyMode(
136136
connection.sendPacket(ClientCommandC2SPacket(player, ClientCommandC2SPacket.Mode.START_FALL_FLYING))
137137

138138
open fun isGliding() = runSafe { player.getFlag(Entity.GLIDING_FLAG_INDEX) || (fakeFly && fakeGliding) } == true
139+
140+
open fun pausingMovement() = false
139141
}

src/main/kotlin/com/lambda/module/modules/movement/elytrafly/GrimFireworkBox.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package com.lambda.module.modules.movement.elytrafly
1919

20+
import com.lambda.context.SafeContext
21+
import com.lambda.interaction.managers.rotating.RotationManager
2022
import net.minecraft.util.math.MathHelper
2123
import net.minecraft.util.math.Vec3d
2224
import kotlin.math.asin
@@ -26,19 +28,18 @@ import kotlin.math.min
2628
import kotlin.math.sin
2729

2830
object GrimFireworkBox {
29-
fun computeFireworksBounds(
31+
context(safeContext: SafeContext)
32+
fun getFireworkBounds(
3033
lastKnownClientVelocity: Vec3d,
3134
currentRotation: Vec3d,
32-
lastSentPitch: Float,
33-
lastSentYaw: Float,
3435
lastMovementIncludedPosition: Boolean,
35-
rescaleAmount: Double,
36-
gravity: Double
36+
rescaleAmount: Double
3737
): DoubleArray? {
38-
val simulatedVelocity = calculateGlidingVelocity(lastKnownClientVelocity, currentRotation, gravity)
38+
val simulatedVelocity = calcGlidingVelocity(lastKnownClientVelocity, currentRotation, safeContext.player.finalGravity)
3939

40+
val serverRot = RotationManager.serverRotation
4041
val currentLook = currentRotation.normalize()
41-
val lastLook = Vec3d.fromPolar(lastSentPitch, lastSentYaw).normalize()
42+
val lastLook = Vec3d.fromPolar(serverRot.pitchF, serverRot.yawF).normalize()
4243
val antiTickSkipping = if (lastMovementIncludedPosition) 0.05 else 0.0
4344

4445
var minX = min(-antiTickSkipping, currentLook.x) + min(-antiTickSkipping, lastLook.x)
@@ -67,7 +68,7 @@ object GrimFireworkBox {
6768
)
6869
}
6970

70-
fun calculateGlidingVelocity(oldVelocity: Vec3d, rotation: Vec3d, gravity: Double): Vec3d {
71+
fun calcGlidingVelocity(oldVelocity: Vec3d, rotation: Vec3d, gravity: Double): Vec3d {
7172
val horizontalLookLength = rotation.horizontalLength()
7273
val horizontalSpeed = oldVelocity.horizontalLength()
7374
val pitch = asin(MathHelper.clamp(-rotation.y, -1.0, 1.0)).toFloat()

src/main/kotlin/com/lambda/module/modules/movement/elytrafly/modes/GrimControlElytraFly.kt

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class GrimControlElytraFly(
6767
private val stillTickTimer = TickTimer()
6868

6969
init {
70-
listen<TickEvent.Pre> {
70+
listen<TickEvent.Pre>({ 1 }) {
7171
if (!player.isGliding) return@listen
7272

7373
if (fakeGliding) flyOrFakeFly()
@@ -92,33 +92,37 @@ class GrimControlElytraFly(
9292
specificYaw = true
9393
}
9494
if (mc.options.jumpKey.isPressed) {
95-
val yaw = if (specificYaw) vec.yawAndPitch.y else player.yaw
96-
vec = Vec3d.fromPolar(-upDownAngle, yaw)
95+
vec =
96+
if (specificYaw) Vec3d.fromPolar(-upDownAngle, vec.yawAndPitch.y)
97+
else Vec3d.fromPolar(-90f, yaw)
9798
}
9899
if (mc.options.sneakKey.isPressed) {
99-
val yaw = if (specificYaw) vec.yawAndPitch.y else player.yaw
100-
vec = Vec3d.fromPolar(upDownAngle, yaw)
100+
vec =
101+
if (specificYaw) Vec3d.fromPolar(upDownAngle, vec.yawAndPitch.y)
102+
else Vec3d.fromPolar(90f, yaw)
101103
}
102104

103105
val prevStill = still
104106
still = vec.lengthSquared() < 1e-4 || Freecam.isEnabled
105-
if (still) moving = false
106107

107108
if (still) {
109+
moving = false
108110
if (!flipFlopMode.isFlipFlopping(hasFirework)) {
109111
stillTickTimer.tick()
110112
return@listen
111113
}
112114
rotationRequest { rotation(if (flipFlop) 0.0 else 180.0, 0.0) }.submit()
113115
flipFlop = !flipFlop
114-
return@listen
116+
if (flipFlopMode == FlipFlopMode.WithFirework) return@listen
115117
}
116118

117119
if (!hasFirework) {
118120
if (findFirework() == null) return@listen
119121
startFirework(inventory)
120122
}
121123

124+
if (still) return@listen
125+
122126
val rot = vec.yawAndPitch
123127
rotationRequest { rotation(rot.y, rot.x) }.submit()
124128
if (hasFirework) {
@@ -152,4 +156,6 @@ class GrimControlElytraFly(
152156
val stack = Items.FIREWORK_ROCKET.select()
153157
return stack.bestItemMatch(player.hotbarStacks) ?: if (inventory) stack.bestItemMatch(player.inventoryStacks) else null
154158
}
159+
160+
override fun pausingMovement() = still
155161
}

0 commit comments

Comments
 (0)