Skip to content

Commit 67ac955

Browse files
committed
Flip Flop Mode setting to pick between With Full, Firework, and None
1 parent d13606a commit 67ac955

2 files changed

Lines changed: 34 additions & 30 deletions

File tree

src/main/java/com/lambda/mixin/entity/LivingEntityMixin.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,11 @@ private boolean injectIsGliding(boolean original) {
185185
@Inject(method = "travelGliding", at = @At("HEAD"), cancellable = true)
186186
private void injectTravelGliding(Vec3d movementInput, CallbackInfo ci) {
187187
if (lambda$instance != Lambda.getMc().player) return;
188+
final var grimMode = ElytraFly.getGrimControlMode();
188189
if (ElytraFly.INSTANCE.isEnabled() &&
189190
ElytraFly.getMode() == ElytraFly.FlyMode.GrimControl &&
190-
ElytraFly.getGrimControlMode().getNoFlipFlop() &&
191-
!ElytraFly.getGrimControlMode().getMoving()
191+
!grimMode.getFlipFlopMode().isFlipFlopping().invoke(grimMode.getHasFirework()) &&
192+
!grimMode.getMoving()
192193
) ci.cancel();
193194
}
194195
}

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

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import com.lambda.interaction.material.StackSelection.Companion.select
2929
import com.lambda.module.modules.movement.BetterFirework.startFirework
3030
import com.lambda.module.modules.movement.elytrafly.ElytraFly.FlyMode
3131
import com.lambda.module.modules.movement.elytrafly.ElytraFlyMode
32+
import com.lambda.util.NamedEnum
3233
import com.lambda.util.TickTimer
3334
import com.lambda.util.Timer
3435
import com.lambda.util.math.MathUtils.toFloat
@@ -45,8 +46,17 @@ import kotlin.time.Duration.Companion.seconds
4546
class GrimControlElytraFly(override val c: Config) : ElytraFlyMode(FlyMode.GrimControl) {
4647
private val inventory by c.setting("Inventory", true, "Allow using fireworks from the players inventory")
4748
private val safetyMargin by c.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")
48-
val noFlipFlop by c.setting("No Flip Flop", true, "Stops flying completely rather than the usual back and forth.")
49-
private val packetGap by c.setting("Packet Gap", 5, 0..100, 1, "The gap between allowing player movement packets to pass") { noFlipFlop }
49+
val flipFlopMode by c.setting("Flip Flop Mode", FlipFlopMode.WithFirework)
50+
private val packetGap by c.setting("Packet Gap", 20, 0..100, 1, "The gap between allowing player movement packets to pass") { flipFlopMode != FlipFlopMode.None }
51+
52+
enum class FlipFlopMode(
53+
override val displayName: String,
54+
val isFlipFlopping: (hasFirework: Boolean) -> Boolean
55+
) : NamedEnum {
56+
Full("Full", { true }),
57+
WithFirework("With Firework", { hasFirework -> hasFirework }),
58+
None("None", { false })
59+
}
5060

5161
private var flipFlop = false
5262
private var rotFlipFlop = false
@@ -56,12 +66,11 @@ class GrimControlElytraFly(override val c: Config) : ElytraFlyMode(FlyMode.GrimC
5666
var moving = false
5767
// Seems to be a weird bug with fireworks not showing every second or so i'd say.
5868
// This ensures it stays constant to avoid random stutters
59-
private var shouldHaveFirework = false
69+
var hasFirework = false
6070
private val stillTickTimer = TickTimer()
6171

6272
init {
6373
listen<TickEvent.Pre> {
64-
shouldHaveFirework = shouldHaveFirework or player.hasFirework
6574
if (!player.isGliding) return@listen
6675

6776
var vec = Vec3d.ZERO
@@ -73,52 +82,46 @@ class GrimControlElytraFly(override val c: Config) : ElytraFlyMode(FlyMode.GrimC
7382
if (mc.options.jumpKey.isPressed) vec = vec.add(Vec3d(0.0, 1.0, 0.0))
7483
if (mc.options.sneakKey.isPressed) vec = vec.add(Vec3d(0.0, -1.0, 0.0))
7584

85+
val prevStill = still
7686
still = vec.lengthSquared() < 1e-4
7787
if (still) moving = false
7888

79-
if (still && noFlipFlop) {
89+
if (still && flipFlopMode != FlipFlopMode.Full) {
8090
stillTickTimer.tick()
81-
if (!player.hasFirework) shouldHaveFirework = false
82-
return@listen
91+
hasFirework = player.hasFirework
92+
if (!flipFlopMode.isFlipFlopping(hasFirework)) return@listen
8393
} else {
84-
val firework = findFirework()
8594
if (fireworkTimer.timePassed(lastDuration.seconds - safetyMargin.seconds)) {
86-
if (firework == null) shouldHaveFirework = false
87-
else {
88-
lastDuration = (firework.get(DataComponentTypes.FIREWORKS)?.flightDuration ?: 1) * 0.5 + 0.5
89-
startFirework(inventory)
90-
fireworkTimer.reset()
91-
}
95+
val firework = findFirework()
96+
hasFirework = firework != null
97+
if (firework == null) return@listen
98+
lastDuration = (firework.get(DataComponentTypes.FIREWORKS)?.flightDuration ?: 1) * 0.5 + 0.5
99+
startFirework(inventory)
100+
fireworkTimer.reset()
92101
}
93102
}
94103

95-
if (!shouldHaveFirework) return@listen
96-
97104
if (still) {
98-
if (flipFlop) {
99-
flipFlop = false
100-
rotationRequest { rotation(0f, 0f) }
101-
} else {
102-
flipFlop = true
103-
rotationRequest { rotation(180f, 0f) }
104-
}
105+
rotationRequest { rotation(if (flipFlop) 0.0 else 180.0, 0.0) }.submit()
106+
flipFlop = !flipFlop
105107
} else {
106108
moving = true
109+
if (prevStill && !player.hasFirework) player.velocity = Vec3d.ZERO
107110
val rot = vec.yawAndPitch
108-
rotationRequest { rotation(rot.y, rot.x) }
109-
}.submit()
111+
rotationRequest { rotation(rot.y, rot.x) }.submit()
112+
}
110113
}
111114

112115
listen<PlayerPacketEvent.Send> { event ->
113-
if (!player.isGliding || !noFlipFlop) return@listen
116+
if (!player.isGliding) return@listen
114117
val rot = RotationManager.activeRotation
115-
val flipFlop = rotFlipFlop.toFloat() * 0.001f
118+
val flipFlop = rotFlipFlop.toFloat() * 0.0001f
116119
rotFlipFlop = !rotFlipFlop
117120
event.packet = PlayerMoveC2SPacket.Full(player.pos, rot.yawF + flipFlop, rot.pitchF, player.isOnGround, player.horizontalCollision)
118121
}
119122

120123
listen<PacketEvent.Send.Pre> { event ->
121-
if (event.packet !is PlayerMoveC2SPacket || !player.isGliding || !noFlipFlop || !still) return@listen
124+
if (event.packet !is PlayerMoveC2SPacket || !player.isGliding || flipFlopMode.isFlipFlopping(hasFirework) || moving) return@listen
122125
if (stillTickTimer.hasSurpassed(packetGap)) {
123126
stillTickTimer.reset()
124127
return@listen

0 commit comments

Comments
 (0)