From 599ecae21f05918bbea4c688cb95c0d8c7d017c3 Mon Sep 17 00:00:00 2001 From: richard Date: Wed, 28 Oct 2026 22:06:50 +0100 Subject: [PATCH] feat(flight): add aspect ratio lift and altitude-hold trim - Derive lift slope and induced drag from each wing's aspect ratio, found by grouping connected wing blocks across short span gaps. - Give stabilizers and vertical wings their own parasitic drag from the stabilizerDrag config. - Replace designSpeed with a fixed lift constant and a liftScale multiplier. - Make auto trim hold the altitude the craft has when the pilot releases pitch, using nested altitude, climb and attitude loops. - Add /improvedaerodynamics (alias /aero) to list, read and set the main config values in game. --- .../lumareth/improvedAerodynamics/Config.java | 16 ++- .../improvedAerodynamics/ConfigCommands.java | 91 +++++++++++++++ .../ImprovedAerodynamics.java | 1 + .../flight/AeroState.java | 19 +-- .../flight/AeroSurface.java | 8 +- .../improvedAerodynamics/flight/AutoTrim.java | 81 ++++++++++--- .../flight/ImprovedAero.java | 31 +++-- .../flight/SurfaceType.java | 20 ++-- .../flight/WariumCapture.java | 2 +- .../flight/WingShape.java | 108 ++++++++++++++++++ 10 files changed, 329 insertions(+), 48 deletions(-) create mode 100644 src/main/java/dev/lumareth/improvedAerodynamics/ConfigCommands.java create mode 100644 src/main/java/dev/lumareth/improvedAerodynamics/flight/WingShape.java diff --git a/src/main/java/dev/lumareth/improvedAerodynamics/Config.java b/src/main/java/dev/lumareth/improvedAerodynamics/Config.java index cabcd2e..f3f060e 100644 --- a/src/main/java/dev/lumareth/improvedAerodynamics/Config.java +++ b/src/main/java/dev/lumareth/improvedAerodynamics/Config.java @@ -72,20 +72,26 @@ public final class Config { public static final ForgeConfigSpec.BooleanValue IMPROVED_FLIGHT_MODEL = BUILDER .comment("Replace Warium's lift and damping with a model based on each surface's angle of attack:", - "lift grows with the square of airspeed, surfaces stall one by one when their angle of attack gets", + "lift grows with the square of airspeed, the air pressure at the altitude and the wing's shape (long narrow", + "wings lift better), surfaces stall one by one when their angle of attack gets", "too high, and stalled surfaces stop damping rotation, which allows post-stall maneuvers with", "thrust vectoring. Changes how craft fly") .define("improvedFlightModel", false); - public static final ForgeConfigSpec.DoubleValue DESIGN_SPEED = BUILDER - .comment("Improved flight model: airspeed (blocks per second) at which a level wing makes the same lift as in Warium.", - "Slower flight needs a higher angle of attack, faster flight a lower one") - .defineInRange("designSpeed", 40.0D, 5.0D, 300.0D); + public static final ForgeConfigSpec.DoubleValue LIFT_SCALE = BUILDER + .comment("Improved flight model: multiplier for the lift of all surfaces (drag is unchanged). Raise it if a craft", + "cannot stay up at the speed it should fly at, lower it for craft that climb too easily") + .defineInRange("liftScale", 1.0D, 0.1D, 10.0D); public static final ForgeConfigSpec.DoubleValue STALL_ANGLE_SCALE = BUILDER .comment("Improved flight model: multiplier for the angle of attack at which surfaces stall") .defineInRange("stallAngleScale", 1.0D, 0.5D, 2.0D); + public static final ForgeConfigSpec.DoubleValue STABILIZER_DRAG = BUILDER + .comment("Improved flight model: parasitic drag coefficient of stabilizers and vertical wings. They stabilize", + "with lift, so this only costs speed. Wings use Warium's 1.0, which also stands in for fuselage drag") + .defineInRange("stabilizerDrag", 0.2D, 0.0D, 2.0D); + public static final ForgeConfigSpec.DoubleValue TRIM_AUTHORITY = BUILDER .comment("Auto trim: largest pitch input (fraction of full deflection) the trim may hold") .defineInRange("trimAuthority", 0.5D, 0.0D, 1.0D); diff --git a/src/main/java/dev/lumareth/improvedAerodynamics/ConfigCommands.java b/src/main/java/dev/lumareth/improvedAerodynamics/ConfigCommands.java new file mode 100644 index 0000000..582ed61 --- /dev/null +++ b/src/main/java/dev/lumareth/improvedAerodynamics/ConfigCommands.java @@ -0,0 +1,91 @@ +package dev.lumareth.improvedAerodynamics; + +import com.mojang.brigadier.arguments.ArgumentType; +import com.mojang.brigadier.arguments.BoolArgumentType; +import com.mojang.brigadier.arguments.DoubleArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.tree.LiteralCommandNode; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.network.chat.Component; +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.event.RegisterCommandsEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; + +import java.util.List; + +/** + * /improvedaerodynamics (or /aero) to read and change the most important server config values in game. + * {@code /aero} lists them, {@code /aero