Skip to content

Commit 668e6e6

Browse files
committed
fixing stuff yay
Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
1 parent 96acbb3 commit 668e6e6

File tree

18 files changed

+95
-54
lines changed

18 files changed

+95
-54
lines changed

src/main/kotlin/ru/octol1ttle/flightassistant/api/computer/ComputerView.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ package ru.octol1ttle.flightassistant.api.computer
22

33
import java.util.function.Function
44
import ru.octol1ttle.flightassistant.api.ModuleView
5-
import ru.octol1ttle.flightassistant.impl.computer.AirDataComputer
65
import ru.octol1ttle.flightassistant.impl.computer.autoflight.AutoFlightComputer
76
import ru.octol1ttle.flightassistant.impl.computer.autoflight.FireworkComputer
87
import ru.octol1ttle.flightassistant.impl.computer.autoflight.FlightPlanComputer
98
import ru.octol1ttle.flightassistant.impl.computer.autoflight.base.HeadingComputer
109
import ru.octol1ttle.flightassistant.impl.computer.autoflight.base.PitchComputer
1110
import ru.octol1ttle.flightassistant.impl.computer.autoflight.base.RollComputer
1211
import ru.octol1ttle.flightassistant.impl.computer.autoflight.base.ThrustComputer
12+
import ru.octol1ttle.flightassistant.impl.computer.data.AirDataComputer
13+
import ru.octol1ttle.flightassistant.impl.computer.data.HudDisplayDataComputer
1314
import ru.octol1ttle.flightassistant.impl.computer.safety.*
1415

1516
interface ComputerView : ModuleView<Computer> {
@@ -18,6 +19,9 @@ interface ComputerView : ModuleView<Computer> {
1819
val data: AirDataComputer
1920
get() = get(AirDataComputer.ID) as AirDataComputer
2021

22+
val hudData: HudDisplayDataComputer
23+
get() = get(HudDisplayDataComputer.ID) as HudDisplayDataComputer
24+
2125
val autoflight: AutoFlightComputer
2226
get() = get(AutoFlightComputer.ID) as AutoFlightComputer
2327

src/main/kotlin/ru/octol1ttle/flightassistant/impl/computer/ComputerHost.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import ru.octol1ttle.flightassistant.impl.computer.autoflight.base.HeadingComput
1717
import ru.octol1ttle.flightassistant.impl.computer.autoflight.base.PitchComputer
1818
import ru.octol1ttle.flightassistant.impl.computer.autoflight.base.RollComputer
1919
import ru.octol1ttle.flightassistant.impl.computer.autoflight.base.ThrustComputer
20+
import ru.octol1ttle.flightassistant.impl.computer.data.AirDataComputer
21+
import ru.octol1ttle.flightassistant.impl.computer.data.HudDisplayDataComputer
2022
import ru.octol1ttle.flightassistant.impl.computer.safety.*
2123

2224
internal object ComputerHost : ModuleController<Computer>, ComputerView {
@@ -69,6 +71,7 @@ internal object ComputerHost : ModuleController<Computer>, ComputerView {
6971

7072
private fun registerBuiltin() {
7173
register(AirDataComputer.ID, AirDataComputer(this, mc))
74+
register(HudDisplayDataComputer.ID, HudDisplayDataComputer(this, mc))
7275
register(FlightProtectionsComputer.ID, FlightProtectionsComputer(this))
7376

7477
register(StallComputer.ID, StallComputer(this))

src/main/kotlin/ru/octol1ttle/flightassistant/impl/computer/autoflight/builtin/BuiltInThrustModes.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,9 @@ data class TakeoffThrustMode(val data: FlightPlanComputer.DepartureData) : AutoF
2121

2222
data class SpeedThrustMode(val target: Int) : AutoFlightComputer.ThrustMode {
2323
override fun getControlInput(computers: ComputerView): ControlInput? {
24-
// TODO: this should NOT rely on interpolated values, they are naturally "biased" and they don't change more than once per tick anyway
25-
// TODO: this leads to severe overcorrection as the response is "late"
26-
// TODO: (reminder that this code runs every LEVEL RENDER not tick)
2724
val currentThrust: Float = computers.thrust.current
2825
val currentSpeed: Double = computers.data.forwardVelocity.length() * 20
29-
val acceleration: Double = computers.data.forwardAcceleration.length() * 20
26+
val acceleration: Double = computers.data.forwardAcceleration * 20
3027

3128
val speedCorrection: Double = (target - currentSpeed) * FATickCounter.timePassed.pow(1.5f)
3229
val accelerationDamping: Double = -acceleration * FATickCounter.timePassed

src/main/kotlin/ru/octol1ttle/flightassistant/impl/computer/autoflight/builtin/BuiltInVerticalModes.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ data class PitchVerticalMode(val target: Float) : AutoFlightComputer.VerticalMod
1313
return ControlInput(
1414
target,
1515
ControlInput.Priority.NORMAL,
16-
Component.translatable("mode.flightassistant.vertical.pitch")
16+
Component.translatable("mode.flightassistant.vertical.pitch", target.toInt())
1717
)
1818
}
1919
}
@@ -24,10 +24,10 @@ data class SpeedReferenceVerticalMode(val targetSpeed: Int) : AutoFlightComputer
2424
val range: Float = computers.thrust.getOptimumClimbPitch() - computers.thrust.getAltitudeHoldPitch()
2525
val currentPitch: Float = computers.data.pitch
2626
val currentSpeed: Double = computers.data.forwardVelocity.length() * 20
27-
val acceleration: Double = computers.data.forwardAcceleration.length() * 20
27+
val acceleration: Double = computers.data.forwardAcceleration * 20
2828

29-
val speedCorrection: Double = (currentSpeed - targetSpeed) * FATickCounter.timePassed.pow(2) * range
30-
val accelerationDamping: Double = -acceleration * FATickCounter.timePassed.pow(4) * range
29+
val speedCorrection: Double = (currentSpeed - targetSpeed) * FATickCounter.timePassed.pow(1.5f) * range
30+
val accelerationDamping: Double = -acceleration * FATickCounter.timePassed.pow(2.0f) * range
3131
return ControlInput(
3232
(currentPitch + speedCorrection + accelerationDamping).toFloat().coerceIn(computers.thrust.getAltitudeHoldPitch()..computers.thrust.getOptimumClimbPitch()),
3333
ControlInput.Priority.NORMAL,

src/main/kotlin/ru/octol1ttle/flightassistant/impl/computer/AirDataComputer.kt renamed to src/main/kotlin/ru/octol1ttle/flightassistant/impl/computer/data/AirDataComputer.kt

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
package ru.octol1ttle.flightassistant.impl.computer
1+
package ru.octol1ttle.flightassistant.impl.computer.data
22

33
import kotlin.math.asin
4-
import kotlin.math.atan2
54
import kotlin.math.max
65
import net.minecraft.client.Minecraft
76
import net.minecraft.client.multiplayer.ClientLevel
87
import net.minecraft.client.player.LocalPlayer
98
import net.minecraft.core.Direction
109
import net.minecraft.resources.ResourceLocation
1110
import net.minecraft.tags.DamageTypeTags
12-
import net.minecraft.util.Mth.wrapDegrees
11+
import net.minecraft.util.Mth
1312
import net.minecraft.world.damagesource.DamageSource
1413
import net.minecraft.world.level.ClipContext
1514
import net.minecraft.world.phys.BlockHitResult
@@ -18,8 +17,6 @@ import net.minecraft.world.phys.Vec3
1817
import ru.octol1ttle.flightassistant.FlightAssistant
1918
import ru.octol1ttle.flightassistant.api.computer.Computer
2019
import ru.octol1ttle.flightassistant.api.computer.ComputerView
21-
import ru.octol1ttle.flightassistant.api.util.FATickCounter.partialTick
22-
import ru.octol1ttle.flightassistant.api.util.RenderMatrices
2320
import ru.octol1ttle.flightassistant.api.util.degrees
2421
import ru.octol1ttle.flightassistant.api.util.extensions.bottomY
2522
import ru.octol1ttle.flightassistant.api.util.requireIn
@@ -33,8 +30,8 @@ class AirDataComputer(computers: ComputerView, private val mc: Minecraft) : Comp
3330
val level: ClientLevel
3431
get() = checkNotNull(mc.level)
3532

36-
var position: Vec3 = Vec3.ZERO
37-
private set
33+
val position: Vec3
34+
get() = player.position()
3835
val altitude: Double
3936
get() = position.y
4037
val voidY: Int
@@ -55,21 +52,19 @@ class AirDataComputer(computers: ComputerView, private val mc: Minecraft) : Comp
5552
val fallDistanceSafe: Boolean
5653
get() = player.isInWater || fallDistance <= player.maxFallDistance || isInvulnerableTo(player.damageSources().fall())
5754

58-
var velocity: Vec3 = Vec3.ZERO
59-
private set
55+
val velocity: Vec3
56+
get() = player.deltaMovement
6057
var forwardVelocity: Vec3 = Vec3.ZERO
6158
private set
62-
var forwardAcceleration: Vec3 = Vec3.ZERO
59+
var forwardAcceleration: Double = 0.0
6360
private set
6461

6562
val pitch: Float
6663
get() = -player.xRot.requireIn(-90.0f..90.0f)
6764
val yaw: Float
68-
get() = wrapDegrees(player.yRot).requireIn(-180.0f..180.0f)
65+
get() = Mth.wrapDegrees(player.yRot).requireIn(-180.0f..180.0f)
6966
val heading: Float
7067
get() = (yaw + 180.0f).requireIn(0.0f..360.0f)
71-
var roll: Float = 0.0f
72-
private set(value) { field = value.requireIn(-180.0f..180.0f) }
7368

7469
val flightPitch: Float
7570
get() = degrees(asin(velocity.normalize().y).toFloat())
@@ -78,12 +73,9 @@ class AirDataComputer(computers: ComputerView, private val mc: Minecraft) : Comp
7873
get() = level.chunkSource.hasChunk(player.chunkPosition().x, player.chunkPosition().z)
7974

8075
override fun tick() {
81-
position = player.getPosition(partialTick)
8276
groundY = computeGroundLevel()
83-
velocity = player.getDeltaMovementLerped(partialTick)
8477
forwardVelocity = computeForwardVector(velocity)
85-
forwardAcceleration = computeForwardVector(player.deltaMovement.subtract(player.getDeltaMovementLerped(0.0f)))
86-
roll = degrees(atan2(-RenderMatrices.worldSpaceMatrix.m10(), RenderMatrices.worldSpaceMatrix.m11()))
78+
forwardAcceleration = forwardVelocity.length() - computeForwardVector(player.getDeltaMovementLerped(0.0f)).length()
8779
}
8880

8981
fun automationsAllowed(checkFlying: Boolean = true): Boolean {
@@ -123,22 +115,19 @@ class AirDataComputer(computers: ComputerView, private val mc: Minecraft) : Comp
123115
return result.location.y
124116
}
125117

126-
private fun computeForwardVector(vector: Vec3): Vec3 {
118+
fun computeForwardVector(vector: Vec3): Vec3 {
127119
val normalizedLookAngle: Vec3 = player.lookAngle.normalize()
128120
val normalizedVector: Vec3 = vector.normalize()
129121
return vector.scale(normalizedLookAngle.dot(normalizedVector).coerceAtLeast(0.0))
130122
}
131123

132124
override fun reset() {
133-
position = Vec3.ZERO
134125
groundY = null
135-
velocity = Vec3.ZERO
136126
forwardVelocity = Vec3.ZERO
137-
forwardAcceleration = Vec3.ZERO
138-
roll = 0.0f
127+
forwardAcceleration = 0.0
139128
}
140129

141130
companion object {
142131
val ID: ResourceLocation = FlightAssistant.id("air_data")
143132
}
144-
}
133+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package ru.octol1ttle.flightassistant.impl.computer.data
2+
3+
import kotlin.math.atan2
4+
import net.minecraft.client.Minecraft
5+
import net.minecraft.client.player.LocalPlayer
6+
import net.minecraft.resources.ResourceLocation
7+
import net.minecraft.world.phys.Vec3
8+
import ru.octol1ttle.flightassistant.FlightAssistant
9+
import ru.octol1ttle.flightassistant.api.computer.Computer
10+
import ru.octol1ttle.flightassistant.api.computer.ComputerView
11+
import ru.octol1ttle.flightassistant.api.util.FATickCounter
12+
import ru.octol1ttle.flightassistant.api.util.RenderMatrices
13+
import ru.octol1ttle.flightassistant.api.util.degrees
14+
import ru.octol1ttle.flightassistant.api.util.requireIn
15+
16+
class HudDisplayDataComputer(computers: ComputerView, private val mc: Minecraft) : Computer(computers) {
17+
val player: LocalPlayer
18+
get() = checkNotNull(mc.player)
19+
20+
var lerpedPosition: Vec3 = Vec3.ZERO
21+
private set
22+
var lerpedVelocity: Vec3 = Vec3.ZERO
23+
private set
24+
var lerpedForwardVelocity: Vec3 = Vec3.ZERO
25+
private set
26+
27+
val lerpedAltitude: Double
28+
get() = lerpedPosition.y
29+
30+
val roll: Float
31+
get() = degrees(atan2(-RenderMatrices.worldSpaceMatrix.m10(), RenderMatrices.worldSpaceMatrix.m11())).requireIn(-180.0f..180.0f)
32+
33+
override fun tick() {
34+
lerpedPosition = player.getPosition(FATickCounter.partialTick)
35+
lerpedVelocity = player.getDeltaMovementLerped(FATickCounter.partialTick)
36+
lerpedForwardVelocity = computers.data.computeForwardVector(lerpedVelocity)
37+
}
38+
39+
override fun reset() {
40+
lerpedPosition = Vec3.ZERO
41+
lerpedVelocity = Vec3.ZERO
42+
lerpedForwardVelocity = Vec3.ZERO
43+
}
44+
45+
companion object {
46+
val ID: ResourceLocation = FlightAssistant.id("hud_display_data")
47+
}
48+
}

src/main/kotlin/ru/octol1ttle/flightassistant/impl/computer/safety/AlertComputer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ import ru.octol1ttle.flightassistant.impl.alert.stall.FullStallAlert
4141
import ru.octol1ttle.flightassistant.impl.alert.thrust.NoThrustSourceAlert
4242
import ru.octol1ttle.flightassistant.impl.alert.thrust.ReverseThrustNotSupportedAlert
4343
import ru.octol1ttle.flightassistant.impl.alert.thrust.ThrustLockedAlert
44-
import ru.octol1ttle.flightassistant.impl.computer.AirDataComputer
4544
import ru.octol1ttle.flightassistant.impl.computer.autoflight.AutoFlightComputer
4645
import ru.octol1ttle.flightassistant.impl.computer.autoflight.FireworkComputer
4746
import ru.octol1ttle.flightassistant.impl.computer.autoflight.FlightPlanComputer
4847
import ru.octol1ttle.flightassistant.impl.computer.autoflight.base.HeadingComputer
4948
import ru.octol1ttle.flightassistant.impl.computer.autoflight.base.PitchComputer
5049
import ru.octol1ttle.flightassistant.impl.computer.autoflight.base.RollComputer
5150
import ru.octol1ttle.flightassistant.impl.computer.autoflight.base.ThrustComputer
51+
import ru.octol1ttle.flightassistant.impl.computer.data.AirDataComputer
5252
import ru.octol1ttle.flightassistant.impl.display.HudDisplayHost
5353

5454
class AlertComputer(computers: ComputerView, private val soundManager: SoundManager) : Computer(computers) {

src/main/kotlin/ru/octol1ttle/flightassistant/impl/computer/safety/ElytraStatusComputer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import ru.octol1ttle.flightassistant.api.computer.Computer
1616
import ru.octol1ttle.flightassistant.api.computer.ComputerView
1717
import ru.octol1ttle.flightassistant.config.FAConfig
1818
import ru.octol1ttle.flightassistant.config.options.DisplayOptions
19-
import ru.octol1ttle.flightassistant.impl.computer.AirDataComputer
19+
import ru.octol1ttle.flightassistant.impl.computer.data.AirDataComputer
2020

2121
class ElytraStatusComputer(computers: ComputerView) : Computer(computers) {
2222
private var activeElytra: ItemStack? = null

src/main/kotlin/ru/octol1ttle/flightassistant/impl/computer/safety/GroundProximityComputer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import ru.octol1ttle.flightassistant.api.computer.Computer
2020
import ru.octol1ttle.flightassistant.api.computer.ComputerView
2121
import ru.octol1ttle.flightassistant.api.util.requireIn
2222
import ru.octol1ttle.flightassistant.config.FAConfig
23-
import ru.octol1ttle.flightassistant.impl.computer.AirDataComputer
23+
import ru.octol1ttle.flightassistant.impl.computer.data.AirDataComputer
2424

2525
class GroundProximityComputer(computers: ComputerView) : Computer(computers), PitchLimiter, FlightController {
2626
private var groundImpactTime: Float = Float.MAX_VALUE

src/main/kotlin/ru/octol1ttle/flightassistant/impl/display/AltitudeDisplay.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class AltitudeDisplay(computers: ComputerView) : Display(computers) {
3232
pose().push()
3333
fusedTranslateScale(x, y, READING_MATRIX_SCALE)
3434

35-
val altitude: Double = computers.data.altitude
35+
val altitude: Double = computers.hudData.lerpedAltitude
3636
val text: String = altitude.roundToInt().toString()
3737

3838
val width: Int = textWidth(text) + 5
@@ -46,7 +46,7 @@ class AltitudeDisplay(computers: ComputerView) : Display(computers) {
4646
}
4747

4848
private fun GuiGraphics.renderAltitudeScale(x: Int, y: Int) {
49-
val altitude: Double = computers.data.altitude
49+
val altitude: Double = computers.hudData.lerpedAltitude
5050

5151
val minY: Int = HudFrame.top
5252
val maxY: Int =
@@ -85,7 +85,7 @@ class AltitudeDisplay(computers: ComputerView) : Display(computers) {
8585

8686
if (FAConfig.display.showVerticalSpeed) {
8787
enableScissor(0, HudFrame.top, guiWidth(), HudFrame.bottom)
88-
fill(x - 3, y, x - 1, (y - 2 * (computers.data.velocity.y * 20)).toInt(), secondaryColor)
88+
fill(x - 3, y, x - 1, (y - 2 * (computers.hudData.lerpedVelocity.y * 20)).toInt(), secondaryColor)
8989
disableScissor()
9090
}
9191
}

0 commit comments

Comments
 (0)