Skip to content

Commit 5132a0a

Browse files
committed
improve speed thrust mode
Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
1 parent 971cd6b commit 5132a0a

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
lines changed

src/main/java/ru/octol1ttle/flightassistant/mixin/EntityInvoker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
@Mixin(Entity.class)
77
public interface EntityInvoker {
88
//? if >=1.21.2 {
9-
/*@org.spongepowered.asm.mixin.gen.Invoker
9+
/*@org.spongepowered.asm.mixin.gen.Invoker("isInvulnerableToBase)
1010
boolean invokeIsInvulnerableToBase(net.minecraft.world.damagesource.DamageSource damageSource);
1111
*///?}
1212
}

src/main/kotlin/ru/octol1ttle/flightassistant/api/autoflight/thrust/BuiltInThrustModes.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ data class SpeedThrustMode(val target: Int) : AutoFlightComputer.ThrustMode {
1313
val currentSpeed: Double = computers.data.forwardVelocity.length() * 20
1414
val acceleration: Double = computers.data.forwardAcceleration.length() * 20
1515

16-
val speedCorrection: Double = (target - currentSpeed) * FATickCounter.timePassed.pow(2)
17-
val accelerationDamping: Double = -acceleration * FATickCounter.timePassed.pow(4)
16+
val speedCorrection: Double = (target - currentSpeed) * FATickCounter.timePassed.pow(1.5f)
17+
val accelerationDamping: Double = -acceleration * FATickCounter.timePassed
1818
return ControlInput(
1919
(currentThrust + speedCorrection + accelerationDamping).toFloat().coerceIn(0.0f..1.0f),
2020
ControlInput.Priority.NORMAL,
@@ -25,6 +25,7 @@ data class SpeedThrustMode(val target: Int) : AutoFlightComputer.ThrustMode {
2525

2626
data class SpeedReferenceVerticalMode(val targetSpeed: Int) : AutoFlightComputer.VerticalMode {
2727
override fun getControlInput(computers: ComputerView): ControlInput {
28+
// TODO: find a way to fix jittering
2829
val range: Float = computers.thrust.getOptimumClimbPitch() - computers.thrust.getAltitudeHoldPitch()
2930
val currentPitch: Float = computers.data.pitch
3031
val currentSpeed: Double = computers.data.forwardVelocity.length() * 20

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,8 @@ class AirDataComputer(computers: ComputerView, private val mc: Minecraft) : Comp
8181
position = player.getPosition(partialTick)
8282
groundY = computeGroundLevel()
8383
velocity = player.getDeltaMovementLerped(partialTick)
84-
85-
val newForwardVelocity: Vec3 = computeForwardVelocity()
86-
forwardAcceleration = newForwardVelocity.subtract(forwardVelocity)
87-
forwardVelocity = newForwardVelocity
88-
84+
forwardVelocity = computeForwardVector(velocity)
85+
forwardAcceleration = computeForwardVector(player.deltaMovement.subtract(player.getDeltaMovementLerped(0.0f)))
8986
roll = degrees(atan2(-RenderMatrices.worldSpaceMatrix.m10(), RenderMatrices.worldSpaceMatrix.m11()))
9087
}
9188

@@ -126,10 +123,10 @@ class AirDataComputer(computers: ComputerView, private val mc: Minecraft) : Comp
126123
return result.location.y
127124
}
128125

129-
private fun computeForwardVelocity(): Vec3 {
126+
private fun computeForwardVector(vector: Vec3): Vec3 {
130127
val normalizedLookAngle: Vec3 = player.lookAngle.normalize()
131-
val normalizedVelocity: Vec3 = velocity.normalize()
132-
return velocity.scale(normalizedLookAngle.dot(normalizedVelocity).coerceAtLeast(0.0))
128+
val normalizedVector: Vec3 = vector.normalize()
129+
return vector.scale(normalizedLookAngle.dot(normalizedVector).coerceAtLeast(0.0))
133130
}
134131

135132
override fun reset() {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,5 @@ class FlightPlanComputer(computers: ComputerView) : Computer(computers) {
7474
CLIMB
7575
}
7676

77-
data class DepartureData(val coordinatesX: Int = 0, val coordinatesZ: Int = 0, val elevation: Int = 0, val takeoffThrust: Float = 0.0f, val minimumClimbSpeed: Int = 0)
77+
data class DepartureData(val coordinatesX: Int = 0, val coordinatesZ: Int = 0, val elevation: Int = 0, val takeoffThrust: Float = 1.0f, val minimumClimbSpeed: Int = 15)
7878
}

0 commit comments

Comments
 (0)