Skip to content

Commit 051d20b

Browse files
committed
use rotation manager
1 parent b79bca2 commit 051d20b

File tree

1 file changed

+39
-36
lines changed

1 file changed

+39
-36
lines changed

src/main/kotlin/com/lambda/module/modules/movement/ElytraAttitudeControl.kt

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@
1717

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

20+
import com.lambda.config.groups.RotationSettings
2021
import com.lambda.event.events.TickEvent
2122
import com.lambda.event.listener.SafeListener.Companion.listen
23+
import com.lambda.interaction.managers.rotating.Rotation
24+
import com.lambda.interaction.managers.rotating.visibilty.lookAt
2225
import com.lambda.module.Module
2326
import com.lambda.module.modules.movement.BetterFirework.startFirework
2427
import com.lambda.module.tag.ModuleTag
@@ -77,6 +80,8 @@ object ElytraAttitudeControl : Module(
7780
val pitch40SpeedThreshold by setting("Speed Threshold", 41f, 10f..100f, .5f, description = "Speed at which to start pitching up") { usePitch40OnHeight }.group(Group.Pitch40Control)
7881
val pitch40UseFireworkOnUpTrajectory by setting("Use Firework On Up Trajectory", false, "Use fireworks when converting speed to altitude in the Pitch 40 maneuver") { usePitch40OnHeight }.group(Group.Pitch40Control)
7982

83+
override val rotationConfig = RotationSettings(this, Group.Rotation)
84+
8085
var controlState = ControlState.AttitudeControl
8186
var state = Pitch40State.GainSpeed
8287
var lastAngle = pitch40UpStartAngle
@@ -109,8 +114,7 @@ object ElytraAttitudeControl : Module(
109114
-1 * altitudeController.getOutput(targetAltitude.toDouble(), player.y) // Negative because in minecraft pitch > 0 is looking down not up
110115
}
111116
}.coerceIn(-maxPitchAngle, maxPitchAngle)
112-
// lookAt(Rotation(player.yaw, newPitch.toFloat())).requestBy(this@ElytraAutopilot) // TODO: Use this when rotation system accepts pitch changes
113-
player.pitch = outputPitch.toFloat()
117+
lookAt(Rotation(player.yaw, outputPitch.toFloat())).requestBy(this@ElytraAttitudeControl)
114118

115119
if (usageDelay.timePassed(2.seconds) && !player.hasFirework) {
116120
if (useFireworkOnHeight && minHeight > player.y) {
@@ -127,45 +131,43 @@ object ElytraAttitudeControl : Module(
127131
}
128132
}
129133
}
130-
ControlState.Pitch40Fly -> {
131-
when (state) {
132-
Pitch40State.GainSpeed -> {
133-
player.pitch = pitch40DownAngle
134-
if (player.flySpeed() > pitch40SpeedThreshold) {
135-
state = Pitch40State.PitchUp
136-
}
134+
ControlState.Pitch40Fly -> when (state) {
135+
Pitch40State.GainSpeed -> {
136+
player.pitch = pitch40DownAngle
137+
if (player.flySpeed() > pitch40SpeedThreshold) {
138+
state = Pitch40State.PitchUp
137139
}
138-
Pitch40State.PitchUp -> {
139-
lastAngle -= 5f
140-
player.pitch = lastAngle
141-
if (lastAngle <= pitch40UpStartAngle) {
142-
state = Pitch40State.FlyUp
143-
if (pitch40UseFireworkOnUpTrajectory) {
144-
runSafe {
145-
startFirework(true)
146-
}
140+
}
141+
Pitch40State.PitchUp -> {
142+
lastAngle -= 5f
143+
player.pitch = lastAngle
144+
if (lastAngle <= pitch40UpStartAngle) {
145+
state = Pitch40State.FlyUp
146+
if (pitch40UseFireworkOnUpTrajectory) {
147+
runSafe {
148+
startFirework(true)
147149
}
148150
}
149151
}
150-
Pitch40State.FlyUp -> {
151-
lastAngle += pitch40AngleChangeRate
152-
player.pitch = lastAngle
153-
if (lastAngle >= 0f) {
154-
state = Pitch40State.GainSpeed
155-
if (logHeightGain) {
156-
var timeDelta = lastCycleFinish.elapsedNow().inWholeMilliseconds
157-
var heightDelta = player.pos.y - lastY
158-
var heightPerMinute = (heightDelta) / (timeDelta / 1000.0) * 60.0
159-
info(literal("Height gained this cycle: %.2f in %.2f seconds (%.2f blocks/min)".format(heightDelta, timeDelta / 1000.0, heightPerMinute)))
160-
}
152+
}
153+
Pitch40State.FlyUp -> {
154+
lastAngle += pitch40AngleChangeRate
155+
player.pitch = lastAngle
156+
if (lastAngle >= 0f) {
157+
state = Pitch40State.GainSpeed
158+
if (logHeightGain) {
159+
var timeDelta = lastCycleFinish.elapsedNow().inWholeMilliseconds
160+
var heightDelta = player.pos.y - lastY
161+
var heightPerMinute = (heightDelta) / (timeDelta / 1000.0) * 60.0
162+
info(literal("Height gained this cycle: %.2f in %.2f seconds (%.2f blocks/min)".format(heightDelta, timeDelta / 1000.0, heightPerMinute)))
163+
}
161164

162-
lastCycleFinish = TimeSource.Monotonic.markNow()
163-
lastY = player.pos.y
164-
if (pitch40ExitHeight < player.y) {
165-
controlState = ControlState.AttitudeControl
166-
speedController.reset()
167-
altitudeController.reset()
168-
}
165+
lastCycleFinish = TimeSource.Monotonic.markNow()
166+
lastY = player.pos.y
167+
if (pitch40ExitHeight < player.y) {
168+
controlState = ControlState.AttitudeControl
169+
speedController.reset()
170+
altitudeController.reset()
169171
}
170172
}
171173
}
@@ -232,6 +234,7 @@ object ElytraAttitudeControl : Module(
232234
SpeedControl("Speed Control"),
233235
AltitudeControl("Altitude Control"),
234236
Pitch40Control("Pitch 40 Control"),
237+
Rotation("Rotation")
235238
}
236239

237240
enum class Pitch40State {

0 commit comments

Comments
 (0)