@@ -4,21 +4,21 @@ import com.mojang.math.Axis
44import net.minecraft.client.gui.GuiGraphics
55import net.minecraft.network.chat.Component
66import net.minecraft.resources.ResourceLocation
7+ import net.minecraft.util.Mth
78import ru.octol1ttle.flightassistant.FlightAssistant
89import ru.octol1ttle.flightassistant.api.autoflight.ControlInput
910import ru.octol1ttle.flightassistant.api.computer.ComputerBus
1011import ru.octol1ttle.flightassistant.api.display.Display
1112import ru.octol1ttle.flightassistant.api.display.HudFrame
1213import ru.octol1ttle.flightassistant.api.util.FATickCounter
13- import ru.octol1ttle.flightassistant.api.util.FloatLerper
1414import ru.octol1ttle.flightassistant.api.util.ScreenSpace
1515import ru.octol1ttle.flightassistant.api.util.extensions.*
16+ import ru.octol1ttle.flightassistant.api.util.findShortestPath
1617import ru.octol1ttle.flightassistant.config.FAConfig
17- import kotlin.math.roundToInt
1818
1919class FlightDirectorsDisplay (computers : ComputerBus ) : Display(computers) {
20- private val xLerper : FloatLerper = FloatLerper ()
21- private val yLerper : FloatLerper = FloatLerper ()
20+ private var lastPitch : Float? = null
21+ private var lastYaw : Float? = null
2222
2323 override fun allowedByConfig (): Boolean {
2424 return FAConfig .hud.showFlightDirectors.allowed()
@@ -43,17 +43,29 @@ class FlightDirectorsDisplay(computers: ComputerBus) : Display(computers) {
4343
4444 val pitchInput: ControlInput ? = computers.pitch.activeInput
4545 if (pitchInput != null && pitchInput.priority >= ControlInput .Priority .NORMAL ) {
46- yLerper.get(ScreenSpace .getY(pitchInput.target)?.toFloat(), FATickCounter .timePassed * 1.5f )?.roundToInt()?.let {
47- hLine(this .centerX - halfWidth, this .centerX + halfWidth, it.coerceIn(HudFrame .top + 1 .. <HudFrame .bottom - 1), primaryAdvisoryColor)
46+ val last = lastPitch
47+ val target = if (last != null ) Mth .lerp(FATickCounter .partialTick, last, pitchInput.target) else pitchInput.target
48+ ScreenSpace .getY(target)?.let {
49+ hLine(this .centerX - halfWidth, this .centerX + halfWidth, it, primaryAdvisoryColor)
4850 }
4951 }
52+ if (FATickCounter .ticksPassed >= 1 ) {
53+ lastPitch = pitchInput?.target
54+ }
5055
5156 val headingInput: ControlInput ? = computers.heading.activeInput
5257 if (headingInput != null && headingInput.priority >= ControlInput .Priority .NORMAL ) {
53- xLerper.get(ScreenSpace .getX(headingInput.target)?.toFloat(), FATickCounter .timePassed * 1.5f )?.roundToInt()?.let {
54- vLine(it.coerceIn(HudFrame .left + 1 .. <HudFrame .right - 1), this.centerY - halfWidth, this.centerY + halfWidth, primaryAdvisoryColor)
58+ val last = lastYaw
59+ val target =
60+ if (last == null ) headingInput.target
61+ else Mth .lerp(FATickCounter .partialTick, last, last + findShortestPath(last, headingInput.target, 360.0f ))
62+ ScreenSpace .getX(target)?.let {
63+ vLine(it, this .centerY - halfWidth, this .centerY + halfWidth, primaryAdvisoryColor)
5564 }
5665 }
66+ if (FATickCounter .ticksPassed >= 1 ) {
67+ lastYaw = headingInput?.target
68+ }
5769
5870 HudFrame .maybeDisableScissor(this )
5971 pose().pop()
0 commit comments