Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
80bb63d44f | ||
|
|
3478a04885 | ||
|
|
23f0f91ede | ||
|
|
782df70a69 | ||
|
|
1be7e90ec2 | ||
|
|
2e75d956a0 | ||
|
|
9f10ff08ff | ||
|
|
2f4f90c773 | ||
|
|
d66e8a83d2 | ||
|
|
8bb2cfd859 | ||
|
|
d376a6b9fa | ||
|
|
da74c2950c | ||
|
|
70eb237d70 |
No files matched your search
+16
-2
@@ -58,6 +58,13 @@ repositories {
|
|||||||
includeGroup "maven.modrinth"
|
includeGroup "maven.modrinth"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
maven {
|
||||||
|
name = "AzureDoom Mods"
|
||||||
|
url = "https://maven.azuredoom.com/mods"
|
||||||
|
content {
|
||||||
|
includeGroup "mod.azure.azurelib"
|
||||||
|
}
|
||||||
|
}
|
||||||
// Warium VS is not on Modrinth, it is compiled against the jar in libs/
|
// Warium VS is not on Modrinth, it is compiled against the jar in libs/
|
||||||
flatDir {
|
flatDir {
|
||||||
dir 'libs'
|
dir 'libs'
|
||||||
@@ -73,9 +80,16 @@ dependencies {
|
|||||||
compileOnly files('libs/vs-core-api-1.1.0.jar', 'libs/vs-core-util-1.1.0.jar', 'libs/joml-primitives-1.10.0.jar')
|
compileOnly files('libs/vs-core-api-1.1.0.jar', 'libs/vs-core-util-1.1.0.jar', 'libs/joml-primitives-1.10.0.jar')
|
||||||
compileOnly 'org.jetbrains.kotlin:kotlin-stdlib:1.9.22'
|
compileOnly 'org.jetbrains.kotlin:kotlin-stdlib:1.9.22'
|
||||||
|
|
||||||
// Warium VS 1.1.6 and Futurism 0.0.4 (optional dependencies, the flight physics mixins only apply when they are present)
|
// Warium VS 1.1.7 and Futurism 0.0.4 (optional dependencies, the flight physics mixins only apply when they are present)
|
||||||
compileOnly fg.deobf("blank:WariumVS:1.1.6")
|
compileOnly fg.deobf("blank:WariumVS:1.1.7")
|
||||||
compileOnly fg.deobf("blank:futurism:0.0.4")
|
compileOnly fg.deobf("blank:futurism:0.0.4")
|
||||||
|
|
||||||
|
// GeckoLib 4.8.4, which Warium VS animates its control surfaces with (optional dependency, remapped, the surface animation mixin
|
||||||
|
// only applies when it and Warium VS are present)
|
||||||
|
compileOnly fg.deobf("maven.modrinth:geckolib:aC5KMoNg")
|
||||||
|
|
||||||
|
// AzureLib 3.2.7 for the animated block models (optional dependency, the common jar uses obfuscated names, so it is remapped)
|
||||||
|
compileOnly fg.deobf("mod.azure.azurelib:azurelib-common-${minecraft_version}:${azurelib_version}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -12,7 +12,8 @@ mapping_version=2023.09.03-1.20.1
|
|||||||
mod_id=improved_aerodynamics
|
mod_id=improved_aerodynamics
|
||||||
mod_name=VS: Improved Aerodynamics
|
mod_name=VS: Improved Aerodynamics
|
||||||
mod_license=MIT
|
mod_license=MIT
|
||||||
mod_version=0.3.0
|
mod_version=0.4.3
|
||||||
|
azurelib_version=3.2.7
|
||||||
mod_group_id=dev.lumareth.improvedaerodynamics
|
mod_group_id=dev.lumareth.improvedaerodynamics
|
||||||
mod_authors=Lumareth
|
mod_authors=Lumareth
|
||||||
mod_description=Valkyrien Skies addon that keeps terrain streaming ahead of fast ships and smooths out Warium flight physics, with an optional flight model with real stalls and auto trim.
|
mod_description=Valkyrien Skies addon that keeps terrain streaming ahead of fast ships and smooths out Warium flight physics, with an optional flight model with real stalls and auto trim.
|
||||||
Binary file not shown.
@@ -150,12 +150,163 @@ public final class Config {
|
|||||||
.comment("Flight computer (auto trim): below this airspeed (blocks per second) the computer holds its current output")
|
.comment("Flight computer (auto trim): below this airspeed (blocks per second) the computer holds its current output")
|
||||||
.defineInRange("trimMinSpeed", 10.0D, 0.0D, 100.0D);
|
.defineInRange("trimMinSpeed", 10.0D, 0.0D, 100.0D);
|
||||||
|
|
||||||
|
public static final ForgeConfigSpec.DoubleValue FLAP_TAKEOFF_DEGREES = BUILDER
|
||||||
|
.comment("Flaps: deflection in degrees of flaps at the takeoff setting. Flaps need the improved flight model")
|
||||||
|
.defineInRange("flapTakeoffDegrees", 15.0D, 0.0D, 60.0D);
|
||||||
|
|
||||||
|
public static final ForgeConfigSpec.DoubleValue FLAP_LANDING_DEGREES = BUILDER
|
||||||
|
.comment("Flaps: deflection in degrees of flaps at the landing setting")
|
||||||
|
.defineInRange("flapLandingDegrees", 35.0D, 0.0D, 60.0D);
|
||||||
|
|
||||||
|
public static final ForgeConfigSpec.DoubleValue FLAP_SLEW_DEGREES = BUILDER
|
||||||
|
.comment("Flaps: how fast they move, in degrees per second")
|
||||||
|
.defineInRange("flapSlewDegrees", 10.0D, 1.0D, 90.0D);
|
||||||
|
|
||||||
|
public static final ForgeConfigSpec.DoubleValue FLAP_TAKEOFF_MAX_SPEED = BUILDER
|
||||||
|
.comment("Flaps: airspeed in blocks per second above which the air pushes takeoff flaps back in, fully retracted at 25% more")
|
||||||
|
.defineInRange("flapTakeoffMaxSpeed", 45.0D, 1.0D, 1000.0D);
|
||||||
|
|
||||||
|
public static final ForgeConfigSpec.DoubleValue FLAP_LANDING_MAX_SPEED = BUILDER
|
||||||
|
.comment("Flaps: the same for the landing setting")
|
||||||
|
.defineInRange("flapLandingMaxSpeed", 35.0D, 1.0D, 1000.0D);
|
||||||
|
|
||||||
|
static {
|
||||||
|
BUILDER.pop();
|
||||||
|
BUILDER.comment("Vectored afterburner nozzle block").push("nozzle");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final ForgeConfigSpec.DoubleValue NOZZLE_MAX_DEFLECTION = BUILDER
|
||||||
|
.comment("Largest angle in degrees the nozzle can swing to either side")
|
||||||
|
.defineInRange("maxDeflectionDegrees", 20.0D, 1.0D, 45.0D);
|
||||||
|
|
||||||
|
public static final ForgeConfigSpec.DoubleValue NOZZLE_SLEW_RATE = BUILDER
|
||||||
|
.comment("Fastest the nozzle swings, in degrees per second, so it never snaps to a new angle")
|
||||||
|
.defineInRange("slewRateDegreesPerSecond", 90.0D, 5.0D, 720.0D);
|
||||||
|
|
||||||
|
public static final ForgeConfigSpec.DoubleValue AFTERBURNER_MIN_THROTTLE = BUILDER
|
||||||
|
.comment("Lowest throttle value on the vehicle control node (0 to 10) at which the afterburner key lights the",
|
||||||
|
"afterburner. It goes out by itself when the throttle falls below it")
|
||||||
|
.defineInRange("afterburnerMinThrottle", 8.0D, 0.0D, 10.0D);
|
||||||
|
|
||||||
|
public static final ForgeConfigSpec.ConfigValue<String> EXHAUST_STYLE = BUILDER
|
||||||
|
.comment("How every jet exhaust looks: Warium's jet exhaust and VTOL exhaust, Futurism's vectored afterburner and",
|
||||||
|
"this mod's nozzle. wariumvs for Warium's own effect entities, improved for the big flame, particles and",
|
||||||
|
"afterburner sound of this mod. Warium's engine sound is kept in both")
|
||||||
|
.defineInList("exhaustStyle", "improved", java.util.List.of("wariumvs", "improved"));
|
||||||
|
|
||||||
|
public static final ForgeConfigSpec.DoubleValue NOZZLE_YAW_MIX = BUILDER
|
||||||
|
.comment("How much of the yaw input goes into the nozzles' differential deflection. The nozzles are canted, so",
|
||||||
|
"deflecting them against each other pushes the tail sideways as well as rolling the craft, like on an",
|
||||||
|
"Su-57. 0 turns yaw vectoring off, a negative value turns it around")
|
||||||
|
.defineInRange("yawMix", 0.6D, -1.0D, 1.0D);
|
||||||
|
|
||||||
|
public static final ForgeConfigSpec.BooleanValue NOZZLE_LIGHT = BUILDER
|
||||||
|
.comment("The nozzle gives off light while its afterburner is lit")
|
||||||
|
.define("lightEnabled", true);
|
||||||
|
|
||||||
|
static {
|
||||||
|
BUILDER.pop();
|
||||||
|
BUILDER.comment("Cursor aim: the mouse moves a cursor on screen, a virtual pilot flies the control node's craft by it").push("cursor_aim");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final ForgeConfigSpec.BooleanValue CURSOR_AIM_ENABLED = BUILDER.comment("Whether pilots may use cursor aim on this server")
|
||||||
|
.define("enabled", true);
|
||||||
|
|
||||||
|
public static final ForgeConfigSpec.DoubleValue CURSOR_AIM_FULL_DEFLECTION_DEGREES = BUILDER.comment("Angle of the cursor from the gun reticle at which the virtual pilot turns as hard as it can: the maximum bank",
|
||||||
|
"sideways, the full pitch rate up or down. Closer than that it turns more gently, so the reticle settles onto",
|
||||||
|
"the cursor. How fast the craft can turn is worked out from the craft itself")
|
||||||
|
.defineInRange("fullDeflectionDegrees", 30.0, 5.0, 90.0);
|
||||||
|
|
||||||
|
public static final ForgeConfigSpec.DoubleValue CURSOR_AIM_DEADZONE_DEGREES = BUILDER.comment("Radius around the gun reticle in degrees inside which the pilot stops steering towards the cursor. The reticle",
|
||||||
|
"then settles this far from the cursor. Outside it the command grows from zero, there is no jump at the edge")
|
||||||
|
.defineInRange("deadzoneDegrees", 0.0, 0.0, 15.0);
|
||||||
|
|
||||||
|
public static final ForgeConfigSpec.DoubleValue CURSOR_AIM_MAX_ROLL_RATE_DEGREES = BUILDER.comment("Fastest roll in degrees per second the pilot asks for when it rolls to a bank angle")
|
||||||
|
.defineInRange("maxRollRateDegrees", 150.0, 10.0, 720.0);
|
||||||
|
|
||||||
|
public static final ForgeConfigSpec.DoubleValue CURSOR_AIM_MAX_BANK_DEGREES = BUILDER.comment("Bank angle the pilot rolls to when the cursor is at full sideways deflection, at most. Craft whose wings",
|
||||||
|
"cannot hold that bank in a level turn get less")
|
||||||
|
.defineInRange("maxBankDegrees", 70.0, 10.0, 90.0);
|
||||||
|
|
||||||
|
public static final ForgeConfigSpec.DoubleValue CURSOR_AIM_BANK_GAIN = BUILDER.comment("Roll rate in rad/s per radian of bank angle error, how eagerly the pilot rolls to the wanted bank and levels the wings")
|
||||||
|
.defineInRange("bankGain", 3.0, 0.2, 20.0);
|
||||||
|
|
||||||
|
public static final ForgeConfigSpec.DoubleValue CURSOR_AIM_RATE_GAIN = BUILDER.comment("How hard the pilot corrects its turn rate, in angular acceleration per rad/s of rate error. Lower is smoother,",
|
||||||
|
"higher follows the cursor tighter and can start to oscillate")
|
||||||
|
.defineInRange("rateGain", 5.0, 0.5, 40.0);
|
||||||
|
|
||||||
|
public static final ForgeConfigSpec.DoubleValue CURSOR_AIM_PUSH_FACTOR = BUILDER.comment("A cursor below the gun reticle pushes the nose down. This is how much of the pull rate that may be, since",
|
||||||
|
"negative g is harder on the craft and the pilot")
|
||||||
|
.defineInRange("pushFactor", 0.4, 0.0, 1.0);
|
||||||
|
|
||||||
|
public static final ForgeConfigSpec.DoubleValue CURSOR_AIM_REVERSE_TURN_DEGREES = BUILDER.comment("How far below the nose (wings level) the cursor has to be before the pilot rolls over and pulls towards it",
|
||||||
|
"instead of pushing the nose down. Less than that is flown with the elevators alone, like for a landing")
|
||||||
|
.defineInRange("reverseTurnDegrees", 40.0, 10.0, 135.0);
|
||||||
|
|
||||||
|
public static final ForgeConfigSpec.DoubleValue CURSOR_AIM_STALLED_PITCH_FACTOR = BUILDER.comment("Multiplier for the pitch rate the pilot asks for while the wings are stalled, so it does not keep pulling")
|
||||||
|
.defineInRange("stalledPitchFactor", 0.3, 0.0, 1.0);
|
||||||
|
|
||||||
|
public static final ForgeConfigSpec.DoubleValue CURSOR_AIM_MIN_SPEED = BUILDER.comment("Below this speed in blocks per second the pilot does not fly the craft: the cursor moves the elevators and",
|
||||||
|
"rudder directly instead, so they follow it while taxiing and rotating for takeoff")
|
||||||
|
.defineInRange("minSpeed", 15.0, 0.0, 200.0);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
BUILDER.pop();
|
BUILDER.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
static final ForgeConfigSpec SPEC = BUILDER.build();
|
static final ForgeConfigSpec SPEC = BUILDER.build();
|
||||||
|
|
||||||
|
private static final ForgeConfigSpec.Builder CLIENT_BUILDER = new ForgeConfigSpec.Builder();
|
||||||
|
|
||||||
|
public static final ForgeConfigSpec.BooleanValue NOZZLE_PARTICLES = CLIENT_BUILDER
|
||||||
|
.comment("Jet exhaust in the improved style: smoke at dry thrust and fire in afterburner")
|
||||||
|
.define("particlesEnabled", true);
|
||||||
|
|
||||||
|
public static final ForgeConfigSpec.BooleanValue NOZZLE_SOUND = CLIENT_BUILDER
|
||||||
|
.comment("Vectored afterburner nozzle: afterburner ignition and heavy afterburner sound")
|
||||||
|
.define("soundEnabled", true);
|
||||||
|
|
||||||
|
public static final ForgeConfigSpec.BooleanValue ANIMATE_SURFACES = CLIENT_BUILDER
|
||||||
|
.comment("Control surfaces and flaps visibly deflect by as much as the flight physics deflects them, instead of Warium's",
|
||||||
|
"fixed 20 degree steps. Needs physicsRateAerodynamics on the server")
|
||||||
|
.define("animateControlSurfaces", true);
|
||||||
|
|
||||||
|
static {
|
||||||
|
CLIENT_BUILDER.comment("Cursor aim, client side").push("cursor_aim");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final ForgeConfigSpec.DoubleValue CURSOR_AIM_LOOK_AHEAD = CLIENT_BUILDER.comment("How strongly the camera looks into the direction of the turn. 0 never moves it, 1 (100%) turns it quickly",
|
||||||
|
"to look where the cursor points. In between it follows more slowly")
|
||||||
|
.defineInRange("lookAhead", 0.0, 0.0, 1.0);
|
||||||
|
|
||||||
|
public static final ForgeConfigSpec.DoubleValue CURSOR_AIM_MOUSE_SENSITIVITY = CLIENT_BUILDER.comment("Multiplier for how far the mouse moves the cursor (or the camera while the free look key is held)")
|
||||||
|
.defineInRange("mouseSensitivity", 1.0, 0.05, 10.0);
|
||||||
|
|
||||||
|
public static final ForgeConfigSpec.DoubleValue CURSOR_AIM_SPRING_BACK_SECONDS = CLIENT_BUILDER.comment("The cursor drifts to the gun reticle with this time constant in seconds, which ends the turn by itself.",
|
||||||
|
"0, the default, keeps it where you put it in the world, so the craft turns until the reticle is on it")
|
||||||
|
.defineInRange("springBackSeconds", 0.0, 0.0, 10.0);
|
||||||
|
|
||||||
|
public static final ForgeConfigSpec.DoubleValue CURSOR_AIM_MAX_ANGLE_DEGREES = CLIENT_BUILDER.comment("Furthest the cursor can go from the gun reticle, 135 is a 270 degree cone")
|
||||||
|
.defineInRange("maxCursorAngleDegrees", 135.0, 10.0, 180.0);
|
||||||
|
|
||||||
|
public static final ForgeConfigSpec.DoubleValue CURSOR_AIM_ZOOM_STEP = CLIENT_BUILDER.comment("Blocks the camera moves per mouse wheel notch")
|
||||||
|
.defineInRange("zoomStep", 2.0, 0.1, 20.0);
|
||||||
|
|
||||||
|
public static final ForgeConfigSpec.DoubleValue CURSOR_AIM_ZOOM_MAX = CLIENT_BUILDER.comment("Furthest the camera can be pulled back from its normal distance, in blocks")
|
||||||
|
.defineInRange("zoomMax", 80.0, 0.0, 500.0);
|
||||||
|
|
||||||
|
public static final ForgeConfigSpec.DoubleValue CURSOR_AIM_MARKER_SIZE = CLIENT_BUILDER.comment("Radius of the cursor ring on screen")
|
||||||
|
.defineInRange("markerSize", 0.04, 0.01, 0.3);
|
||||||
|
|
||||||
|
public static final ForgeConfigSpec.BooleanValue CURSOR_AIM_SHOW_RETICLE = CLIENT_BUILDER.comment("Draw a small cross where the gun reticle points, the zero of the cursor, so you can see it when the camera looks away")
|
||||||
|
.define("showReticle", true);
|
||||||
|
|
||||||
|
static {
|
||||||
|
CLIENT_BUILDER.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
static final ForgeConfigSpec CLIENT_SPEC = CLIENT_BUILDER.build();
|
||||||
|
|
||||||
private Config() {
|
private Config() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,11 +3,14 @@ package dev.lumareth.improvedAerodynamics;
|
|||||||
import com.mojang.brigadier.arguments.ArgumentType;
|
import com.mojang.brigadier.arguments.ArgumentType;
|
||||||
import com.mojang.brigadier.arguments.BoolArgumentType;
|
import com.mojang.brigadier.arguments.BoolArgumentType;
|
||||||
import com.mojang.brigadier.arguments.DoubleArgumentType;
|
import com.mojang.brigadier.arguments.DoubleArgumentType;
|
||||||
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||||
|
import dev.lumareth.improvedAerodynamics.exhaust.NozzleCommands;
|
||||||
import dev.lumareth.improvedAerodynamics.flight.ControlMode;
|
import dev.lumareth.improvedAerodynamics.flight.ControlMode;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.commands.Commands;
|
import net.minecraft.commands.Commands;
|
||||||
|
import net.minecraft.commands.SharedSuggestionProvider;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraftforge.common.ForgeConfigSpec;
|
import net.minecraftforge.common.ForgeConfigSpec;
|
||||||
@@ -24,7 +27,11 @@ import java.util.List;
|
|||||||
* All of them are read live, so changes apply immediately.
|
* All of them are read live, so changes apply immediately.
|
||||||
*/
|
*/
|
||||||
public final class ConfigCommands {
|
public final class ConfigCommands {
|
||||||
private record Option<T>(String name, ForgeConfigSpec.ConfigValue<T> value, ArgumentType<T> argument, Class<T> type) {
|
private record Option<T>(String name, ForgeConfigSpec.ConfigValue<T> value, ArgumentType<T> argument, Class<T> type,
|
||||||
|
List<String> choices) {
|
||||||
|
Option(String name, ForgeConfigSpec.ConfigValue<T> value, ArgumentType<T> argument, Class<T> type) {
|
||||||
|
this(name, value, argument, type, List.of());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final List<Option<?>> OPTIONS = List.of(
|
private static final List<Option<?>> OPTIONS = List.of(
|
||||||
@@ -50,6 +57,17 @@ public final class ConfigCommands {
|
|||||||
new Option<>("flight_computer_actuator_rate", Config.FBW_ACTUATOR_RATE, DoubleArgumentType.doubleArg(), Double.class),
|
new Option<>("flight_computer_actuator_rate", Config.FBW_ACTUATOR_RATE, DoubleArgumentType.doubleArg(), Double.class),
|
||||||
new Option<>("trim_min_speed", Config.TRIM_MIN_SPEED, DoubleArgumentType.doubleArg(), Double.class),
|
new Option<>("trim_min_speed", Config.TRIM_MIN_SPEED, DoubleArgumentType.doubleArg(), Double.class),
|
||||||
new Option<>("air_placeholder", Config.ENABLE_AIR_PLACEHOLDER, BoolArgumentType.bool(), Boolean.class),
|
new Option<>("air_placeholder", Config.ENABLE_AIR_PLACEHOLDER, BoolArgumentType.bool(), Boolean.class),
|
||||||
|
new Option<>("nozzle_max_deflection", Config.NOZZLE_MAX_DEFLECTION, DoubleArgumentType.doubleArg(), Double.class),
|
||||||
|
new Option<>("nozzle_slew_rate", Config.NOZZLE_SLEW_RATE, DoubleArgumentType.doubleArg(), Double.class),
|
||||||
|
new Option<>("afterburner_min_throttle", Config.AFTERBURNER_MIN_THROTTLE, DoubleArgumentType.doubleArg(), Double.class),
|
||||||
|
new Option<>("exhaust_style", Config.EXHAUST_STYLE, StringArgumentType.word(), String.class, List.of("wariumvs", "improved")),
|
||||||
|
new Option<>("nozzle_yaw_mix", Config.NOZZLE_YAW_MIX, DoubleArgumentType.doubleArg(), Double.class),
|
||||||
|
new Option<>("nozzle_light", Config.NOZZLE_LIGHT, BoolArgumentType.bool(), Boolean.class),
|
||||||
|
new Option<>("flap_takeoff_degrees", Config.FLAP_TAKEOFF_DEGREES, DoubleArgumentType.doubleArg(), Double.class),
|
||||||
|
new Option<>("flap_landing_degrees", Config.FLAP_LANDING_DEGREES, DoubleArgumentType.doubleArg(), Double.class),
|
||||||
|
new Option<>("flap_slew_degrees", Config.FLAP_SLEW_DEGREES, DoubleArgumentType.doubleArg(), Double.class),
|
||||||
|
new Option<>("flap_takeoff_max_speed", Config.FLAP_TAKEOFF_MAX_SPEED, DoubleArgumentType.doubleArg(), Double.class),
|
||||||
|
new Option<>("flap_landing_max_speed", Config.FLAP_LANDING_MAX_SPEED, DoubleArgumentType.doubleArg(), Double.class),
|
||||||
new Option<>("lookahead_seconds", Config.LOOKAHEAD_SECONDS, DoubleArgumentType.doubleArg(), Double.class));
|
new Option<>("lookahead_seconds", Config.LOOKAHEAD_SECONDS, DoubleArgumentType.doubleArg(), Double.class));
|
||||||
|
|
||||||
private ConfigCommands() {
|
private ConfigCommands() {
|
||||||
@@ -72,6 +90,8 @@ public final class ConfigCommands {
|
|||||||
for (Option<?> option : OPTIONS) {
|
for (Option<?> option : OPTIONS) {
|
||||||
root.then(optionNode(option).requires(ConfigCommands::mayUse));
|
root.then(optionNode(option).requires(ConfigCommands::mayUse));
|
||||||
}
|
}
|
||||||
|
root.then(SeedgenCommands.node().requires(ConfigCommands::mayUse));
|
||||||
|
root.then(NozzleCommands.node().requires(ConfigCommands::mayUse));
|
||||||
root.then(controlsNode());
|
root.then(controlsNode());
|
||||||
LiteralCommandNode<CommandSourceStack> node = event.getDispatcher().register(root);
|
LiteralCommandNode<CommandSourceStack> node = event.getDispatcher().register(root);
|
||||||
event.getDispatcher().register(Commands.literal("aero")
|
event.getDispatcher().register(Commands.literal("aero")
|
||||||
@@ -108,10 +128,12 @@ public final class ConfigCommands {
|
|||||||
private static <T> LiteralArgumentBuilder<CommandSourceStack> optionNode(Option<T> option) {
|
private static <T> LiteralArgumentBuilder<CommandSourceStack> optionNode(Option<T> option) {
|
||||||
return Commands.literal(option.name())
|
return Commands.literal(option.name())
|
||||||
.executes(context -> {
|
.executes(context -> {
|
||||||
context.getSource().sendSuccess(() -> Component.literal(option.name() + " = " + option.value().get()), false);
|
context.getSource().sendSuccess(() -> Component.literal(option.name() + " = " + option.value().get()
|
||||||
|
+ (option.choices().isEmpty() ? "" : " (" + String.join(" or ", option.choices()) + ")")), false);
|
||||||
return 1;
|
return 1;
|
||||||
})
|
})
|
||||||
.then(Commands.argument("value", option.argument())
|
.then(Commands.argument("value", option.argument())
|
||||||
|
.suggests((context, builder) -> SharedSuggestionProvider.suggest(option.choices(), builder))
|
||||||
.executes(context -> set(context.getSource(), option, context.getArgument("value", option.type()))));
|
.executes(context -> set(context.getSource(), option, context.getArgument("value", option.type()))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,7 +143,8 @@ public final class ConfigCommands {
|
|||||||
ForgeConfigSpec.Range<?> range = spec.getRange();
|
ForgeConfigSpec.Range<?> range = spec.getRange();
|
||||||
source.sendFailure(Component.literal(range != null
|
source.sendFailure(Component.literal(range != null
|
||||||
? option.name() + " must be between " + range.getMin() + " and " + range.getMax()
|
? option.name() + " must be between " + range.getMin() + " and " + range.getMax()
|
||||||
: "Invalid value for " + option.name()));
|
: option.choices().isEmpty() ? "Invalid value for " + option.name()
|
||||||
|
: option.name() + " must be " + String.join(" or ", option.choices())));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
option.value().set(newValue);
|
option.value().set(newValue);
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package dev.lumareth.improvedAerodynamics;
|
package dev.lumareth.improvedAerodynamics;
|
||||||
|
|
||||||
import com.mojang.logging.LogUtils;
|
import com.mojang.logging.LogUtils;
|
||||||
import dev.lumareth.improvedAerodynamics.client.aim.CursorAimClientConfig;
|
|
||||||
import dev.lumareth.improvedAerodynamics.client.pipper.PipperConfig;
|
import dev.lumareth.improvedAerodynamics.client.pipper.PipperConfig;
|
||||||
import dev.lumareth.improvedAerodynamics.flight.CursorAimConfig;
|
import dev.lumareth.improvedAerodynamics.exhaust.ExhaustSync;
|
||||||
|
import dev.lumareth.improvedAerodynamics.exhaust.NozzleContent;
|
||||||
import dev.lumareth.improvedAerodynamics.flight.PhysicsBridge;
|
import dev.lumareth.improvedAerodynamics.flight.PhysicsBridge;
|
||||||
import dev.lumareth.improvedAerodynamics.network.Network;
|
import dev.lumareth.improvedAerodynamics.network.Network;
|
||||||
import dev.lumareth.improvedAerodynamics.terrain.LookaheadLoader;
|
import dev.lumareth.improvedAerodynamics.terrain.LookaheadLoader;
|
||||||
@@ -11,6 +11,7 @@ import net.minecraftforge.common.MinecraftForge;
|
|||||||
import net.minecraftforge.fml.ModLoadingContext;
|
import net.minecraftforge.fml.ModLoadingContext;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
import net.minecraftforge.fml.config.ModConfig;
|
import net.minecraftforge.fml.config.ModConfig;
|
||||||
|
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
@Mod(ImprovedAerodynamics.MOD_ID)
|
@Mod(ImprovedAerodynamics.MOD_ID)
|
||||||
@@ -23,11 +24,15 @@ public class ImprovedAerodynamics {
|
|||||||
MinecraftForge.EVENT_BUS.register(LookaheadLoader.class);
|
MinecraftForge.EVENT_BUS.register(LookaheadLoader.class);
|
||||||
MinecraftForge.EVENT_BUS.register(PhysicsBridge.class);
|
MinecraftForge.EVENT_BUS.register(PhysicsBridge.class);
|
||||||
MinecraftForge.EVENT_BUS.register(ConfigCommands.class);
|
MinecraftForge.EVENT_BUS.register(ConfigCommands.class);
|
||||||
|
MinecraftForge.EVENT_BUS.register(ExhaustSync.class);
|
||||||
MinecraftForge.EVENT_BUS.register(dev.lumareth.improvedAerodynamics.flight.ControlMode.class);
|
MinecraftForge.EVENT_BUS.register(dev.lumareth.improvedAerodynamics.flight.ControlMode.class);
|
||||||
|
MinecraftForge.EVENT_BUS.register(dev.lumareth.improvedAerodynamics.flight.FlapInteraction.class);
|
||||||
|
MinecraftForge.EVENT_BUS.register(dev.lumareth.improvedAerodynamics.flight.DeflectionSync.class);
|
||||||
ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, Config.SPEC);
|
ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, Config.SPEC);
|
||||||
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, PipperConfig.SPEC);
|
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, Config.CLIENT_SPEC);
|
||||||
ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, CursorAimConfig.SPEC, "improved_aerodynamics-cursor-aim.toml");
|
// Own file name: the default one is taken by Config.CLIENT_SPEC
|
||||||
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, CursorAimClientConfig.SPEC, "improved_aerodynamics-cursor-aim-client.toml");
|
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, PipperConfig.SPEC, "improved_aerodynamics-pipper-client.toml");
|
||||||
|
NozzleContent.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||||
Network.register();
|
Network.register();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
import dev.lumareth.improvedAerodynamics.terrain.AirCeiling;
|
||||||
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
|
import net.minecraft.commands.Commands;
|
||||||
|
import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.resources.ResourceKey;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.world.level.ChunkPos;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
|
||||||
|
import java.util.OptionalInt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@code /aero seedgen}: measures where the air starts in one real chunk, for worlds where the air placeholder's
|
||||||
|
* noise based surface estimate does not work (flat worlds and the like).
|
||||||
|
* {@code set <x> <y> <z>} picks the chunk containing that position in the current dimension, {@code start} reads its
|
||||||
|
* blocks and saves the height above which only air remains, {@code clear} forgets it again.
|
||||||
|
* Pick a chunk that is as high as the tallest terrain you want ships to ignore, and has no builds in it.
|
||||||
|
*/
|
||||||
|
final class SeedgenCommands {
|
||||||
|
private record Selection(ResourceKey<Level> dimension, ChunkPos chunk) {
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Selection selection;
|
||||||
|
|
||||||
|
private SeedgenCommands() {
|
||||||
|
}
|
||||||
|
|
||||||
|
static LiteralArgumentBuilder<CommandSourceStack> node() {
|
||||||
|
return Commands.literal("seedgen")
|
||||||
|
.executes(context -> status(context.getSource()))
|
||||||
|
.then(Commands.literal("set")
|
||||||
|
.then(Commands.argument("pos", BlockPosArgument.blockPos())
|
||||||
|
.executes(context -> set(context.getSource(), BlockPosArgument.getBlockPos(context, "pos")))))
|
||||||
|
.then(Commands.literal("start").executes(context -> start(context.getSource())))
|
||||||
|
.then(Commands.literal("clear").executes(context -> clear(context.getSource())));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int set(CommandSourceStack source, BlockPos pos) {
|
||||||
|
ChunkPos chunk = new ChunkPos(pos);
|
||||||
|
selection = new Selection(source.getLevel().dimension(), chunk);
|
||||||
|
source.sendSuccess(() -> Component.literal("Chunk " + chunk.x + " " + chunk.z + " in "
|
||||||
|
+ source.getLevel().dimension().location() + " selected, run /aero seedgen start to analyze it"), true);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int start(CommandSourceStack source) {
|
||||||
|
if (selection == null) {
|
||||||
|
source.sendFailure(Component.literal("No chunk selected, use /aero seedgen set <x> <y> <z> first"));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
ServerLevel level = source.getServer().getLevel(selection.dimension());
|
||||||
|
if (level == null) {
|
||||||
|
source.sendFailure(Component.literal("Dimension " + selection.dimension().location() + " is not loaded"));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
ChunkPos chunk = selection.chunk();
|
||||||
|
AirCeiling.Analysis analysis = AirCeiling.analyze(level, chunk);
|
||||||
|
if (!analysis.complete()) {
|
||||||
|
source.sendFailure(Component.literal("Chunk " + chunk.x + " " + chunk.z + " still has blocks at y="
|
||||||
|
+ analysis.highestSolid() + ", the top of what is read (" + AirCeiling.SCAN_MIN_Y + " to "
|
||||||
|
+ AirCeiling.SCAN_MAX_Y + "), so the air may start higher. Pick a different chunk"));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
AirCeiling.get(level).set(level.dimension(), analysis.airHeight());
|
||||||
|
source.sendSuccess(() -> Component.literal("Only air above y=" + analysis.highestSolid() + " in chunk " + chunk.x + " "
|
||||||
|
+ chunk.z + ", saved y=" + analysis.airHeight() + " for " + level.dimension().location()
|
||||||
|
+ ". The air placeholder hands VS air from there up" + (Config.ENABLE_AIR_PLACEHOLDER.get() ? ""
|
||||||
|
: " (turn it on with /aero air_placeholder true)")), true);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int clear(CommandSourceStack source) {
|
||||||
|
ServerLevel level = source.getLevel();
|
||||||
|
boolean removed = AirCeiling.get(level).clear(level.dimension());
|
||||||
|
source.sendSuccess(() -> Component.literal(removed ? "Measured air height of " + level.dimension().location()
|
||||||
|
+ " removed, the placeholder estimates it from world generation again"
|
||||||
|
: "No measured air height for " + level.dimension().location()), true);
|
||||||
|
return removed ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int status(CommandSourceStack source) {
|
||||||
|
ServerLevel level = source.getLevel();
|
||||||
|
OptionalInt height = AirCeiling.get(level).ceiling(level.dimension());
|
||||||
|
String selected = selection != null ? "chunk " + selection.chunk().x + " " + selection.chunk().z + " in "
|
||||||
|
+ selection.dimension().location() : "none";
|
||||||
|
source.sendSuccess(() -> Component.literal("Selected: " + selected + "\nMeasured air height in "
|
||||||
|
+ level.dimension().location() + ": " + (height.isPresent() ? "y=" + height.getAsInt() : "none, estimated from world generation")), false);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,9 @@ package dev.lumareth.improvedAerodynamics.client;
|
|||||||
|
|
||||||
import com.mojang.blaze3d.platform.InputConstants;
|
import com.mojang.blaze3d.platform.InputConstants;
|
||||||
import dev.lumareth.improvedAerodynamics.ImprovedAerodynamics;
|
import dev.lumareth.improvedAerodynamics.ImprovedAerodynamics;
|
||||||
|
import dev.lumareth.improvedAerodynamics.network.FlapPacket;
|
||||||
import dev.lumareth.improvedAerodynamics.network.Network;
|
import dev.lumareth.improvedAerodynamics.network.Network;
|
||||||
|
import dev.lumareth.improvedAerodynamics.network.ToggleAfterburnerPacket;
|
||||||
import dev.lumareth.improvedAerodynamics.network.ToggleAutoTrimPacket;
|
import dev.lumareth.improvedAerodynamics.network.ToggleAutoTrimPacket;
|
||||||
import net.minecraft.client.KeyMapping;
|
import net.minecraft.client.KeyMapping;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
@@ -18,6 +20,15 @@ public final class KeyBindings {
|
|||||||
public static final KeyMapping TOGGLE_AUTO_TRIM = new KeyMapping("key.improved_aerodynamics.toggle_auto_trim",
|
public static final KeyMapping TOGGLE_AUTO_TRIM = new KeyMapping("key.improved_aerodynamics.toggle_auto_trim",
|
||||||
KeyConflictContext.IN_GAME, InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_J, "key.categories.improved_aerodynamics");
|
KeyConflictContext.IN_GAME, InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_J, "key.categories.improved_aerodynamics");
|
||||||
|
|
||||||
|
public static final KeyMapping TOGGLE_AFTERBURNER = new KeyMapping("key.improved_aerodynamics.toggle_afterburner",
|
||||||
|
KeyConflictContext.IN_GAME, InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_K, "key.categories.improved_aerodynamics");
|
||||||
|
|
||||||
|
public static final KeyMapping FLAPS_DOWN = new KeyMapping("key.improved_aerodynamics.flaps_down",
|
||||||
|
KeyConflictContext.IN_GAME, InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_G, "key.categories.improved_aerodynamics");
|
||||||
|
|
||||||
|
public static final KeyMapping FLAPS_UP = new KeyMapping("key.improved_aerodynamics.flaps_up",
|
||||||
|
KeyConflictContext.IN_GAME, InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_H, "key.categories.improved_aerodynamics");
|
||||||
|
|
||||||
private KeyBindings() {
|
private KeyBindings() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,6 +40,9 @@ public final class KeyBindings {
|
|||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onRegisterKeyMappings(RegisterKeyMappingsEvent event) {
|
public static void onRegisterKeyMappings(RegisterKeyMappingsEvent event) {
|
||||||
event.register(TOGGLE_AUTO_TRIM);
|
event.register(TOGGLE_AUTO_TRIM);
|
||||||
|
event.register(TOGGLE_AFTERBURNER);
|
||||||
|
event.register(FLAPS_DOWN);
|
||||||
|
event.register(FLAPS_UP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,6 +64,25 @@ public final class KeyBindings {
|
|||||||
Network.CHANNEL.sendToServer(new ToggleAutoTrimPacket());
|
Network.CHANNEL.sendToServer(new ToggleAutoTrimPacket());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
while (TOGGLE_AFTERBURNER.consumeClick()) {
|
||||||
|
if (minecraft.player != null && minecraft.player.getVehicle() != null && minecraft.getConnection() != null
|
||||||
|
&& Network.CHANNEL.isRemotePresent(minecraft.getConnection().getConnection())) {
|
||||||
|
Network.CHANNEL.sendToServer(new ToggleAfterburnerPacket());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (FLAPS_DOWN.consumeClick()) {
|
||||||
|
sendFlaps(minecraft, true);
|
||||||
|
}
|
||||||
|
while (FLAPS_UP.consumeClick()) {
|
||||||
|
sendFlaps(minecraft, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void sendFlaps(Minecraft minecraft, boolean extend) {
|
||||||
|
if (minecraft.player != null && minecraft.player.getVehicle() != null && minecraft.getConnection() != null
|
||||||
|
&& Network.CHANNEL.isRemotePresent(minecraft.getConnection().getConnection())) {
|
||||||
|
Network.CHANNEL.sendToServer(new FlapPacket(extend));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package dev.lumareth.improvedAerodynamics.client.aim;
|
package dev.lumareth.improvedAerodynamics.client.aim;
|
||||||
|
|
||||||
|
import dev.lumareth.improvedAerodynamics.Config;
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
import com.mojang.blaze3d.vertex.BufferBuilder;
|
import com.mojang.blaze3d.vertex.BufferBuilder;
|
||||||
import com.mojang.blaze3d.vertex.BufferUploader;
|
import com.mojang.blaze3d.vertex.BufferUploader;
|
||||||
@@ -32,6 +33,7 @@ import net.minecraftforge.fml.ModList;
|
|||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
import net.minecraftforge.fml.util.ObfuscationReflectionHelper;
|
import net.minecraftforge.fml.util.ObfuscationReflectionHelper;
|
||||||
import org.joml.Matrix4f;
|
import org.joml.Matrix4f;
|
||||||
|
import org.joml.primitives.AABBdc;
|
||||||
import org.joml.Quaterniondc;
|
import org.joml.Quaterniondc;
|
||||||
import org.joml.Vector3d;
|
import org.joml.Vector3d;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
@@ -44,9 +46,10 @@ import java.lang.reflect.Method;
|
|||||||
/**
|
/**
|
||||||
* Cursor aim, the client side. While it is on:
|
* Cursor aim, the client side. While it is on:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>the mouse moves a cursor instead of the camera. The cursor is a direction relative to the gun reticle (the
|
* <li>the mouse moves a cursor instead of the camera. The cursor is a fixed direction in the world: the craft
|
||||||
* craft's boresight), at most {@code maxCursorAngleDegrees} away from it, and springs back to it when the mouse
|
* turning does not drag it along, so the virtual pilot on the server steers until the gun reticle (the craft's
|
||||||
* rests. It is sent to the server every tick, where a virtual pilot flies the craft by it;</li>
|
* boresight) sits on the cursor again. It is kept at most {@code maxCursorAngleDegrees} from the reticle and, if
|
||||||
|
* spring back is set, drifts back to it. Every tick it is sent to the server as an offset from the reticle;</li>
|
||||||
* <li>the camera is a chase view, looking along the reticle, or, with look ahead, towards the cursor;</li>
|
* <li>the camera is a chase view, looking along the reticle, or, with look ahead, towards the cursor;</li>
|
||||||
* <li>holding the free look key moves the camera instead of the cursor, it eases back when released;</li>
|
* <li>holding the free look key moves the camera instead of the cursor, it eases back when released;</li>
|
||||||
* <li>the mouse wheel changes how far the camera is behind the craft.</li>
|
* <li>the mouse wheel changes how far the camera is behind the craft.</li>
|
||||||
@@ -62,16 +65,23 @@ public final class CursorAimClient {
|
|||||||
private static final float MARKER_DISTANCE = 2.0F;
|
private static final float MARKER_DISTANCE = 2.0F;
|
||||||
private static final double LOOK_AHEAD_RATE = 6.0;
|
private static final double LOOK_AHEAD_RATE = 6.0;
|
||||||
private static final double FREE_LOOK_RETURN_RATE = 10.0;
|
private static final double FREE_LOOK_RETURN_RATE = 10.0;
|
||||||
|
// Blocks under the craft's bounding box that count as still on the ground, and how long it has to be off it
|
||||||
|
private static final double GROUND_CLEARANCE = 1.5;
|
||||||
|
private static final int AIRBORNE_TICKS = 20;
|
||||||
|
|
||||||
private static boolean active;
|
private static boolean active;
|
||||||
// Chosen with /aero controls, told by the server
|
// Chosen with /aero controls, told by the server
|
||||||
private static boolean cursorAimMode;
|
private static boolean cursorAimMode;
|
||||||
// Cursor as components along the craft's forward (gun reticle), right and up axes
|
// Cursor as a world direction, null until the first frame puts it on the reticle
|
||||||
|
private static Vector3d cursorWorld;
|
||||||
|
// The same cursor as components along the craft's forward (gun reticle), right and up axes, as of the last update
|
||||||
private static double cf = 1.0;
|
private static double cf = 1.0;
|
||||||
private static double cr;
|
private static double cr;
|
||||||
private static double cu;
|
private static double cu;
|
||||||
// Camera direction in ship space and the free look offset on top of it, degrees
|
// Camera direction in ship space and the free look offset on top of it, degrees
|
||||||
private static double[] cameraDirection;
|
private static double[] cameraDirection;
|
||||||
|
// Client ticks the craft has been off the ground, up to AIRBORNE_TICKS
|
||||||
|
private static int airborneTicks;
|
||||||
private static double offsetYaw;
|
private static double offsetYaw;
|
||||||
private static double offsetPitch;
|
private static double offsetPitch;
|
||||||
// Rotation the player was given last frame, to see what the mouse did since
|
// Rotation the player was given last frame, to see what the mouse did since
|
||||||
@@ -109,9 +119,91 @@ public final class CursorAimClient {
|
|||||||
deactivate(minecraft);
|
deactivate(minecraft);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// The craft has turned since the last frame: the cursor stays put in the world, its offset changes
|
||||||
|
Entity seat = AimSeat.seatOf(player);
|
||||||
|
AimBasis basis = minecraft.level != null ? AimBasis.of(minecraft.level, seat.blockPosition()) : null;
|
||||||
|
Quaterniondc rotation = basis != null ? shipRotation(minecraft.level, seat, false) : null;
|
||||||
|
if (rotation != null) {
|
||||||
|
cursorFromWorld(basis, rotation);
|
||||||
|
}
|
||||||
|
updateAirborne(minecraft.level, seat);
|
||||||
send(minecraft, true);
|
send(minecraft, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the craft is off the ground, for look ahead: on the ground (and for a moment after leaving it) the camera
|
||||||
|
* stays behind the reticle, so pulling the nose up to take off does not swing it down under the craft.
|
||||||
|
*/
|
||||||
|
private static void updateAirborne(ClientLevel level, Entity seat) {
|
||||||
|
Ship ship = VSGameUtilsKt.getLoadedShipManagingPos(level, BlockPos.containing(seat.getX(), seat.getY(), seat.getZ()));
|
||||||
|
if (ship == null || onGround(level, ship.getWorldAABB())) {
|
||||||
|
airborneTicks = 0;
|
||||||
|
} else if (airborneTicks < AIRBORNE_TICKS) {
|
||||||
|
airborneTicks++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether there is solid ground right under the craft: any block with a collision shape in a layer just below the
|
||||||
|
* bottom of its world bounding box. The craft's own blocks are not in the world, so they never count.
|
||||||
|
*/
|
||||||
|
private static boolean onGround(ClientLevel level, AABBdc box) {
|
||||||
|
int minX = Mth.floor(box.minX());
|
||||||
|
int maxX = Mth.floor(box.maxX());
|
||||||
|
int minZ = Mth.floor(box.minZ());
|
||||||
|
int maxZ = Mth.floor(box.maxZ());
|
||||||
|
int fromY = Mth.floor(box.minY() - GROUND_CLEARANCE);
|
||||||
|
int toY = Mth.floor(box.minY() + 0.5);
|
||||||
|
// At most about 16 x 16 columns, a big craft is sampled on a coarser grid
|
||||||
|
int stepX = Math.max(1, (maxX - minX) / 16);
|
||||||
|
int stepZ = Math.max(1, (maxZ - minZ) / 16);
|
||||||
|
BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos();
|
||||||
|
for (int x = minX; x <= maxX; x += stepX) {
|
||||||
|
for (int z = minZ; z <= maxZ; z += stepZ) {
|
||||||
|
for (int y = fromY; y <= toY; y++) {
|
||||||
|
pos.set(x, y, z);
|
||||||
|
if (!level.getBlockState(pos).getCollisionShape(level, pos).isEmpty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Rotation of the ship the seat is on, its render transform when drawing, null if it is not on a ship. */
|
||||||
|
private static Quaterniondc shipRotation(ClientLevel level, Entity seat, boolean render) {
|
||||||
|
Ship ship = VSGameUtilsKt.getLoadedShipManagingPos(level, BlockPos.containing(seat.getX(), seat.getY(), seat.getZ()));
|
||||||
|
if (ship == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return render && ship instanceof ClientShip clientShip
|
||||||
|
? clientShip.getRenderTransform().getShipToWorldRotation() : ship.getTransform().getShipToWorldRotation();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sets the cursor's components from its world direction, putting it on the reticle the first time. */
|
||||||
|
private static void cursorFromWorld(AimBasis basis, Quaterniondc rotation) {
|
||||||
|
if (cursorWorld == null) {
|
||||||
|
double[] forward = basis.forward();
|
||||||
|
cursorWorld = rotation.transform(new Vector3d(forward[0], forward[1], forward[2]));
|
||||||
|
}
|
||||||
|
Vector3d ship = rotation.transformInverse(cursorWorld, new Vector3d());
|
||||||
|
double[] f = basis.forward();
|
||||||
|
double[] r = basis.right();
|
||||||
|
double[] u = basis.up();
|
||||||
|
cf = ship.x * f[0] + ship.y * f[1] + ship.z * f[2];
|
||||||
|
cr = ship.x * r[0] + ship.y * r[1] + ship.z * r[2];
|
||||||
|
cu = ship.x * u[0] + ship.y * u[1] + ship.z * u[2];
|
||||||
|
normalizeCursor();
|
||||||
|
limitCursor();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Stores the cursor's components back as its world direction. */
|
||||||
|
private static void cursorToWorld(AimBasis basis, Quaterniondc rotation) {
|
||||||
|
double[] ship = basis.toShip(cf, cr, cu);
|
||||||
|
cursorWorld = rotation.transform(new Vector3d(ship[0], ship[1], ship[2]));
|
||||||
|
}
|
||||||
|
|
||||||
/** Called when the server tells the client how its player flies. */
|
/** Called when the server tells the client how its player flies. */
|
||||||
public static void setMode(boolean cursorAim) {
|
public static void setMode(boolean cursorAim) {
|
||||||
cursorAimMode = cursorAim;
|
cursorAimMode = cursorAim;
|
||||||
@@ -135,10 +227,12 @@ public final class CursorAimClient {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
active = true;
|
active = true;
|
||||||
|
cursorWorld = null;
|
||||||
cf = 1.0;
|
cf = 1.0;
|
||||||
cr = 0.0;
|
cr = 0.0;
|
||||||
cu = 0.0;
|
cu = 0.0;
|
||||||
cameraDirection = null;
|
cameraDirection = null;
|
||||||
|
airborneTicks = 0;
|
||||||
offsetYaw = 0.0;
|
offsetYaw = 0.0;
|
||||||
offsetPitch = 0.0;
|
offsetPitch = 0.0;
|
||||||
haveLast = false;
|
haveLast = false;
|
||||||
@@ -184,7 +278,8 @@ public final class CursorAimClient {
|
|||||||
}
|
}
|
||||||
Entity seat = AimSeat.seatOf(player);
|
Entity seat = AimSeat.seatOf(player);
|
||||||
AimBasis basis = AimBasis.of(level, seat.blockPosition());
|
AimBasis basis = AimBasis.of(level, seat.blockPosition());
|
||||||
if (basis == null) {
|
Quaterniondc rotation = basis != null ? shipRotation(level, seat, true) : null;
|
||||||
|
if (basis == null || rotation == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (minecraft.options.getCameraType() != CameraType.THIRD_PERSON_BACK) {
|
if (minecraft.options.getCameraType() != CameraType.THIRD_PERSON_BACK) {
|
||||||
@@ -207,10 +302,11 @@ public final class CursorAimClient {
|
|||||||
deltaPitch = 0.0;
|
deltaPitch = 0.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
double sensitivity = CursorAimClientConfig.MOUSE_SENSITIVITY.get();
|
double sensitivity = Config.CURSOR_AIM_MOUSE_SENSITIVITY.get();
|
||||||
boolean freeLook = minecraft.screen == null && AimKeys.FREE_LOOK.isDown();
|
boolean freeLook = minecraft.screen == null && AimKeys.FREE_LOOK.isDown();
|
||||||
|
|
||||||
double spring = CursorAimClientConfig.SPRING_BACK_SECONDS.get();
|
cursorFromWorld(basis, rotation);
|
||||||
|
double spring = Config.CURSOR_AIM_SPRING_BACK_SECONDS.get();
|
||||||
if (spring > 0.0) {
|
if (spring > 0.0) {
|
||||||
shrinkCursor(Math.exp(-dt / spring));
|
shrinkCursor(Math.exp(-dt / spring));
|
||||||
}
|
}
|
||||||
@@ -223,14 +319,16 @@ public final class CursorAimClient {
|
|||||||
offsetYaw *= decay;
|
offsetYaw *= decay;
|
||||||
offsetPitch *= decay;
|
offsetPitch *= decay;
|
||||||
}
|
}
|
||||||
|
cursorToWorld(basis, rotation);
|
||||||
|
|
||||||
// Camera: along the reticle, or turned towards the cursor by the look ahead setting
|
// Camera: along the reticle, or turned towards the cursor by the look ahead setting once the craft is flying
|
||||||
double lookAhead = CursorAimClientConfig.LOOK_AHEAD.get();
|
double lookAhead = Config.CURSOR_AIM_LOOK_AHEAD.get();
|
||||||
double[] forward = basis.forward();
|
double[] forward = basis.forward();
|
||||||
if (cameraDirection == null || lookAhead <= 0.0) {
|
if (cameraDirection == null || lookAhead <= 0.0) {
|
||||||
cameraDirection = forward.clone();
|
cameraDirection = forward.clone();
|
||||||
} else {
|
} else {
|
||||||
double[] target = basis.toShip(cf, cr, cu);
|
// On the ground it eases back behind the reticle rather than snapping there
|
||||||
|
double[] target = airborneTicks >= AIRBORNE_TICKS ? basis.toShip(cf, cr, cu) : forward;
|
||||||
cameraDirection = turnTowards(cameraDirection, target, 1.0 - Math.exp(-lookAhead * LOOK_AHEAD_RATE * dt));
|
cameraDirection = turnTowards(cameraDirection, target, 1.0 - Math.exp(-lookAhead * LOOK_AHEAD_RATE * dt));
|
||||||
}
|
}
|
||||||
double[] direction = rotate(cameraDirection, basis.up(), -Math.toRadians(offsetYaw));
|
double[] direction = rotate(cameraDirection, basis.up(), -Math.toRadians(offsetYaw));
|
||||||
@@ -295,7 +393,7 @@ public final class CursorAimClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void limitCursor() {
|
private static void limitCursor() {
|
||||||
double limit = Math.toRadians(CursorAimClientConfig.MAX_CURSOR_ANGLE_DEGREES.get());
|
double limit = Math.toRadians(Config.CURSOR_AIM_MAX_ANGLE_DEGREES.get());
|
||||||
double angle = Math.acos(Mth.clamp(cf, -1.0, 1.0));
|
double angle = Math.acos(Mth.clamp(cf, -1.0, 1.0));
|
||||||
if (angle <= limit) {
|
if (angle <= limit) {
|
||||||
return;
|
return;
|
||||||
@@ -318,7 +416,7 @@ public final class CursorAimClient {
|
|||||||
if (!active || minecraft.screen != null) {
|
if (!active || minecraft.screen != null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
zoom = Mth.clamp(zoom - event.getScrollDelta() * CursorAimClientConfig.ZOOM_STEP.get(), -3.0, CursorAimClientConfig.ZOOM_MAX.get());
|
zoom = Mth.clamp(zoom - event.getScrollDelta() * Config.CURSOR_AIM_ZOOM_STEP.get(), -3.0, Config.CURSOR_AIM_ZOOM_MAX.get());
|
||||||
event.setCanceled(true);
|
event.setCanceled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -354,14 +452,10 @@ public final class CursorAimClient {
|
|||||||
}
|
}
|
||||||
Entity seat = AimSeat.seatOf(player);
|
Entity seat = AimSeat.seatOf(player);
|
||||||
AimBasis basis = AimBasis.of(level, seat.blockPosition());
|
AimBasis basis = AimBasis.of(level, seat.blockPosition());
|
||||||
Ship ship = VSGameUtilsKt.getLoadedShipManagingPos(level, BlockPos.containing(seat.getX(), seat.getY(), seat.getZ()));
|
Quaterniondc rotation = basis != null ? shipRotation(level, seat, true) : null;
|
||||||
if (basis == null || ship == null) {
|
if (rotation == null || cursorWorld == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Quaterniondc rotation = ship instanceof ClientShip clientShip
|
|
||||||
? clientShip.getRenderTransform().getShipToWorldRotation() : ship.getTransform().getShipToWorldRotation();
|
|
||||||
double[] cursorShip = basis.toShip(cf, cr, cu);
|
|
||||||
Vector3d cursorWorld = rotation.transform(new Vector3d(cursorShip[0], cursorShip[1], cursorShip[2]));
|
|
||||||
double[] forward = basis.forward();
|
double[] forward = basis.forward();
|
||||||
Vector3d reticleWorld = rotation.transform(new Vector3d(forward[0], forward[1], forward[2]));
|
Vector3d reticleWorld = rotation.transform(new Vector3d(forward[0], forward[1], forward[2]));
|
||||||
|
|
||||||
@@ -375,8 +469,8 @@ public final class CursorAimClient {
|
|||||||
RenderSystem.setShader(GameRenderer::getPositionColorShader);
|
RenderSystem.setShader(GameRenderer::getPositionColorShader);
|
||||||
builder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
builder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
||||||
|
|
||||||
float size = (float) (CursorAimClientConfig.MARKER_SIZE.get() * MARKER_DISTANCE);
|
float size = (float) (Config.CURSOR_AIM_MARKER_SIZE.get() * MARKER_DISTANCE);
|
||||||
if (CursorAimClientConfig.SHOW_RETICLE.get()) {
|
if (Config.CURSOR_AIM_SHOW_RETICLE.get()) {
|
||||||
plus(builder, matrix, camera, reticleWorld, size * 0.35F, RETICLE_COLOR);
|
plus(builder, matrix, camera, reticleWorld, size * 0.35F, RETICLE_COLOR);
|
||||||
}
|
}
|
||||||
ring(builder, matrix, camera, cursorWorld, size, CURSOR_COLOR);
|
ring(builder, matrix, camera, cursorWorld, size, CURSOR_COLOR);
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
package dev.lumareth.improvedAerodynamics.client.aim;
|
|
||||||
|
|
||||||
import net.minecraftforge.common.ForgeConfigSpec;
|
|
||||||
|
|
||||||
/** Client side settings of cursor aim. Lives in improved_aerodynamics-cursor-aim-client.toml. */
|
|
||||||
public final class CursorAimClientConfig {
|
|
||||||
public static final ForgeConfigSpec SPEC;
|
|
||||||
|
|
||||||
public static final ForgeConfigSpec.DoubleValue LOOK_AHEAD;
|
|
||||||
public static final ForgeConfigSpec.DoubleValue MOUSE_SENSITIVITY;
|
|
||||||
public static final ForgeConfigSpec.DoubleValue SPRING_BACK_SECONDS;
|
|
||||||
public static final ForgeConfigSpec.DoubleValue MAX_CURSOR_ANGLE_DEGREES;
|
|
||||||
public static final ForgeConfigSpec.DoubleValue ZOOM_STEP;
|
|
||||||
public static final ForgeConfigSpec.DoubleValue ZOOM_MAX;
|
|
||||||
public static final ForgeConfigSpec.DoubleValue MARKER_SIZE;
|
|
||||||
public static final ForgeConfigSpec.BooleanValue SHOW_RETICLE;
|
|
||||||
|
|
||||||
static {
|
|
||||||
ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder();
|
|
||||||
builder.comment("Cursor aim, client side").push("cursor_aim");
|
|
||||||
LOOK_AHEAD = builder.comment("How strongly the camera looks into the direction of the turn. 0 never moves it, 1 (100%) turns it quickly",
|
|
||||||
"to look where the cursor points. In between it follows more slowly")
|
|
||||||
.defineInRange("lookAhead", 0.0, 0.0, 1.0);
|
|
||||||
MOUSE_SENSITIVITY = builder.comment("Multiplier for how far the mouse moves the cursor (or the camera while the free look key is held)")
|
|
||||||
.defineInRange("mouseSensitivity", 1.0, 0.05, 10.0);
|
|
||||||
SPRING_BACK_SECONDS = builder.comment("The cursor returns to the gun reticle with this time constant in seconds when you stop moving the mouse.",
|
|
||||||
"0 makes it stay where you left it")
|
|
||||||
.defineInRange("springBackSeconds", 1.0, 0.0, 10.0);
|
|
||||||
MAX_CURSOR_ANGLE_DEGREES = builder.comment("Furthest the cursor can go from the gun reticle, 135 is a 270 degree cone")
|
|
||||||
.defineInRange("maxCursorAngleDegrees", 135.0, 10.0, 180.0);
|
|
||||||
ZOOM_STEP = builder.comment("Blocks the camera moves per mouse wheel notch")
|
|
||||||
.defineInRange("zoomStep", 2.0, 0.1, 20.0);
|
|
||||||
ZOOM_MAX = builder.comment("Furthest the camera can be pulled back from its normal distance, in blocks")
|
|
||||||
.defineInRange("zoomMax", 80.0, 0.0, 500.0);
|
|
||||||
MARKER_SIZE = builder.comment("Radius of the cursor ring on screen")
|
|
||||||
.defineInRange("markerSize", 0.04, 0.01, 0.3);
|
|
||||||
SHOW_RETICLE = builder.comment("Draw a small cross where the gun reticle points, the zero of the cursor, so you can see it when the camera looks away")
|
|
||||||
.define("showReticle", true);
|
|
||||||
builder.pop();
|
|
||||||
SPEC = builder.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private CursorAimClientConfig() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+138
@@ -0,0 +1,138 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.client.animation;
|
||||||
|
|
||||||
|
import dev.lumareth.improvedAerodynamics.Config;
|
||||||
|
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
|
import net.minecraftforge.client.event.ClientPlayerNetworkEvent;
|
||||||
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
import software.bernie.geckolib.core.animatable.model.CoreGeoBone;
|
||||||
|
import software.bernie.geckolib.model.GeoModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Client side of the control surface animation. The server tells the clients how far each control surface is deflected
|
||||||
|
* (see {@code DeflectionSync}); this class keeps those values, eases towards them, and sets the rotation of the "Fin"
|
||||||
|
* bone of Warium's control surface models to them after GeckoLib has played Warium's own fixed animation.
|
||||||
|
* <p>
|
||||||
|
* Warium's animations tilt the Fin bone by 20 degrees about X for a positive input, which GeckoLib turns into a
|
||||||
|
* rotation of -20 degrees (it negates X and Y for rotations), and the same sign is used here, so a surface moves the
|
||||||
|
* way Warium's own animation moves it, only by the amount the physics uses. Warframes' vertical control surfaces are
|
||||||
|
* modelled differently: their Fin turns about Y, by -20 degrees in the animation file (+20 after GeckoLib) for the same
|
||||||
|
* input.
|
||||||
|
* <p>
|
||||||
|
* Futurism's vectored afterburner is shown the same way: its own animation only swings the Nozzle bone all the way (20
|
||||||
|
* degrees about X) up or down, here it follows the tilt the block actually has, which Futurism keeps in the block's
|
||||||
|
* synced data as "Vectorpitch" (minus a third of the input).
|
||||||
|
*/
|
||||||
|
@Mod.EventBusSubscriber(modid = dev.lumareth.improvedAerodynamics.ImprovedAerodynamics.MOD_ID, value = Dist.CLIENT)
|
||||||
|
public final class SurfaceAnimation {
|
||||||
|
private static final String BONE = "Fin";
|
||||||
|
private static final String WARFRAMES_VERTICAL = "net.evo_mc.warframes.block.entity.WarframeVerticalControlSurfaceBlockEntity";
|
||||||
|
private static final String FUTURISM_VECTORED = "net.mcreator.futurism.block.entity.VectoredAfterburnerTileEntity";
|
||||||
|
private static final String NOZZLE_BONE = "Nozzle";
|
||||||
|
// Futurism's animation swing at full input, degrees
|
||||||
|
private static final float FUTURISM_FULL_DEGREES = 20.0F;
|
||||||
|
// A value that has not been refreshed for this long is dropped, Warium's own animation takes over again
|
||||||
|
private static final long STALE_NANOS = 3_000_000_000L;
|
||||||
|
// Time in seconds the visible deflection takes to close most of the way to the latest value
|
||||||
|
private static final double EASE_SECONDS = 0.07;
|
||||||
|
|
||||||
|
private static final class Entry {
|
||||||
|
float target;
|
||||||
|
float shown;
|
||||||
|
long updated;
|
||||||
|
long drawn;
|
||||||
|
boolean placed;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Long2ObjectOpenHashMap<Entry> ENTRIES = new Long2ObjectOpenHashMap<>();
|
||||||
|
// Shown angle (degrees) of each Futurism vectored afterburner
|
||||||
|
private static final Long2ObjectOpenHashMap<Entry> VECTORED = new Long2ObjectOpenHashMap<>();
|
||||||
|
|
||||||
|
private SurfaceAnimation() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/** New deflection of a control surface in degrees, in Warium's animation sign (positive is its "input up" tilt). */
|
||||||
|
public static void set(long pos, float degrees) {
|
||||||
|
Entry entry = ENTRIES.computeIfAbsent(pos, key -> new Entry());
|
||||||
|
entry.target = degrees;
|
||||||
|
entry.updated = System.nanoTime();
|
||||||
|
if (!entry.placed) {
|
||||||
|
// First value of a surface: show it right away, it may have been there before the player came near
|
||||||
|
entry.shown = degrees;
|
||||||
|
entry.placed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void apply(BlockEntity blockEntity, GeoModel<?> model) {
|
||||||
|
if (!Config.ANIMATE_SURFACES.get()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (blockEntity.getClass().getName().equals(FUTURISM_VECTORED)) {
|
||||||
|
applyVectored(blockEntity, model);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ENTRIES.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Entry entry = ENTRIES.get(blockEntity.getBlockPos().asLong());
|
||||||
|
if (entry == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
long now = System.nanoTime();
|
||||||
|
if (now - entry.updated > STALE_NANOS) {
|
||||||
|
ENTRIES.remove(blockEntity.getBlockPos().asLong());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ease(entry, now);
|
||||||
|
CoreGeoBone bone = model.getAnimationProcessor().getBone(BONE);
|
||||||
|
if (bone == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
float radians = (float) Math.toRadians(entry.shown);
|
||||||
|
if (blockEntity.getClass().getName().equals(WARFRAMES_VERTICAL)) {
|
||||||
|
bone.setRotX(0.0F);
|
||||||
|
bone.setRotY(radians);
|
||||||
|
} else {
|
||||||
|
bone.setRotX(-radians);
|
||||||
|
}
|
||||||
|
// Setting a rotation flags the bone as animated, and GeckoLib cleared its flags before this runs. Left set, the
|
||||||
|
// flag would make GeckoLib skip resetting this bone for the next block drawn with the same model (all blocks of
|
||||||
|
// a model share its bones), so that block would keep this block's deflection
|
||||||
|
bone.resetStateChanges();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Futurism's vectored afterburner: the Nozzle bone at the block's real tilt, Futurism's sign. */
|
||||||
|
private static void applyVectored(BlockEntity blockEntity, GeoModel<?> model) {
|
||||||
|
float input = (float) (-3.0 * blockEntity.getPersistentData().getDouble("Vectorpitch"));
|
||||||
|
float degrees = FUTURISM_FULL_DEGREES * Math.max(-1.0F, Math.min(1.0F, input));
|
||||||
|
Entry entry = VECTORED.computeIfAbsent(blockEntity.getBlockPos().asLong(), key -> new Entry());
|
||||||
|
entry.target = degrees;
|
||||||
|
if (!entry.placed) {
|
||||||
|
entry.shown = degrees;
|
||||||
|
entry.placed = true;
|
||||||
|
}
|
||||||
|
ease(entry, System.nanoTime());
|
||||||
|
CoreGeoBone bone = model.getAnimationProcessor().getBone(NOZZLE_BONE);
|
||||||
|
if (bone != null) {
|
||||||
|
bone.setRotX((float) -Math.toRadians(entry.shown));
|
||||||
|
bone.resetStateChanges();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Moves the shown value towards the target. The same block can be drawn more than once a frame (shadows, other passes), the easing steps once per frame. */
|
||||||
|
private static void ease(Entry entry, long now) {
|
||||||
|
if (entry.drawn != 0L && now != entry.drawn) {
|
||||||
|
double dt = (now - entry.drawn) / 1.0E9;
|
||||||
|
entry.shown += (entry.target - entry.shown) * (float) (1.0 - Math.exp(-dt / EASE_SECONDS));
|
||||||
|
}
|
||||||
|
entry.drawn = now;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onLoggingOut(ClientPlayerNetworkEvent.LoggingOut event) {
|
||||||
|
ENTRIES.clear();
|
||||||
|
VECTORED.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.exhaust;
|
||||||
|
|
||||||
|
import dev.lumareth.improvedAerodynamics.Config;
|
||||||
|
import dev.lumareth.improvedAerodynamics.flight.AutoTrimToggle;
|
||||||
|
import net.mcreator.valkyrienwarium.entity.SeatEntityEntity;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Server side of the afterburner key. The switch lives in the control node, like auto trim, so it stays with the
|
||||||
|
* craft and every nozzle linked to the node follows it. It only lights with enough throttle and goes out for good
|
||||||
|
* once the throttle falls below that, see {@link NozzleBlockEntity}.
|
||||||
|
*/
|
||||||
|
public final class AfterburnerToggle {
|
||||||
|
/** Tag on the control node that holds the switch. */
|
||||||
|
public static final String TAG = "improved_aerodynamics_afterburner";
|
||||||
|
|
||||||
|
private AfterburnerToggle() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void toggle(ServerPlayer player) {
|
||||||
|
Entity vehicle = player.getVehicle();
|
||||||
|
if (!(vehicle instanceof SeatEntityEntity)) {
|
||||||
|
player.displayClientMessage(Component.translatable("message.improved_aerodynamics.afterburner.no_seat"), true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
BlockEntity node = AutoTrimToggle.findNode(vehicle.level(), vehicle.blockPosition());
|
||||||
|
if (node == null) {
|
||||||
|
player.displayClientMessage(Component.translatable("message.improved_aerodynamics.afterburner.no_node"), true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CompoundTag tag = node.getPersistentData();
|
||||||
|
double minimum = Config.AFTERBURNER_MIN_THROTTLE.get();
|
||||||
|
if (!tag.getBoolean(TAG) && tag.getDouble("Throttle") < minimum) {
|
||||||
|
player.displayClientMessage(Component.translatable("message.improved_aerodynamics.afterburner.throttle", (int) Math.ceil(minimum)), true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
boolean enabled = !tag.getBoolean(TAG);
|
||||||
|
tag.putBoolean(TAG, enabled);
|
||||||
|
node.setChanged();
|
||||||
|
player.displayClientMessage(Component.translatable(enabled
|
||||||
|
? "message.improved_aerodynamics.afterburner.on" : "message.improved_aerodynamics.afterburner.off"), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.exhaust;
|
||||||
|
|
||||||
|
import dev.lumareth.improvedAerodynamics.ImprovedAerodynamics;
|
||||||
|
import dev.lumareth.improvedAerodynamics.network.ExhaustPacket;
|
||||||
|
import dev.lumareth.improvedAerodynamics.network.Network;
|
||||||
|
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.resources.ResourceKey;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
import net.minecraftforge.event.server.ServerStoppedEvent;
|
||||||
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
|
import net.minecraftforge.network.PacketDistributor;
|
||||||
|
import org.joml.Vector3d;
|
||||||
|
import org.valkyrienskies.mod.common.VSGameUtilsKt;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tells the players near a burning jet exhaust about it, for the improved exhaust style. A packet goes out when the
|
||||||
|
* exhaust changes and otherwise every few ticks, which keeps the flame alive on the clients, see {@code ExhaustFlames}.
|
||||||
|
*/
|
||||||
|
public final class ExhaustSync {
|
||||||
|
private static final int RESEND_TICKS = 4;
|
||||||
|
private static final double RANGE = 256.0;
|
||||||
|
private static boolean announced;
|
||||||
|
|
||||||
|
private record Sent(long tick, Vec3 direction, int intensity, boolean afterburner) {
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Map<ResourceKey<Level>, Long2ObjectOpenHashMap<Sent>> SENT = new HashMap<>();
|
||||||
|
|
||||||
|
private ExhaustSync() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param key the block the exhaust belongs to, one flame per key
|
||||||
|
* @param exit where the flame starts, in the block's coordinates
|
||||||
|
* @param direction unit vector the exhaust moves along
|
||||||
|
* @param intensity 0 to 1
|
||||||
|
*/
|
||||||
|
public static void emit(ServerLevel level, BlockPos key, Vec3 exit, Vec3 direction, float intensity, boolean afterburner) {
|
||||||
|
Long2ObjectOpenHashMap<Sent> sent = SENT.computeIfAbsent(level.dimension(), dimension -> new Long2ObjectOpenHashMap<>());
|
||||||
|
long now = level.getGameTime();
|
||||||
|
int quantized = Math.round(Math.max(0.0F, Math.min(1.0F, intensity)) * 100.0F);
|
||||||
|
Sent last = sent.get(key.asLong());
|
||||||
|
if (last != null && now - last.tick() < RESEND_TICKS && last.intensity() == quantized && last.afterburner() == afterburner
|
||||||
|
&& last.direction().distanceToSqr(direction) < 1.0E-4) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sent.put(key.asLong(), new Sent(now, direction, quantized, afterburner));
|
||||||
|
ExhaustPacket packet = new ExhaustPacket(key, exit.subtract(key.getX(), key.getY(), key.getZ()), direction, quantized, afterburner);
|
||||||
|
// Near where the exhaust is in the world: on a ship the block itself is far out in the ship's own chunks, which
|
||||||
|
// nobody is tracking in the usual way
|
||||||
|
Vec3 world = exit;
|
||||||
|
var ship = VSGameUtilsKt.getShipManagingPos(level, key);
|
||||||
|
if (ship != null) {
|
||||||
|
Vector3d transformed = ship.getShipToWorld().transformPosition(new Vector3d(exit.x, exit.y, exit.z));
|
||||||
|
world = new Vec3(transformed.x, transformed.y, transformed.z);
|
||||||
|
}
|
||||||
|
Vec3 point = world;
|
||||||
|
Network.CHANNEL.send(PacketDistributor.NEAR.with(() -> new PacketDistributor.TargetPoint(point.x, point.y, point.z,
|
||||||
|
RANGE, level.dimension())), packet);
|
||||||
|
if (!announced) {
|
||||||
|
announced = true;
|
||||||
|
ImprovedAerodynamics.LOGGER.info("Sent the first improved exhaust flame, at {} (world {}) to the players within {} blocks",
|
||||||
|
key.toShortString(), point, RANGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onServerStopped(ServerStoppedEvent event) {
|
||||||
|
SENT.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.exhaust;
|
||||||
|
|
||||||
|
import net.mcreator.valkyrienwarium.ships.ForceData;
|
||||||
|
import net.mcreator.valkyrienwarium.ships.ForceDirectionMode;
|
||||||
|
import net.mcreator.valkyrienwarium.ships.ForceInducedShips;
|
||||||
|
import net.mcreator.valkyrienwarium.ships.ForceMode;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.core.Direction;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
import org.joml.Vector3d;
|
||||||
|
import org.valkyrienskies.core.api.ships.LoadedServerShip;
|
||||||
|
import org.valkyrienskies.core.api.ships.ServerShip;
|
||||||
|
import org.valkyrienskies.mod.common.VSGameUtilsKt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thrust of a nozzle, the way Futurism's vectored afterburner makes it: the power comes from the Warium jet exhaust
|
||||||
|
* directly behind the nozzle, which hands it over through its {@code ExhaustPower} value instead of pushing the ship
|
||||||
|
* itself because the nozzle is in the {@code warium_vs:blocksjet} tag. The push goes opposite to the way the exhaust
|
||||||
|
* leaves, so a nozzle deflected upwards pushes the tail down. Only used where Warium VS is installed.
|
||||||
|
*/
|
||||||
|
final class ExhaustThrust {
|
||||||
|
private ExhaustThrust() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The power the jet exhaust directly behind the nozzle hands over, 0 if there is none or it is off. */
|
||||||
|
static double power(Level level, BlockPos pos, Direction facing) {
|
||||||
|
BlockEntity exhaust = level.getBlockEntity(pos.relative(facing.getOpposite()));
|
||||||
|
return exhaust != null ? exhaust.getPersistentData().getDouble("ExhaustPower") : 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void apply(ServerLevel level, BlockPos pos, Direction facing, Vec3 exhaustDirection) {
|
||||||
|
double power = power(level, pos, facing);
|
||||||
|
if (power <= 0.0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
LoadedServerShip ship = VSGameUtilsKt.getLoadedShipManagingPos(level, pos);
|
||||||
|
if (ship == null || ((ServerShip) ship).isStatic()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Vector3d push = new Vector3d(-exhaustDirection.x, -exhaustDirection.y, -exhaustDirection.z);
|
||||||
|
ForceInducedShips.getOrCreate(ship).addForce(pos, new ForceData(push, power, ForceMode.POSITION, ForceDirectionMode.SHIP));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.exhaust;
|
||||||
|
|
||||||
|
import dev.lumareth.improvedAerodynamics.Config;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.core.Direction;
|
||||||
|
import net.minecraft.core.registries.Registries;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.tags.TagKey;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.level.LevelAccessor;
|
||||||
|
import net.minecraft.world.level.block.Block;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
||||||
|
import net.minecraft.world.level.block.state.properties.Property;
|
||||||
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The improved exhaust style, see {@code exhaustStyle} in the config. It applies to every block that makes a jet exhaust:
|
||||||
|
* Warium's jet exhaust and VTOL exhaust, Futurism's vectored afterburner behind which a jet exhaust sits, and this mod's
|
||||||
|
* nozzle. In the other style Warium's own effect entities draw the flame and none of this runs.
|
||||||
|
* <p>
|
||||||
|
* Warium's exhausts do not spawn their effect entities then. When one would have, it sends a burning flame to the clients instead, from the
|
||||||
|
* block in front if that one takes over the thrust (the {@code blocksjet} tag), at its exit and along its deflection. The
|
||||||
|
* engine behind the exhaust says how hard it works ({@code Power}) and whether its afterburner burns. Warium's sound is
|
||||||
|
* kept.
|
||||||
|
*/
|
||||||
|
public final class ImprovedExhaust {
|
||||||
|
private static final double FULL_POWER = 100.0;
|
||||||
|
private static final TagKey<Block> TAKES_OVER_THRUST = TagKey.create(Registries.BLOCK, new ResourceLocation("warium_vs", "blocksjet"));
|
||||||
|
|
||||||
|
private ImprovedExhaust() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isImproved() {
|
||||||
|
try {
|
||||||
|
return "improved".equals(Config.EXHAUST_STYLE.get());
|
||||||
|
} catch (IllegalStateException e) {
|
||||||
|
// The config is not loaded yet
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// What the exhaust being ticked would have spawned, it only ticks on the server thread and one at a time
|
||||||
|
private static boolean jetEffect;
|
||||||
|
private static boolean afterburnerEffect;
|
||||||
|
|
||||||
|
/** Called when an exhaust starts its tick. */
|
||||||
|
public static void begin() {
|
||||||
|
jetEffect = false;
|
||||||
|
afterburnerEffect = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used instead of adding Warium's effect entity. The exhaust only makes one when it burns, so that is the signal to
|
||||||
|
* send the improved flame; in the improved style the entity itself is not added, in the other it is, as always.
|
||||||
|
*/
|
||||||
|
public static boolean addEffectEntity(ServerLevel level, Entity entity) {
|
||||||
|
if (!isImproved()) {
|
||||||
|
return level.addFreshEntity(entity);
|
||||||
|
}
|
||||||
|
var key = net.minecraftforge.registries.ForgeRegistries.ENTITY_TYPES.getKey(entity.getType());
|
||||||
|
if (key != null && key.getPath().contains("after")) {
|
||||||
|
afterburnerEffect = true;
|
||||||
|
} else {
|
||||||
|
jetEffect = true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sends the flame of the exhaust at this position for this tick. */
|
||||||
|
public static void plume(LevelAccessor accessor, double x, double y, double z, BlockState state) {
|
||||||
|
Direction facing = facingOf(state);
|
||||||
|
if (!isImproved() || !(accessor instanceof ServerLevel level) || facing == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!jetEffect && !afterburnerEffect) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
BlockPos pos = BlockPos.containing(x, y, z);
|
||||||
|
boolean afterburner = afterburnerEffect;
|
||||||
|
// How hard it works, if the engine behind says so, otherwise a flame that is clearly there
|
||||||
|
BlockEntity engine = level.getBlockEntity(pos.relative(facing.getOpposite()));
|
||||||
|
double power = engine != null ? engine.getPersistentData().getDouble("Power") : 0.0;
|
||||||
|
float intensity = power > 0.0 ? (float) Math.min(1.0, 0.3 + power / FULL_POWER) : (afterburner ? 1.0F : 0.8F);
|
||||||
|
|
||||||
|
Vec3 exit = NozzleGeometry.exit(pos, facing);
|
||||||
|
Vec3 direction = new Vec3(facing.getStepX(), facing.getStepY(), facing.getStepZ());
|
||||||
|
BlockPos frontPos = pos.relative(facing);
|
||||||
|
BlockState front = level.getBlockState(frontPos);
|
||||||
|
if (front.is(TAKES_OVER_THRUST)) {
|
||||||
|
if (front.getBlock() instanceof NozzleBlock) {
|
||||||
|
// The nozzle draws its own flame, swinging with its nozzle
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Futurism's vectored afterburner: its flame leaves its exit, tilted by its vector value
|
||||||
|
Direction frontFacing = facingOf(front) != null ? facingOf(front) : facing;
|
||||||
|
BlockEntity frontEntity = level.getBlockEntity(frontPos);
|
||||||
|
double tilt = frontEntity != null ? frontEntity.getPersistentData().getDouble("Vectorpitch") : 0.0;
|
||||||
|
exit = NozzleGeometry.exit(frontPos, frontFacing);
|
||||||
|
direction = new Vec3(frontFacing.getStepX(), frontFacing.getStepY() + tilt, frontFacing.getStepZ()).normalize();
|
||||||
|
}
|
||||||
|
ExhaustSync.emit(level, pos, exit, direction, intensity, afterburner);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The direction a Warium block faces, from its property called facing, which is not always the same property. */
|
||||||
|
public static Direction facingOf(BlockState state) {
|
||||||
|
for (Property<?> property : state.getProperties()) {
|
||||||
|
if (property instanceof DirectionProperty direction && property.getName().equals("facing")) {
|
||||||
|
return state.getValue(direction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.exhaust;
|
||||||
|
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.world.InteractionHand;
|
||||||
|
import net.minecraft.world.InteractionResult;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.block.BaseEntityBlock;
|
||||||
|
import net.minecraft.world.level.block.DirectionalBlock;
|
||||||
|
import net.minecraft.world.level.block.Mirror;
|
||||||
|
import net.minecraft.world.level.block.RenderShape;
|
||||||
|
import net.minecraft.world.level.block.Rotation;
|
||||||
|
import net.minecraft.world.level.block.SoundType;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import net.minecraft.world.level.block.state.StateDefinition;
|
||||||
|
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
||||||
|
import net.minecraft.world.level.material.MapColor;
|
||||||
|
import net.minecraft.world.phys.BlockHitResult;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Jet engine nozzle with thrust vectoring. Faces the way its exhaust leaves, like Warium's jet exhausts, and is drawn by
|
||||||
|
* AzureLib. Sneak-use with an empty hand switches it between left and right engine.
|
||||||
|
*/
|
||||||
|
public class NozzleBlock extends BaseEntityBlock {
|
||||||
|
public static final BooleanProperty LIT = BooleanProperty.create("lit");
|
||||||
|
|
||||||
|
public NozzleBlock() {
|
||||||
|
super(Properties.of().mapColor(MapColor.METAL).strength(3.0F, 6.0F).requiresCorrectToolForDrops()
|
||||||
|
.sound(SoundType.METAL).noOcclusion().lightLevel(state -> state.getValue(LIT) ? 13 : 0));
|
||||||
|
registerDefaultState(stateDefinition.any().setValue(DirectionalBlock.FACING, net.minecraft.core.Direction.NORTH)
|
||||||
|
.setValue(LIT, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void createBlockStateDefinition(StateDefinition.Builder<net.minecraft.world.level.block.Block, BlockState> builder) {
|
||||||
|
builder.add(DirectionalBlock.FACING, LIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockState getStateForPlacement(BlockPlaceContext context) {
|
||||||
|
return defaultBlockState().setValue(DirectionalBlock.FACING, context.getNearestLookingDirection().getOpposite());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockState rotate(BlockState state, Rotation rotation) {
|
||||||
|
return state.setValue(DirectionalBlock.FACING, rotation.rotate(state.getValue(DirectionalBlock.FACING)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockState mirror(BlockState state, Mirror mirror) {
|
||||||
|
return state.rotate(mirror.getRotation(state.getValue(DirectionalBlock.FACING)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RenderShape getRenderShape(BlockState state) {
|
||||||
|
return RenderShape.ENTITYBLOCK_ANIMATED;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
|
||||||
|
if (!player.isShiftKeyDown() || !player.getItemInHand(hand).isEmpty()) {
|
||||||
|
return InteractionResult.PASS;
|
||||||
|
}
|
||||||
|
if (!level.isClientSide && level.getBlockEntity(pos) instanceof NozzleBlockEntity nozzle) {
|
||||||
|
nozzle.setRightEngine(!nozzle.isRightEngine());
|
||||||
|
player.displayClientMessage(Component.translatable(nozzle.isRightEngine()
|
||||||
|
? "message.improved_aerodynamics.nozzle.right" : "message.improved_aerodynamics.nozzle.left"), true);
|
||||||
|
}
|
||||||
|
return InteractionResult.sidedSuccess(level.isClientSide);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
|
||||||
|
return new NozzleBlockEntity(pos, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) {
|
||||||
|
return createTickerHelper(type, NozzleContent.NOZZLE_ENTITY.get(), NozzleBlockEntity::tick);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,281 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.exhaust;
|
||||||
|
|
||||||
|
import dev.lumareth.improvedAerodynamics.Config;
|
||||||
|
import dev.lumareth.improvedAerodynamics.exhaust.client.NozzleClientEffects;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.core.Direction;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.network.Connection;
|
||||||
|
import net.minecraft.network.protocol.Packet;
|
||||||
|
import net.minecraft.network.protocol.game.ClientGamePacketListener;
|
||||||
|
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.block.DirectionalBlock;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import net.minecraft.world.phys.AABB;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* State of one vectored afterburner nozzle. The server owns it: whatever drives the nozzle (a debug command now, flight
|
||||||
|
* logic later) calls {@link #setDeflectionTarget}, {@link #setThrottle} and {@link #setAfterburner}, the rest follows
|
||||||
|
* from them. Everything the client needs to draw the nozzle is in the update tag, so players that join or reload the
|
||||||
|
* chunk see the right state.
|
||||||
|
*/
|
||||||
|
public class NozzleBlockEntity extends BlockEntity {
|
||||||
|
// Warium's throttle goes from 0 to 10
|
||||||
|
private static final float MAX_NODE_THROTTLE = 10.0F;
|
||||||
|
private static final boolean WARIUM_LOADED = net.minecraftforge.fml.ModList.get().isLoaded("valkyrien_warium");
|
||||||
|
// What changes are worth an update packet: a quarter degree, two percent throttle
|
||||||
|
private static final float DEFLECTION_STEP = (float) Math.toRadians(0.25);
|
||||||
|
private static final float THROTTLE_STEP = 0.02F;
|
||||||
|
|
||||||
|
private float deflectionTarget;
|
||||||
|
private float deflectionPrevious;
|
||||||
|
private float deflectionCurrent;
|
||||||
|
private float throttle;
|
||||||
|
private boolean afterburnerRequested;
|
||||||
|
private boolean afterburnerAuto;
|
||||||
|
private boolean afterburner;
|
||||||
|
private boolean rightEngine;
|
||||||
|
|
||||||
|
// Last values sent to the clients
|
||||||
|
private int sentDeflection;
|
||||||
|
private int sentThrottle;
|
||||||
|
private boolean sentAfterburner;
|
||||||
|
private boolean sentRightEngine;
|
||||||
|
|
||||||
|
/** The client's sound and particle state, owned by {@link NozzleClientEffects}. */
|
||||||
|
@Nullable
|
||||||
|
private Object clientEffects;
|
||||||
|
|
||||||
|
public NozzleBlockEntity(BlockPos pos, BlockState state) {
|
||||||
|
super(NozzleContent.NOZZLE_ENTITY.get(), pos, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- API ----
|
||||||
|
|
||||||
|
/** Sets where the nozzle should swing to, in radians, positive turns the nozzle's rotation bone positively. */
|
||||||
|
public void setDeflectionTarget(float radians) {
|
||||||
|
float limit = (float) Math.toRadians(Config.NOZZLE_MAX_DEFLECTION.get());
|
||||||
|
deflectionTarget = Math.max(-limit, Math.min(limit, radians));
|
||||||
|
changed();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sets the engine throttle, 0 to 1. Only matters for a nozzle that is not linked to a control node. */
|
||||||
|
public void setThrottle(float throttle) {
|
||||||
|
this.throttle = Math.max(0.0F, Math.min(1.0F, throttle));
|
||||||
|
changed();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Forces the afterburner on, independent of the control node. Switching it off leaves it to the afterburner key again. */
|
||||||
|
public void setAfterburner(boolean on) {
|
||||||
|
afterburnerRequested = on;
|
||||||
|
changed();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRightEngine(boolean right) {
|
||||||
|
rightEngine = right;
|
||||||
|
changed();
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getDeflectionTarget() {
|
||||||
|
return deflectionTarget;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The deflection being drawn, eased towards the target, interpolated between ticks. */
|
||||||
|
public float getDeflection(float partialTick) {
|
||||||
|
return deflectionPrevious + (deflectionCurrent - deflectionPrevious) * partialTick;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getThrottle() {
|
||||||
|
return throttle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAfterburner() {
|
||||||
|
return afterburner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isRightEngine() {
|
||||||
|
return rightEngine;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Direction getFacing() {
|
||||||
|
return getBlockState().getValue(DirectionalBlock.FACING);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- Ticking ----
|
||||||
|
|
||||||
|
public static void tick(Level level, BlockPos pos, BlockState state, NozzleBlockEntity nozzle) {
|
||||||
|
nozzle.tick(level);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void tick(Level level) {
|
||||||
|
if (!level.isClientSide) {
|
||||||
|
drive(level);
|
||||||
|
}
|
||||||
|
float maxStep = (float) Math.toRadians(Config.NOZZLE_SLEW_RATE.get() / 20.0);
|
||||||
|
deflectionPrevious = deflectionCurrent;
|
||||||
|
deflectionCurrent += Math.max(-maxStep, Math.min(maxStep, deflectionTarget - deflectionCurrent));
|
||||||
|
|
||||||
|
if (level.isClientSide) {
|
||||||
|
NozzleClientEffects.tick(this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
boolean lit = afterburnerRequested || afterburnerAuto;
|
||||||
|
if (lit != afterburner) {
|
||||||
|
afterburner = lit;
|
||||||
|
setChanged();
|
||||||
|
}
|
||||||
|
sync();
|
||||||
|
boolean light = lit && Config.NOZZLE_LIGHT.get();
|
||||||
|
BlockState state = getBlockState();
|
||||||
|
if (state.getValue(NozzleBlock.LIT) != light) {
|
||||||
|
level.setBlock(worldPosition, state.setValue(NozzleBlock.LIT, light), 3);
|
||||||
|
}
|
||||||
|
if (WARIUM_LOADED && level instanceof ServerLevel serverLevel) {
|
||||||
|
ExhaustThrust.apply(serverLevel, worldPosition, getFacing(),
|
||||||
|
NozzleGeometry.exhaustDirection(getFacing(), deflectionCurrent, rightEngine));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes throttle, deflection and afterburner from the linked control node. A nozzle without a link keeps what the
|
||||||
|
* API or the debug command gave it.
|
||||||
|
*/
|
||||||
|
private void drive(Level level) {
|
||||||
|
NozzleControl.Inputs inputs = NozzleControl.read(level, this);
|
||||||
|
if (inputs == null) {
|
||||||
|
afterburnerAuto = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// No flame without a running engine behind the nozzle: the jet exhaust there hands over its power
|
||||||
|
boolean running = !WARIUM_LOADED || ExhaustThrust.power(level, worldPosition, getFacing()) > 0.0;
|
||||||
|
throttle = running ? Math.min(1.0F, (float) inputs.throttle() / MAX_NODE_THROTTLE) : 0.0F;
|
||||||
|
float pitch = (float) inputs.pitchUp();
|
||||||
|
float roll = (float) inputs.rollRight();
|
||||||
|
deflectionTarget = NozzleMixing.deflection(pitch, roll, (float) inputs.yawRight(), rightEngine);
|
||||||
|
double minimum = Config.AFTERBURNER_MIN_THROTTLE.get();
|
||||||
|
if (inputs.afterburnerSwitch() && inputs.throttle() < minimum) {
|
||||||
|
// Too little throttle: out, and it stays out until the key is pressed again
|
||||||
|
inputs.node().getPersistentData().putBoolean(AfterburnerToggle.TAG, false);
|
||||||
|
inputs.node().setChanged();
|
||||||
|
}
|
||||||
|
afterburnerAuto = running && inputs.afterburnerSwitch() && inputs.throttle() >= minimum;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Saves the state, and tells the clients if something they can see changed. */
|
||||||
|
private void changed() {
|
||||||
|
setChanged();
|
||||||
|
sync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sync() {
|
||||||
|
if (level == null || level.isClientSide) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int deflection = Math.round(deflectionTarget / DEFLECTION_STEP);
|
||||||
|
int throttleStep = Math.round(throttle / THROTTLE_STEP);
|
||||||
|
if (deflection != sentDeflection || throttleStep != sentThrottle || afterburner != sentAfterburner || rightEngine != sentRightEngine) {
|
||||||
|
sentDeflection = deflection;
|
||||||
|
sentThrottle = throttleStep;
|
||||||
|
sentAfterburner = afterburner;
|
||||||
|
sentRightEngine = rightEngine;
|
||||||
|
level.sendBlockUpdated(worldPosition, getBlockState(), getBlockState(), UPDATE_CLIENTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final int UPDATE_CLIENTS = 2;
|
||||||
|
|
||||||
|
// ---- Saving and syncing ----
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void saveAdditional(CompoundTag tag) {
|
||||||
|
super.saveAdditional(tag);
|
||||||
|
tag.putFloat("Deflection", deflectionTarget);
|
||||||
|
tag.putFloat("Throttle", throttle);
|
||||||
|
tag.putBoolean("Afterburner", afterburner);
|
||||||
|
tag.putBoolean("AfterburnerRequested", afterburnerRequested);
|
||||||
|
tag.putBoolean("RightEngine", rightEngine);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load(CompoundTag tag) {
|
||||||
|
super.load(tag);
|
||||||
|
deflectionTarget = tag.getFloat("Deflection");
|
||||||
|
throttle = tag.getFloat("Throttle");
|
||||||
|
afterburner = tag.getBoolean("Afterburner");
|
||||||
|
afterburnerRequested = tag.getBoolean("AfterburnerRequested");
|
||||||
|
afterburnerAuto = afterburner && !afterburnerRequested;
|
||||||
|
rightEngine = tag.getBoolean("RightEngine");
|
||||||
|
if (level == null || !level.isClientSide || deflectionCurrent == 0.0F && deflectionPrevious == 0.0F) {
|
||||||
|
// Loaded fresh: start at the target instead of swinging in from zero
|
||||||
|
deflectionCurrent = deflectionTarget;
|
||||||
|
deflectionPrevious = deflectionTarget;
|
||||||
|
}
|
||||||
|
sentDeflection = Math.round(deflectionTarget / DEFLECTION_STEP);
|
||||||
|
sentThrottle = Math.round(throttle / THROTTLE_STEP);
|
||||||
|
sentAfterburner = afterburner;
|
||||||
|
sentRightEngine = rightEngine;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompoundTag getUpdateTag() {
|
||||||
|
return saveWithoutMetadata();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Packet<ClientGamePacketListener> getUpdatePacket() {
|
||||||
|
return ClientboundBlockEntityDataPacket.create(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDataPacket(Connection connection, ClientboundBlockEntityDataPacket packet) {
|
||||||
|
CompoundTag tag = packet.getTag();
|
||||||
|
if (tag != null) {
|
||||||
|
// Warium's key configuration screen reads the keys from the block's persistent data on the client, so that
|
||||||
|
// has to arrive too. Not load() as a whole: the deflection on screen must keep easing from where it is
|
||||||
|
super.load(tag);
|
||||||
|
deflectionTarget = tag.getFloat("Deflection");
|
||||||
|
throttle = tag.getFloat("Throttle");
|
||||||
|
afterburner = tag.getBoolean("Afterburner");
|
||||||
|
rightEngine = tag.getBoolean("RightEngine");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- Client ----
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Object getClientEffects() {
|
||||||
|
return clientEffects;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClientEffects(@Nullable Object clientEffects) {
|
||||||
|
this.clientEffects = clientEffects;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AABB getRenderBoundingBox() {
|
||||||
|
// The nozzle swings out of the block and the flame trails behind it
|
||||||
|
return new AABB(worldPosition).inflate(2.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setRemoved() {
|
||||||
|
super.setRemoved();
|
||||||
|
stopEffects();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChunkUnloaded() {
|
||||||
|
super.onChunkUnloaded();
|
||||||
|
stopEffects();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void stopEffects() {
|
||||||
|
if (level != null && level.isClientSide) {
|
||||||
|
NozzleClientEffects.stop(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.exhaust;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.arguments.BoolArgumentType;
|
||||||
|
import com.mojang.brigadier.arguments.FloatArgumentType;
|
||||||
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
|
import net.minecraft.commands.Commands;
|
||||||
|
import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@code /aero nozzle <pos> ...}: moves a vectored afterburner nozzle by hand, for testing it without the flight system.
|
||||||
|
* {@code deflection <degrees>}, {@code throttle <0..1>}, {@code afterburner <true|false>} and {@code right <true|false>}.
|
||||||
|
*/
|
||||||
|
public final class NozzleCommands {
|
||||||
|
private NozzleCommands() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LiteralArgumentBuilder<CommandSourceStack> node() {
|
||||||
|
return Commands.literal("nozzle").then(Commands.argument("pos", BlockPosArgument.blockPos())
|
||||||
|
.executes(context -> status(context.getSource(), BlockPosArgument.getLoadedBlockPos(context, "pos")))
|
||||||
|
.then(Commands.literal("deflection").then(Commands.argument("degrees", FloatArgumentType.floatArg(-90.0F, 90.0F))
|
||||||
|
.executes(context -> {
|
||||||
|
float degrees = FloatArgumentType.getFloat(context, "degrees");
|
||||||
|
return modify(context.getSource(), BlockPosArgument.getLoadedBlockPos(context, "pos"),
|
||||||
|
nozzle -> nozzle.setDeflectionTarget((float) Math.toRadians(degrees)));
|
||||||
|
})))
|
||||||
|
.then(Commands.literal("throttle").then(Commands.argument("throttle", FloatArgumentType.floatArg(0.0F, 1.0F))
|
||||||
|
.executes(context -> {
|
||||||
|
float throttle = FloatArgumentType.getFloat(context, "throttle");
|
||||||
|
return modify(context.getSource(), BlockPosArgument.getLoadedBlockPos(context, "pos"),
|
||||||
|
nozzle -> nozzle.setThrottle(throttle));
|
||||||
|
})))
|
||||||
|
.then(Commands.literal("afterburner").then(Commands.argument("on", BoolArgumentType.bool())
|
||||||
|
.executes(context -> {
|
||||||
|
boolean on = BoolArgumentType.getBool(context, "on");
|
||||||
|
return modify(context.getSource(), BlockPosArgument.getLoadedBlockPos(context, "pos"),
|
||||||
|
nozzle -> nozzle.setAfterburner(on));
|
||||||
|
})))
|
||||||
|
.then(Commands.literal("right").then(Commands.argument("right", BoolArgumentType.bool())
|
||||||
|
.executes(context -> {
|
||||||
|
boolean right = BoolArgumentType.getBool(context, "right");
|
||||||
|
return modify(context.getSource(), BlockPosArgument.getLoadedBlockPos(context, "pos"),
|
||||||
|
nozzle -> nozzle.setRightEngine(right));
|
||||||
|
}))));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int modify(CommandSourceStack source, BlockPos pos, Consumer<NozzleBlockEntity> change) {
|
||||||
|
if (!(source.getLevel().getBlockEntity(pos) instanceof NozzleBlockEntity nozzle)) {
|
||||||
|
source.sendFailure(Component.literal("There is no vectored afterburner nozzle at " + pos.toShortString()));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
change.accept(nozzle);
|
||||||
|
return status(source, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int status(CommandSourceStack source, BlockPos pos) {
|
||||||
|
if (!(source.getLevel().getBlockEntity(pos) instanceof NozzleBlockEntity nozzle)) {
|
||||||
|
source.sendFailure(Component.literal("There is no vectored afterburner nozzle at " + pos.toShortString()));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
source.sendSuccess(() -> Component.literal(String.format("Nozzle at %s: deflection %.1f deg, throttle %.2f, afterburner %s, %s engine",
|
||||||
|
pos.toShortString(), Math.toDegrees(nozzle.getDeflectionTarget()), nozzle.getThrottle(),
|
||||||
|
nozzle.isAfterburner() ? "on" : "off", nozzle.isRightEngine() ? "right" : "left")), false);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.exhaust;
|
||||||
|
|
||||||
|
import dev.lumareth.improvedAerodynamics.ImprovedAerodynamics;
|
||||||
|
import net.minecraft.core.registries.Registries;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.world.item.BlockItem;
|
||||||
|
import net.minecraft.world.item.CreativeModeTab;
|
||||||
|
import net.minecraft.world.item.Item;
|
||||||
|
import net.minecraft.world.level.block.Block;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
|
import net.minecraftforge.eventbus.api.IEventBus;
|
||||||
|
import net.minecraftforge.registries.DeferredRegister;
|
||||||
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
|
import net.minecraftforge.registries.RegistryObject;
|
||||||
|
|
||||||
|
/** Registry entries of the vectored afterburner nozzle. */
|
||||||
|
public final class NozzleContent {
|
||||||
|
private static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, ImprovedAerodynamics.MOD_ID);
|
||||||
|
private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, ImprovedAerodynamics.MOD_ID);
|
||||||
|
private static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITIES =
|
||||||
|
DeferredRegister.create(ForgeRegistries.BLOCK_ENTITY_TYPES, ImprovedAerodynamics.MOD_ID);
|
||||||
|
private static final DeferredRegister<CreativeModeTab> TABS =
|
||||||
|
DeferredRegister.create(Registries.CREATIVE_MODE_TAB, ImprovedAerodynamics.MOD_ID);
|
||||||
|
|
||||||
|
public static final RegistryObject<Block> NOZZLE = BLOCKS.register("vectored_afterburner_nozzle", NozzleBlock::new);
|
||||||
|
public static final RegistryObject<Item> NOZZLE_ITEM = ITEMS.register("vectored_afterburner_nozzle",
|
||||||
|
() -> new BlockItem(NOZZLE.get(), new Item.Properties()));
|
||||||
|
public static final RegistryObject<BlockEntityType<NozzleBlockEntity>> NOZZLE_ENTITY = BLOCK_ENTITIES.register("vectored_afterburner_nozzle",
|
||||||
|
() -> BlockEntityType.Builder.of(NozzleBlockEntity::new, NOZZLE.get()).build(null));
|
||||||
|
|
||||||
|
public static final RegistryObject<CreativeModeTab> TAB = TABS.register("main", () -> CreativeModeTab.builder()
|
||||||
|
.title(Component.translatable("itemGroup." + ImprovedAerodynamics.MOD_ID))
|
||||||
|
.icon(() -> NOZZLE_ITEM.get().getDefaultInstance())
|
||||||
|
.displayItems((parameters, output) -> output.accept(NOZZLE_ITEM.get()))
|
||||||
|
.build());
|
||||||
|
|
||||||
|
private NozzleContent() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void register(IEventBus modBus) {
|
||||||
|
BLOCKS.register(modBus);
|
||||||
|
ITEMS.register(modBus);
|
||||||
|
BLOCK_ENTITIES.register(modBus);
|
||||||
|
TABS.register(modBus);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.exhaust;
|
||||||
|
|
||||||
|
import dev.lumareth.improvedAerodynamics.flight.ControlAxis;
|
||||||
|
import dev.lumareth.improvedAerodynamics.flight.LiveInputs;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* What a nozzle reads from the vehicle control node it was linked to with Warium's linker, and how its two keys, set
|
||||||
|
* with Warium's two key configuration screen, are read. Either key can name any axis: Pitch+ means W raises the nose and
|
||||||
|
* Pitch- means S does, Roll+ or Roll- says which roll input rolls the plane right, Yaw+ or Yaw- which yaw input yaws it
|
||||||
|
* right. An axis no key names is off, except that a nozzle with no key at all pitches with W, and yaw follows D without
|
||||||
|
* a key. While the ship flies, the inputs are the ones the flight physics uses ({@link LiveInputs}), so the nozzles follow
|
||||||
|
* cursor aim and the flight computer like the control surfaces do.
|
||||||
|
*/
|
||||||
|
final class NozzleControl {
|
||||||
|
private static final ResourceLocation NODE_BLOCK = new ResourceLocation("valkyrien_warium", "vehicle_control_node");
|
||||||
|
|
||||||
|
/** The control node's state in node units: pitch, roll and yaw from -1 to 1, throttle from 0 to 10. Yaw needs no key, D is right. */
|
||||||
|
record Inputs(BlockEntity node, double pitchUp, double rollRight, double yawRight, double throttle, boolean afterburnerSwitch) {
|
||||||
|
}
|
||||||
|
|
||||||
|
private NozzleControl() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
static Inputs read(Level level, NozzleBlockEntity nozzle) {
|
||||||
|
CompoundTag own = nozzle.getPersistentData();
|
||||||
|
if (!own.contains("ControlX")) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
BlockPos nodePos = BlockPos.containing(own.getDouble("ControlX"), own.getDouble("ControlY"), own.getDouble("ControlZ"));
|
||||||
|
if (!level.isLoaded(nodePos) || !ForgeRegistries.BLOCKS.getKey(level.getBlockState(nodePos).getBlock()).equals(NODE_BLOCK)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
BlockEntity node = level.getBlockEntity(nodePos);
|
||||||
|
if (node == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
CompoundTag tag = node.getPersistentData();
|
||||||
|
String key = own.getString("Key");
|
||||||
|
String key2 = own.getString("Key2");
|
||||||
|
boolean unset = (key.isEmpty() || key.equals("Null")) && (key2.isEmpty() || key2.equals("Null"));
|
||||||
|
long nodeKey = nodePos.asLong();
|
||||||
|
double pitch = clamp(LiveInputs.value(nodeKey, tag, ControlAxis.PITCH)) * sign(key, key2, "Pitch", unset ? 1.0 : 0.0);
|
||||||
|
double roll = clamp(LiveInputs.value(nodeKey, tag, ControlAxis.ROLL)) * sign(key, key2, "Roll", 0.0);
|
||||||
|
double yaw = clamp(LiveInputs.value(nodeKey, tag, ControlAxis.YAW)) * sign(key, key2, "Yaw", 1.0);
|
||||||
|
return new Inputs(node, pitch, roll, yaw, Math.max(0.0, tag.getDouble("Throttle")), tag.getBoolean(AfterburnerToggle.TAG));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** +1 for axis+, -1 for axis-, from the first key that names the axis, the fallback if neither does. */
|
||||||
|
private static double sign(String key, String key2, String axis, double fallback) {
|
||||||
|
for (String candidate : new String[]{key, key2}) {
|
||||||
|
if (candidate.equals(axis + "+")) {
|
||||||
|
return 1.0;
|
||||||
|
}
|
||||||
|
if (candidate.equals(axis + "-")) {
|
||||||
|
return -1.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double clamp(double value) {
|
||||||
|
return Math.max(-1.0, Math.min(1.0, value));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.exhaust;
|
||||||
|
|
||||||
|
import net.minecraft.core.Direction;
|
||||||
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
import org.joml.Quaternionf;
|
||||||
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Where the exhaust leaves the nozzle and which way it goes, in the block's own coordinates (ship coordinates on a
|
||||||
|
* ship). Matches the model: the nozzle sits in the north half of the block, tilted by the hinge bone and swung by the
|
||||||
|
* rotation bone, and the block is turned by its facing the way AzureLib turns the model.
|
||||||
|
*/
|
||||||
|
public final class NozzleGeometry {
|
||||||
|
/** Static tilt of the hinge bone around the thrust axis, in degrees, see the model. */
|
||||||
|
private static final float HINGE_TILT = 32.5F;
|
||||||
|
/** The right engine swings about the mirrored axis, so the same deflection turns the opposite way there. */
|
||||||
|
public static final float RIGHT_ENGINE_SIGN = -1.0F;
|
||||||
|
|
||||||
|
private NozzleGeometry() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Center of the nozzle exit, on the block face the exhaust leaves through. */
|
||||||
|
public static Vec3 exit(net.minecraft.core.BlockPos pos, Direction facing) {
|
||||||
|
return new Vec3(pos.getX() + 0.5 + facing.getStepX() * 0.5, pos.getY() + 0.5 + facing.getStepY() * 0.5,
|
||||||
|
pos.getZ() + 0.5 + facing.getStepZ() * 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit vector the exhaust moves along. At no deflection it is the facing, a deflection swings it around the axis the
|
||||||
|
* rotation bone turns about: the hinge's tilt applied to X for the left engine, to Y for the right one.
|
||||||
|
*/
|
||||||
|
public static Vec3 exhaustDirection(Direction facing, float deflection, boolean rightEngine) {
|
||||||
|
Vector3f swing = new Vector3f(0.0F, 0.0F, -1.0F);
|
||||||
|
swing.rotateAxis((rightEngine ? RIGHT_ENGINE_SIGN : 1.0F) * deflection, rightEngine ? 0.0F : 1.0F, rightEngine ? 1.0F : 0.0F, 0.0F);
|
||||||
|
// The deflection is about an axis turned by the hinge, the counter bone turns the nozzle back
|
||||||
|
swing.rotateZ((float) Math.toRadians(HINGE_TILT));
|
||||||
|
swing.rotate(facingRotation(facing));
|
||||||
|
return new Vec3(swing.x, swing.y, swing.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The turn AzureLib applies to a model for a block facing, from facing north. */
|
||||||
|
private static Quaternionf facingRotation(Direction facing) {
|
||||||
|
Quaternionf rotation = new Quaternionf();
|
||||||
|
switch (facing) {
|
||||||
|
case SOUTH -> rotation.rotateY((float) Math.toRadians(180));
|
||||||
|
case WEST -> rotation.rotateY((float) Math.toRadians(90));
|
||||||
|
case EAST -> rotation.rotateY((float) Math.toRadians(270));
|
||||||
|
case UP -> rotation.rotateX((float) Math.toRadians(90));
|
||||||
|
case DOWN -> rotation.rotateX((float) Math.toRadians(-90));
|
||||||
|
default -> {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rotation;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.exhaust;
|
||||||
|
|
||||||
|
import dev.lumareth.improvedAerodynamics.Config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Turns pilot inputs into the deflection of one nozzle of a twin engine craft: the same sign on both engines pitches,
|
||||||
|
* opposite signs roll and yaw. The nozzles hinge on canted axes, so deflecting them against each other turns the exhaust
|
||||||
|
* sideways as well as up and down: the vertical parts make a rolling moment, the sideways parts push the tail around.
|
||||||
|
* That coupling is how an Su-57 yaws with its nozzles, so roll and yaw share the one differential channel. Positive
|
||||||
|
* deflection always means the exhaust swings up, on both sides. Not tied to any input source, whatever drives the
|
||||||
|
* nozzles calls this and then {@link NozzleBlockEntity#setDeflectionTarget}.
|
||||||
|
*/
|
||||||
|
public final class NozzleMixing {
|
||||||
|
private NozzleMixing() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param pitchUp -1 to 1, positive raises the nose, which takes the exhaust up
|
||||||
|
* @param rollRight -1 to 1, positive rolls the plane right, which takes the right engine's exhaust up and the left one's down
|
||||||
|
* @param yawRight -1 to 1, positive yaws the nose right. The left engine's exhaust swings up and the right one's down,
|
||||||
|
* which for this model's canting turns both sideways to the left and pushes the tail left
|
||||||
|
* @return target deflection in radians, within the configured limit
|
||||||
|
*/
|
||||||
|
public static float deflection(float pitchUp, float rollRight, float yawRight, boolean rightEngine) {
|
||||||
|
float differential = rollRight - yawRight * Config.NOZZLE_YAW_MIX.get().floatValue();
|
||||||
|
float mixed = Math.max(-1.0F, Math.min(1.0F, pitchUp + (rightEngine ? differential : -differential)));
|
||||||
|
return mixed * (float) Math.toRadians(Config.NOZZLE_MAX_DEFLECTION.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,144 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.exhaust.client;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||||
|
import dev.lumareth.improvedAerodynamics.Config;
|
||||||
|
import dev.lumareth.improvedAerodynamics.ImprovedAerodynamics;
|
||||||
|
import dev.lumareth.improvedAerodynamics.exhaust.ImprovedExhaust;
|
||||||
|
import dev.lumareth.improvedAerodynamics.network.ExhaustPacket;
|
||||||
|
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.renderer.MultiBufferSource;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
|
import net.minecraftforge.client.event.RenderLevelStageEvent;
|
||||||
|
import net.minecraftforge.event.TickEvent;
|
||||||
|
import net.minecraftforge.event.level.LevelEvent;
|
||||||
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
import org.joml.Matrix4dc;
|
||||||
|
import org.joml.Quaternionf;
|
||||||
|
import org.joml.Vector3d;
|
||||||
|
import org.joml.Vector3f;
|
||||||
|
import org.valkyrienskies.core.api.ships.ClientShip;
|
||||||
|
import org.valkyrienskies.mod.common.VSGameUtilsKt;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The flames of Warium's jet exhausts in the improved style. The server says which exhausts burn, see {@code ExhaustSync},
|
||||||
|
* and each stays alive on the client for a few ticks after its last message, fading out. They are drawn after the
|
||||||
|
* particles, in the world, on ships with the ship's interpolated transform, and give off their particles here.
|
||||||
|
*/
|
||||||
|
@Mod.EventBusSubscriber(modid = ImprovedAerodynamics.MOD_ID, value = Dist.CLIENT)
|
||||||
|
public final class ExhaustFlames {
|
||||||
|
private static final int LIFETIME_TICKS = 10;
|
||||||
|
private static final int FADE_TICKS = 4;
|
||||||
|
|
||||||
|
private record Flame(BlockPos pos, Vec3 exit, Vec3 direction, float intensity, boolean afterburner, long expires) {
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Long2ObjectOpenHashMap<Flame> FLAMES = new Long2ObjectOpenHashMap<>();
|
||||||
|
|
||||||
|
private static boolean announced;
|
||||||
|
|
||||||
|
private ExhaustFlames() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void accept(ExhaustPacket packet) {
|
||||||
|
Level level = Minecraft.getInstance().level;
|
||||||
|
if (level == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!announced) {
|
||||||
|
announced = true;
|
||||||
|
ImprovedAerodynamics.LOGGER.info("Received the first improved exhaust flame, at {}", packet.pos().toShortString());
|
||||||
|
}
|
||||||
|
Vec3 exit = packet.exitOffset().add(packet.pos().getX(), packet.pos().getY(), packet.pos().getZ());
|
||||||
|
FLAMES.put(packet.pos().asLong(), new Flame(packet.pos(), exit, packet.direction(), packet.intensity() / 100.0F,
|
||||||
|
packet.afterburner(), level.getGameTime() + LIFETIME_TICKS));
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onClientTick(TickEvent.ClientTickEvent event) {
|
||||||
|
Level level = Minecraft.getInstance().level;
|
||||||
|
if (event.phase != TickEvent.Phase.END || level == null || FLAMES.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!ImprovedExhaust.isImproved()) {
|
||||||
|
FLAMES.clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
boolean particles = Config.NOZZLE_PARTICLES.get();
|
||||||
|
Iterator<Flame> iterator = FLAMES.values().iterator();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
Flame flame = iterator.next();
|
||||||
|
if (level.getGameTime() > flame.expires()) {
|
||||||
|
iterator.remove();
|
||||||
|
} else if (particles) {
|
||||||
|
Vec3 world = transform(level, flame.pos(), flame.exit(), false, 1.0F);
|
||||||
|
Vec3 direction = transform(level, flame.pos(), flame.direction(), true, 1.0F);
|
||||||
|
ExhaustParticles.emit(level, world, direction, flame.intensity(), flame.afterburner());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onRenderLevel(RenderLevelStageEvent event) {
|
||||||
|
Level level = Minecraft.getInstance().level;
|
||||||
|
if (event.getStage() != RenderLevelStageEvent.Stage.AFTER_PARTICLES || level == null || FLAMES.isEmpty()
|
||||||
|
|| !ImprovedExhaust.isImproved()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
float partialTick = event.getPartialTick();
|
||||||
|
Vec3 camera = event.getCamera().getPosition();
|
||||||
|
MultiBufferSource.BufferSource buffers = Minecraft.getInstance().renderBuffers().bufferSource();
|
||||||
|
VertexConsumer buffer = buffers.getBuffer(FlameRenderer.RENDER_TYPE);
|
||||||
|
for (Flame flame : FLAMES.values()) {
|
||||||
|
// Only afterburners burn with the big flame, dry thrust is smoke
|
||||||
|
if (!flame.afterburner()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
float fade = Math.min(1.0F, (flame.expires() - level.getGameTime() + partialTick) / FADE_TICKS);
|
||||||
|
Vec3 exit = transform(level, flame.pos(), flame.exit(), false, partialTick);
|
||||||
|
Vec3 direction = transform(level, flame.pos(), flame.direction(), true, partialTick);
|
||||||
|
|
||||||
|
PoseStack poseStack = event.getPoseStack();
|
||||||
|
poseStack.pushPose();
|
||||||
|
poseStack.translate(exit.x - camera.x, exit.y - camera.y, exit.z - camera.z);
|
||||||
|
poseStack.mulPose(new Quaternionf().rotationTo(new Vector3f(0.0F, 0.0F, -1.0F),
|
||||||
|
new Vector3f((float) direction.x, (float) direction.y, (float) direction.z)));
|
||||||
|
PoseStack.Pose pose = poseStack.last();
|
||||||
|
FlameRenderer.draw(buffer, pose.pose(), pose.normal(), 0.0F, 0.0F, 0.0F, flame.intensity(),
|
||||||
|
level.getGameTime() + partialTick, Math.max(0.0F, fade));
|
||||||
|
poseStack.popPose();
|
||||||
|
}
|
||||||
|
buffers.endBatch(FlameRenderer.RENDER_TYPE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onLevelUnload(LevelEvent.Unload event) {
|
||||||
|
if (event.getLevel().isClientSide()) {
|
||||||
|
FLAMES.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A position or direction in the block's coordinates as one in the world, differs on a ship. */
|
||||||
|
private static Vec3 transform(Level level, BlockPos pos, Vec3 vector, boolean direction, float partialTick) {
|
||||||
|
var ship = VSGameUtilsKt.getShipManagingPos(level, pos);
|
||||||
|
if (ship == null) {
|
||||||
|
return vector;
|
||||||
|
}
|
||||||
|
Matrix4dc shipToWorld = ship instanceof ClientShip client && partialTick != 1.0F ? client.getRenderTransform().getShipToWorld()
|
||||||
|
: ship.getShipToWorld();
|
||||||
|
Vector3d result = new Vector3d(vector.x, vector.y, vector.z);
|
||||||
|
if (direction) {
|
||||||
|
shipToWorld.transformDirection(result);
|
||||||
|
} else {
|
||||||
|
shipToWorld.transformPosition(result);
|
||||||
|
}
|
||||||
|
return new Vec3(result.x, result.y, result.z);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.exhaust.client;
|
||||||
|
|
||||||
|
import net.minecraft.core.particles.ParticleOptions;
|
||||||
|
import net.minecraft.core.particles.ParticleTypes;
|
||||||
|
import net.minecraft.util.RandomSource;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
|
||||||
|
/** The particles of a jet exhaust in the improved style, for the nozzle and for Warium's exhausts alike. */
|
||||||
|
final class ExhaustParticles {
|
||||||
|
private ExhaustParticles() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param exit where the exhaust leaves, in the world
|
||||||
|
* @param direction unit vector the exhaust moves along, in the world
|
||||||
|
* @param intensity 0 to 1
|
||||||
|
*/
|
||||||
|
static void emit(Level level, Vec3 exit, Vec3 direction, float intensity, boolean afterburner) {
|
||||||
|
RandomSource random = level.getRandom();
|
||||||
|
if (afterburner) {
|
||||||
|
// A hot plume: fire, a blue core and a heavy smoke trail behind it
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
spawn(level, random, ParticleTypes.FLAME, exit, direction, 0.8 + 1.4 * intensity, 0.1);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < 2; i++) {
|
||||||
|
spawn(level, random, ParticleTypes.SOUL_FIRE_FLAME, exit, direction, 1.2 + 1.6 * intensity, 0.03);
|
||||||
|
}
|
||||||
|
spawn(level, random, ParticleTypes.LARGE_SMOKE, exit, direction, 0.7 + 0.9 * intensity, 0.12);
|
||||||
|
if (random.nextFloat() < 0.4F) {
|
||||||
|
spawn(level, random, ParticleTypes.CAMPFIRE_COSY_SMOKE, exit, direction, 0.5, 0.15);
|
||||||
|
}
|
||||||
|
} else if (random.nextFloat() < intensity) {
|
||||||
|
spawn(level, random, ParticleTypes.LARGE_SMOKE, exit, direction, 0.4 + 0.6 * intensity, 0.06);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void spawn(Level level, RandomSource random, ParticleOptions type, Vec3 position, Vec3 direction, double speed, double spread) {
|
||||||
|
level.addParticle(type, position.x + (random.nextDouble() - 0.5) * 0.3, position.y + (random.nextDouble() - 0.5) * 0.3,
|
||||||
|
position.z + (random.nextDouble() - 0.5) * 0.3,
|
||||||
|
direction.x * speed + (random.nextDouble() - 0.5) * spread, direction.y * speed + (random.nextDouble() - 0.5) * spread,
|
||||||
|
direction.z * speed + (random.nextDouble() - 0.5) * spread);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.exhaust.client;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||||
|
import net.minecraft.client.renderer.LightTexture;
|
||||||
|
import net.minecraft.client.renderer.RenderType;
|
||||||
|
import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import org.joml.Matrix3f;
|
||||||
|
import org.joml.Matrix4f;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The afterburner flame: glowing cones with a dull red halo, an orange body, a yellow middle and a blue-white core,
|
||||||
|
* shock diamonds along the axis like a real afterburner and a bright glow at the exit. Length and brightness follow the
|
||||||
|
* throttle and everything flickers. They use the plain white texture and vertex colors, so no model is needed. The flame
|
||||||
|
* points along -Z from the origin it is drawn at, the caller turns and places it.
|
||||||
|
*/
|
||||||
|
final class FlameRenderer {
|
||||||
|
static final RenderType RENDER_TYPE = RenderType.entityTranslucentEmissive(new ResourceLocation("textures/misc/white.png"));
|
||||||
|
// Radius at the base, and length range
|
||||||
|
private static final float BASE_RADIUS = 0.4F;
|
||||||
|
private static final float MIN_LENGTH = 1.8F;
|
||||||
|
private static final float LENGTH_RANGE = 4.5F;
|
||||||
|
private static final int PLANES = 3;
|
||||||
|
private static final int DIAMONDS = 5;
|
||||||
|
// Radius factor, length factor, red, green, blue, alpha at the base
|
||||||
|
private static final float[][] CONES = {
|
||||||
|
{1.45F, 1.10F, 1.00F, 0.25F, 0.05F, 0.22F},
|
||||||
|
{1.00F, 1.00F, 1.00F, 0.45F, 0.10F, 0.55F},
|
||||||
|
{0.70F, 0.82F, 1.00F, 0.75F, 0.30F, 0.75F},
|
||||||
|
{0.38F, 0.58F, 0.85F, 0.92F, 1.00F, 0.95F},
|
||||||
|
};
|
||||||
|
|
||||||
|
private FlameRenderer() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param origin where the flame starts, in the space of the matrix
|
||||||
|
* @param throttle 0 to 1, how long and bright the flame is
|
||||||
|
* @param time ticks with partial tick, drives the flicker
|
||||||
|
* @param fade 0 to 1, extra brightness factor for flames that are dying down
|
||||||
|
*/
|
||||||
|
static void draw(VertexConsumer buffer, Matrix4f matrix, Matrix3f normal, float originX, float originY, float originZ,
|
||||||
|
float throttle, float time, float fade) {
|
||||||
|
float flicker = 0.9F + 0.07F * (float) Math.sin(time * 1.9F) + 0.05F * (float) Math.sin(time * 4.3F + 1.0F)
|
||||||
|
+ 0.03F * (float) Math.sin(time * 9.1F);
|
||||||
|
float length = (MIN_LENGTH + LENGTH_RANGE * throttle) * flicker * (0.4F + 0.6F * fade);
|
||||||
|
float brightness = (0.55F + 0.45F * throttle) * fade;
|
||||||
|
Draw draw = new Draw(buffer, matrix, normal, originX, originY);
|
||||||
|
|
||||||
|
for (float[] cone : CONES) {
|
||||||
|
float pulse = 1.0F + 0.06F * (float) Math.sin(time * 5.0F + cone[0] * 7.0F);
|
||||||
|
draw.cone(originZ, originZ - length * cone[1], BASE_RADIUS * cone[0] * pulse,
|
||||||
|
cone[2], cone[3], cone[4], Math.min(1.0F, cone[5] * brightness));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Shock diamonds: two cones back to back, spaced along the flame, shrinking and pulsing
|
||||||
|
for (int i = 0; i < DIAMONDS; i++) {
|
||||||
|
float center = originZ - length * (0.14F + 0.15F * i);
|
||||||
|
float radius = BASE_RADIUS * 0.34F * (1.0F - 0.13F * i) * (0.85F + 0.15F * (float) Math.sin(time * 6.0F + i * 1.7F));
|
||||||
|
float half = length * 0.055F;
|
||||||
|
float alpha = Math.min(1.0F, 0.95F * brightness * (1.0F - 0.1F * i));
|
||||||
|
draw.cone(center, center - half, radius, 0.75F, 0.9F, 1.0F, alpha);
|
||||||
|
draw.cone(center, center + half, radius, 0.75F, 0.9F, 1.0F, alpha);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bright glow right at the exit
|
||||||
|
draw.cone(originZ, originZ - 0.35F, BASE_RADIUS * 0.9F, 1.0F, 0.95F, 0.8F, 0.9F * brightness);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The buffer and placement of one flame, so the cones only need to say where they are. */
|
||||||
|
private record Draw(VertexConsumer buffer, Matrix4f matrix, Matrix3f normal, float x, float y) {
|
||||||
|
/** A cone of {@code PLANES} crossed triangles from a base circle at baseZ to a point at tipZ. */
|
||||||
|
void cone(float baseZ, float tipZ, float radius, float red, float green, float blue, float baseAlpha) {
|
||||||
|
for (int plane = 0; plane < PLANES; plane++) {
|
||||||
|
double angle = Math.PI * plane / PLANES;
|
||||||
|
float dx = (float) Math.cos(angle) * radius;
|
||||||
|
float dy = (float) Math.sin(angle) * radius;
|
||||||
|
vertex(x - dx, y - dy, baseZ, red, green, blue, baseAlpha);
|
||||||
|
vertex(x + dx, y + dy, baseZ, red, green, blue, baseAlpha);
|
||||||
|
vertex(x, y, tipZ, red, green, blue, 0.0F);
|
||||||
|
vertex(x, y, tipZ, red, green, blue, 0.0F);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void vertex(float vx, float vy, float vz, float red, float green, float blue, float alpha) {
|
||||||
|
buffer.vertex(matrix, vx, vy, vz).color(red, green, blue, alpha).uv(0.5F, 0.5F)
|
||||||
|
.overlayCoords(OverlayTexture.NO_OVERLAY).uv2(LightTexture.FULL_BRIGHT).normal(normal, 0.0F, 0.0F, -1.0F).endVertex();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.exhaust.client;
|
||||||
|
|
||||||
|
import dev.lumareth.improvedAerodynamics.ImprovedAerodynamics;
|
||||||
|
import dev.lumareth.improvedAerodynamics.exhaust.NozzleBlockEntity;
|
||||||
|
import dev.lumareth.improvedAerodynamics.exhaust.NozzleGeometry;
|
||||||
|
import mod.azure.azurelib.animation.controller.AzAnimationController;
|
||||||
|
import mod.azure.azurelib.animation.controller.AzAnimationControllerContainer;
|
||||||
|
import mod.azure.azurelib.animation.impl.AzBlockAnimator;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Swings the nozzle. The model has no keyframes, the animation file is a stub the animator needs anyway; the rotation
|
||||||
|
* bone is set from code every frame, from its initial pose, so the angle can never drift.
|
||||||
|
*/
|
||||||
|
final class NozzleAnimator extends AzBlockAnimator<NozzleBlockEntity> {
|
||||||
|
static final ResourceLocation ANIMATION = new ResourceLocation(ImprovedAerodynamics.MOD_ID,
|
||||||
|
"animations/blockentities/nozzle.animation.json");
|
||||||
|
private static final String ROTATION_BONE = "rotation";
|
||||||
|
/**
|
||||||
|
* The left engine's nozzle swings about the model's X axis. The right one about Y, the axis that mirrors the hinge's
|
||||||
|
* tilt, and turns the opposite way for the same deflection, see {@link NozzleGeometry#RIGHT_ENGINE_SIGN}.
|
||||||
|
*/
|
||||||
|
private static final float LEFT_SIGN = 1.0F;
|
||||||
|
|
||||||
|
NozzleAnimator() {
|
||||||
|
super(mod.azure.azurelib.animation.AzAnimatorConfig.defaultConfig());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerControllers(AzAnimationControllerContainer<NozzleBlockEntity> container) {
|
||||||
|
container.add(AzAnimationController.builder(this, "base_controller").build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull ResourceLocation getAnimationLocation(NozzleBlockEntity animatable) {
|
||||||
|
return ANIMATION;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCustomAnimations(NozzleBlockEntity nozzle, float partialTicks) {
|
||||||
|
super.setCustomAnimations(nozzle, partialTicks);
|
||||||
|
var model = context().boneCache().getBakedModel();
|
||||||
|
var rotation = model != null ? model.getBoneOrNull(ROTATION_BONE) : null;
|
||||||
|
if (rotation == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
float theta = nozzle.getDeflection(partialTicks);
|
||||||
|
var initial = rotation.getInitialAzSnapshot();
|
||||||
|
if (nozzle.isRightEngine()) {
|
||||||
|
rotation.setRotY(initial.getRotY() + NozzleGeometry.RIGHT_ENGINE_SIGN * theta);
|
||||||
|
} else {
|
||||||
|
rotation.setRotX(initial.getRotX() + LEFT_SIGN * theta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+113
@@ -0,0 +1,113 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.exhaust.client;
|
||||||
|
|
||||||
|
import dev.lumareth.improvedAerodynamics.Config;
|
||||||
|
import dev.lumareth.improvedAerodynamics.exhaust.ImprovedExhaust;
|
||||||
|
import dev.lumareth.improvedAerodynamics.exhaust.NozzleBlockEntity;
|
||||||
|
import dev.lumareth.improvedAerodynamics.exhaust.NozzleGeometry;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.sounds.SoundEvent;
|
||||||
|
import net.minecraft.sounds.SoundSource;
|
||||||
|
import net.minecraft.util.RandomSource;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
|
import org.joml.Vector3d;
|
||||||
|
import org.valkyrienskies.mod.common.VSGameUtilsKt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Client side sound and particles of the nozzles. Only ever called on the logical client.
|
||||||
|
* <p>
|
||||||
|
* Sound is Warium's own: its jet engines have no looping sound either, they play a short blast again and again. The jet
|
||||||
|
* exhaust behind the nozzle does that, the nozzle adds the heavy blast for the afterburner. Nothing here runs in the
|
||||||
|
* wariumvs exhaust style.
|
||||||
|
*/
|
||||||
|
public final class NozzleClientEffects {
|
||||||
|
private static final SoundSource CATEGORY = SoundSource.BLOCKS;
|
||||||
|
private static final int HEAVY_BLAST_INTERVAL = 14;
|
||||||
|
|
||||||
|
/** What one nozzle has done so far on this client, kept on the block entity. */
|
||||||
|
private static final class State {
|
||||||
|
boolean wasAfterburner;
|
||||||
|
}
|
||||||
|
|
||||||
|
private NozzleClientEffects() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void tick(NozzleBlockEntity nozzle) {
|
||||||
|
Level level = nozzle.getLevel();
|
||||||
|
if (level == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
State state = (State) nozzle.getClientEffects();
|
||||||
|
if (state == null) {
|
||||||
|
state = new State();
|
||||||
|
state.wasAfterburner = nozzle.isAfterburner();
|
||||||
|
nozzle.setClientEffects(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ImprovedExhaust.isImproved()) {
|
||||||
|
// Warium's own effect, which comes from the exhaust behind the nozzle, is wanted
|
||||||
|
state.wasAfterburner = nozzle.isAfterburner();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (Config.NOZZLE_SOUND.get() && nozzle.isAfterburner()) {
|
||||||
|
playBlasts(level, nozzle, !state.wasAfterburner);
|
||||||
|
}
|
||||||
|
state.wasAfterburner = nozzle.isAfterburner();
|
||||||
|
|
||||||
|
if (Config.NOZZLE_PARTICLES.get() && nozzle.getThrottle() > 0.05F) {
|
||||||
|
emitParticles(level, nozzle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Nothing keeps running on the client, so there is nothing to stop but the remembered state. */
|
||||||
|
public static void stop(NozzleBlockEntity nozzle) {
|
||||||
|
nozzle.setClientEffects(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void playBlasts(Level level, NozzleBlockEntity nozzle, boolean ignition) {
|
||||||
|
RandomSource random = level.getRandom();
|
||||||
|
Vec3 exit = NozzleGeometry.exit(nozzle.getBlockPos(), nozzle.getFacing());
|
||||||
|
Vec3 position = toWorld(level, exit.add(NozzleGeometry.exhaustDirection(nozzle.getFacing(), 0.0F, false).scale(4.0)));
|
||||||
|
long time = level.getGameTime() + nozzle.getBlockPos().hashCode();
|
||||||
|
// Warium's jet exhaust behind the nozzle already plays the engine blast, the afterburner adds the heavy one
|
||||||
|
if (ignition || time % HEAVY_BLAST_INTERVAL == 0) {
|
||||||
|
play(level, "heavyjetblast", position, ignition ? 30.0F : 18.0F, (float) (0.95 + random.nextDouble() * 0.1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Plays one of Warium's sounds, nothing if Warium is not installed. */
|
||||||
|
private static void play(Level level, String name, Vec3 position, float volume, float pitch) {
|
||||||
|
SoundEvent sound = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("valkyrien_warium", name));
|
||||||
|
if (sound != null) {
|
||||||
|
level.playLocalSound(position.x, position.y, position.z, sound, CATEGORY, volume, pitch, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void emitParticles(Level level, NozzleBlockEntity nozzle) {
|
||||||
|
Vec3 exit = NozzleGeometry.exit(nozzle.getBlockPos(), nozzle.getFacing());
|
||||||
|
Vec3 direction = NozzleGeometry.exhaustDirection(nozzle.getFacing(), nozzle.getDeflection(1.0F), nozzle.isRightEngine());
|
||||||
|
ExhaustParticles.emit(level, toWorld(level, exit), toWorldDirection(level, nozzle.getBlockPos(), direction),
|
||||||
|
nozzle.getThrottle(), nozzle.isAfterburner());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A position in the block's coordinates as a position in the world, differs on a ship. */
|
||||||
|
public static Vec3 toWorld(Level level, Vec3 position) {
|
||||||
|
var ship = VSGameUtilsKt.getShipManagingPos(level, position.x, position.y, position.z);
|
||||||
|
if (ship == null) {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
Vector3d world = ship.getShipToWorld().transformPosition(new Vector3d(position.x, position.y, position.z));
|
||||||
|
return new Vec3(world.x, world.y, world.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Vec3 toWorldDirection(Level level, BlockPos pos, Vec3 direction) {
|
||||||
|
var ship = VSGameUtilsKt.getShipManagingPos(level, pos);
|
||||||
|
if (ship == null) {
|
||||||
|
return direction;
|
||||||
|
}
|
||||||
|
Vector3d world = ship.getShipToWorld().transformDirection(new Vector3d(direction.x, direction.y, direction.z));
|
||||||
|
return new Vec3(world.x, world.y, world.z);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.exhaust.client;
|
||||||
|
|
||||||
|
import dev.lumareth.improvedAerodynamics.ImprovedAerodynamics;
|
||||||
|
import dev.lumareth.improvedAerodynamics.exhaust.NozzleContent;
|
||||||
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
|
import net.minecraftforge.client.event.EntityRenderersEvent;
|
||||||
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
|
import net.minecraftforge.fml.ModList;
|
||||||
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
|
||||||
|
/** Registers the nozzle's AzureLib renderer, if AzureLib is installed. */
|
||||||
|
@Mod.EventBusSubscriber(modid = ImprovedAerodynamics.MOD_ID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||||
|
public final class NozzleClientSetup {
|
||||||
|
private NozzleClientSetup() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onRegisterRenderers(EntityRenderersEvent.RegisterRenderers event) {
|
||||||
|
if (!ModList.get().isLoaded("azurelib")) {
|
||||||
|
ImprovedAerodynamics.LOGGER.warn("AzureLib is not installed, the vectored afterburner nozzle will be invisible");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
event.registerBlockEntityRenderer(NozzleContent.NOZZLE_ENTITY.get(), context -> new NozzleRenderer());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.exhaust.client;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||||
|
import dev.lumareth.improvedAerodynamics.exhaust.ImprovedExhaust;
|
||||||
|
import dev.lumareth.improvedAerodynamics.exhaust.NozzleBlockEntity;
|
||||||
|
import mod.azure.azurelib.model.AzBone;
|
||||||
|
import mod.azure.azurelib.render.AzRendererPipelineContext;
|
||||||
|
import mod.azure.azurelib.render.layer.AzRenderLayer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The afterburner flame of the nozzle, drawn in the space of the nozzle's last bone so it swings with the nozzle, see
|
||||||
|
* {@link FlameRenderer}.
|
||||||
|
*/
|
||||||
|
final class NozzleFlameLayer implements AzRenderLayer<Long, NozzleBlockEntity> {
|
||||||
|
private static final String NOZZLE_BONE = "counter";
|
||||||
|
// The middle of the nozzle exit in the model's own coordinates, in blocks
|
||||||
|
private static final float EXIT_X = 0.5F;
|
||||||
|
private static final float EXIT_Y = 0.5F;
|
||||||
|
private static final float EXIT_Z = 0.0F;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void preRender(AzRendererPipelineContext<Long, NozzleBlockEntity> context) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(AzRendererPipelineContext<Long, NozzleBlockEntity> context) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renderForBone(AzRendererPipelineContext<Long, NozzleBlockEntity> context, AzBone bone) {
|
||||||
|
NozzleBlockEntity nozzle = context.animatable();
|
||||||
|
if (!NOZZLE_BONE.equals(bone.getName()) || !nozzle.isAfterburner() || nozzle.getLevel() == null
|
||||||
|
|| !ImprovedExhaust.isImproved()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PoseStack.Pose pose = context.poseStack().last();
|
||||||
|
VertexConsumer buffer = context.multiBufferSource().getBuffer(FlameRenderer.RENDER_TYPE);
|
||||||
|
FlameRenderer.draw(buffer, pose.pose(), pose.normal(), EXIT_X, EXIT_Y, EXIT_Z, nozzle.getThrottle(),
|
||||||
|
nozzle.getLevel().getGameTime() + context.partialTick(), 1.0F);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean sortsTranslucency() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.exhaust.client;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
import dev.lumareth.improvedAerodynamics.exhaust.NozzleBlockEntity;
|
||||||
|
import mod.azure.azurelib.render.AzLayerRenderer;
|
||||||
|
import mod.azure.azurelib.render.block.AzBlockEntityModelRenderer;
|
||||||
|
import mod.azure.azurelib.render.block.AzBlockEntityRendererPipeline;
|
||||||
|
import net.minecraft.core.Direction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AzureLib puts the middle of its models on the middle of the block, the nozzle model is built in the 0 to 16 range of
|
||||||
|
* the block, so it is moved back by half a block after the block is turned to its facing.
|
||||||
|
*/
|
||||||
|
final class NozzleModelRenderer extends AzBlockEntityModelRenderer<NozzleBlockEntity> {
|
||||||
|
NozzleModelRenderer(AzBlockEntityRendererPipeline<NozzleBlockEntity> pipeline, AzLayerRenderer<Long, NozzleBlockEntity> layerRenderer) {
|
||||||
|
super(pipeline, layerRenderer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void rotateBlock(Direction facing, PoseStack poseStack) {
|
||||||
|
super.rotateBlock(facing, poseStack);
|
||||||
|
poseStack.translate(-0.5, 0.0, -0.5);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.exhaust.client;
|
||||||
|
|
||||||
|
import dev.lumareth.improvedAerodynamics.ImprovedAerodynamics;
|
||||||
|
import dev.lumareth.improvedAerodynamics.exhaust.NozzleBlockEntity;
|
||||||
|
import mod.azure.azurelib.render.block.AzBlockEntityRenderer;
|
||||||
|
import mod.azure.azurelib.render.block.AzBlockEntityRendererConfig;
|
||||||
|
import mod.azure.azurelib.render.block.AzBlockEntityRendererPipeline;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
|
/** Draws the vectored afterburner nozzle with AzureLib. */
|
||||||
|
final class NozzleRenderer extends AzBlockEntityRenderer<NozzleBlockEntity> {
|
||||||
|
private static final ResourceLocation MODEL = new ResourceLocation(ImprovedAerodynamics.MOD_ID,
|
||||||
|
"geo/blockentities/vectored_afterburner_nozzle.geo.json");
|
||||||
|
private static final ResourceLocation TEXTURE = new ResourceLocation(ImprovedAerodynamics.MOD_ID,
|
||||||
|
"textures/blockentities/jetexausttexture.png");
|
||||||
|
|
||||||
|
NozzleRenderer() {
|
||||||
|
super(AzBlockEntityRendererConfig.<NozzleBlockEntity>builder(MODEL, TEXTURE)
|
||||||
|
.setAnimatorProvider(NozzleAnimator::new)
|
||||||
|
.setModelRenderer((pipeline, layerRenderer) ->
|
||||||
|
new NozzleModelRenderer((AzBlockEntityRendererPipeline<NozzleBlockEntity>) pipeline, layerRenderer))
|
||||||
|
.addRenderLayer(new NozzleFlameLayer())
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,6 +27,8 @@ public final class AeroState implements PhysicsBridge.Publishable {
|
|||||||
private static final double INPUT_RATE_PER_TICK = 0.2;
|
private static final double INPUT_RATE_PER_TICK = 0.2;
|
||||||
private static final double VELOCITY_EPSILON = 0.05;
|
private static final double VELOCITY_EPSILON = 0.05;
|
||||||
private static final double ANGULAR_EPSILON = 0.005;
|
private static final double ANGULAR_EPSILON = 0.005;
|
||||||
|
// Time constant of the smoothing of measured control rates
|
||||||
|
private static final double RATE_SMOOTHING_SECONDS = 0.3;
|
||||||
private static final ControlAxis[] MEASURED_AXES = {ControlAxis.PITCH, ControlAxis.YAW, ControlAxis.ROLL};
|
private static final ControlAxis[] MEASURED_AXES = {ControlAxis.PITCH, ControlAxis.YAW, ControlAxis.ROLL};
|
||||||
|
|
||||||
private final SubstepClock clock;
|
private final SubstepClock clock;
|
||||||
@@ -41,7 +43,12 @@ public final class AeroState implements PhysicsBridge.Publishable {
|
|||||||
private Frame current;
|
private Frame current;
|
||||||
private boolean[] stalled = new boolean[0];
|
private boolean[] stalled = new boolean[0];
|
||||||
private boolean wingStalled;
|
private boolean wingStalled;
|
||||||
|
// Lift the wings could make at the edge of the stall in the airflow of the last substep, NaN without the improved
|
||||||
|
// flight model, which has no stall
|
||||||
|
private double maxLift = Double.NaN;
|
||||||
private final Map<Long, NodeState> nodeStates = new ConcurrentHashMap<>();
|
private final Map<Long, NodeState> nodeStates = new ConcurrentHashMap<>();
|
||||||
|
// Every ship's node states by node position, for the control surface animation on the server thread
|
||||||
|
private static final Map<Long, NodeState> ALL_NODE_STATES = new ConcurrentHashMap<>();
|
||||||
private final Wrench wrench = new Wrench();
|
private final Wrench wrench = new Wrench();
|
||||||
private final Wrench probe = new Wrench();
|
private final Wrench probe = new Wrench();
|
||||||
|
|
||||||
@@ -55,6 +62,10 @@ public final class AeroState implements PhysicsBridge.Publishable {
|
|||||||
double roll;
|
double roll;
|
||||||
double trimIntegral;
|
double trimIntegral;
|
||||||
double trimOutput;
|
double trimOutput;
|
||||||
|
// Deflection of this node's flaps in radians, moves towards what the flap lever and airspeed allow
|
||||||
|
double flapAngle;
|
||||||
|
// Wall clock time of the last physics substep that ran this node, to tell whether its ship is flying
|
||||||
|
volatile long updatedMillis;
|
||||||
// Total pitch input the flight computer applied last substep, pilot and trim together
|
// Total pitch input the flight computer applied last substep, pilot and trim together
|
||||||
double computerOutput;
|
double computerOutput;
|
||||||
// Torque (ship axes) one unit of pitch input on this node's pitch surfaces makes, measured every substep
|
// Torque (ship axes) one unit of pitch input on this node's pitch surfaces makes, measured every substep
|
||||||
@@ -65,6 +76,17 @@ public final class AeroState implements PhysicsBridge.Publishable {
|
|||||||
final Vector3d yawResponseBuilding = new Vector3d();
|
final Vector3d yawResponseBuilding = new Vector3d();
|
||||||
final Vector3d rollResponse = new Vector3d();
|
final Vector3d rollResponse = new Vector3d();
|
||||||
final Vector3d rollResponseBuilding = new Vector3d();
|
final Vector3d rollResponseBuilding = new Vector3d();
|
||||||
|
// Fastest steady pitch rate (rad/s) the pitch surfaces can hold against the craft's pitch damping, smoothed,
|
||||||
|
// measured while cursor aim flies the node. NaN until measured
|
||||||
|
double controlRate = Double.NaN;
|
||||||
|
// Cursor aim is rolling the craft over to reach a cursor far below the nose
|
||||||
|
boolean reversing;
|
||||||
|
// Share of the pull cursor aim keeps, eased down while the wings are stalled
|
||||||
|
double stallEase = 1.0;
|
||||||
|
// Which way pitch and yaw input turn the craft (+1 or -1 for nose up and nose right), learned from the measured
|
||||||
|
// responses. Until then Warium's keys: W (Pitch+) is usually nose down, D (Yaw+) nose right
|
||||||
|
double pitchSign = -1.0;
|
||||||
|
double yawSign = 1.0;
|
||||||
final AutoTrim.Targets trimTargets = new AutoTrim.Targets();
|
final AutoTrim.Targets trimTargets = new AutoTrim.Targets();
|
||||||
volatile double savedTrim;
|
volatile double savedTrim;
|
||||||
|
|
||||||
@@ -84,6 +106,7 @@ public final class AeroState implements PhysicsBridge.Publishable {
|
|||||||
trimOutput = data.autoTrim() ? 0.0 : trimIntegral;
|
trimOutput = data.autoTrim() ? 0.0 : trimIntegral;
|
||||||
savedTrim = trimIntegral;
|
savedTrim = trimIntegral;
|
||||||
computerOutput = pitch + trimOutput;
|
computerOutput = pitch + trimOutput;
|
||||||
|
flapAngle = Math.toRadians(FlapSetting.of(data.flapSetting()).degrees());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,9 +171,14 @@ public final class AeroState implements PhysicsBridge.Publishable {
|
|||||||
double dt = clock.substepSeconds();
|
double dt = clock.substepSeconds();
|
||||||
boolean improved = Config.IMPROVED_FLIGHT_MODEL.get();
|
boolean improved = Config.IMPROVED_FLIGHT_MODEL.get();
|
||||||
Matrix3dc inertia = ship.getMomentOfInertia();
|
Matrix3dc inertia = ship.getMomentOfInertia();
|
||||||
|
// Same frames and scaling as Warium applies its forces in
|
||||||
|
double scale = transform.getShipToWorldScaling().x();
|
||||||
|
double forceScale = autoScale ? scale * scale * scale : 1.0;
|
||||||
|
double liftAcceleration = maxLift * forceScale / ship.getMass();
|
||||||
|
|
||||||
updateNodes(frame, worldVelocity, transform.getPositionInWorld().y(), rotation, inertia, w, dt, improved);
|
updateNodes(frame, worldVelocity, transform.getPositionInWorld().y(), rotation, inertia, w, dt, improved, liftAcceleration);
|
||||||
evaluate(frame, centerOfMass, v, w, improved, true, wrench);
|
evaluate(frame, centerOfMass, v, w, improved, true, wrench);
|
||||||
|
measureControlRates(frame, centerOfMass, v, w, improved, dt);
|
||||||
|
|
||||||
if (Config.IMPLICIT_DAMPING.get()) {
|
if (Config.IMPLICIT_DAMPING.get()) {
|
||||||
// Implicit Euler for the damping part: scale each axis by 1 / (1 + dt * damping / inertia), using the
|
// Implicit Euler for the damping part: scale each axis by 1 / (1 + dt * damping / inertia), using the
|
||||||
@@ -177,9 +205,6 @@ public final class AeroState implements PhysicsBridge.Publishable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Same frames and scaling as Warium applies its forces in
|
|
||||||
double scale = transform.getShipToWorldScaling().x();
|
|
||||||
double forceScale = autoScale ? scale * scale * scale : 1.0;
|
|
||||||
Vector3d force = new Vector3d(wrench.force[0], wrench.force[1], wrench.force[2]).mul(forceScale);
|
Vector3d force = new Vector3d(wrench.force[0], wrench.force[1], wrench.force[2]).mul(forceScale);
|
||||||
Vector3d forceTorque = new Vector3d(wrench.forceTorque[0], wrench.forceTorque[1], wrench.forceTorque[2]).mul(forceScale);
|
Vector3d forceTorque = new Vector3d(wrench.forceTorque[0], wrench.forceTorque[1], wrench.forceTorque[2]).mul(forceScale);
|
||||||
if (force.isFinite() && forceTorque.isFinite()) {
|
if (force.isFinite() && forceTorque.isFinite()) {
|
||||||
@@ -206,9 +231,15 @@ public final class AeroState implements PhysicsBridge.Publishable {
|
|||||||
for (int i = 0; i < stalled.length; i++) {
|
for (int i = 0; i < stalled.length; i++) {
|
||||||
stalled[i] = previous.get(frame.surfaces[i].key());
|
stalled[i] = previous.get(frame.surfaces[i].key());
|
||||||
}
|
}
|
||||||
nodeStates.keySet().removeIf(key -> !frame.nodes.containsKey((long) key));
|
nodeStates.keySet().removeIf(key -> {
|
||||||
|
boolean gone = !frame.nodes.containsKey((long) key);
|
||||||
|
if (gone) {
|
||||||
|
ALL_NODE_STATES.remove(key);
|
||||||
|
}
|
||||||
|
return gone;
|
||||||
|
});
|
||||||
for (NodeData node : frame.nodes.values()) {
|
for (NodeData node : frame.nodes.values()) {
|
||||||
nodeStates.computeIfAbsent(node.key(), key -> new NodeState(node));
|
ALL_NODE_STATES.put(node.key(), nodeStates.computeIfAbsent(node.key(), key -> new NodeState(node)));
|
||||||
}
|
}
|
||||||
current = frame;
|
current = frame;
|
||||||
}
|
}
|
||||||
@@ -226,6 +257,7 @@ public final class AeroState implements PhysicsBridge.Publishable {
|
|||||||
double[] r = new double[3];
|
double[] r = new double[3];
|
||||||
if (commit) {
|
if (commit) {
|
||||||
wingStalled = false;
|
wingStalled = false;
|
||||||
|
maxLift = improved ? 0.0 : Double.NaN;
|
||||||
for (NodeState state : nodeStates.values()) {
|
for (NodeState state : nodeStates.values()) {
|
||||||
state.pitchResponseBuilding.zero();
|
state.pitchResponseBuilding.zero();
|
||||||
state.yawResponseBuilding.zero();
|
state.yawResponseBuilding.zero();
|
||||||
@@ -241,12 +273,16 @@ public final class AeroState implements PhysicsBridge.Publishable {
|
|||||||
NodeData node = s.node() != AeroSurface.NO_NODE ? frame.nodes.get(s.node()) : null;
|
NodeData node = s.node() != AeroSurface.NO_NODE ? frame.nodes.get(s.node()) : null;
|
||||||
NodeState state = node != null ? nodeStates.get(node.key()) : null;
|
NodeState state = node != null ? nodeStates.get(node.key()) : null;
|
||||||
double input = s.type().controllable ? input(s, node, state, ControlAxis.NONE, 0.0) : 0.0;
|
double input = s.type().controllable ? input(s, node, state, ControlAxis.NONE, 0.0) : 0.0;
|
||||||
|
double flap = s.flap() && state != null ? state.flapAngle : 0.0;
|
||||||
|
|
||||||
if (improved) {
|
if (improved) {
|
||||||
boolean nowStalled = ImprovedAero.evaluate(s, v, w, r, input, weight, tuning, stalled[i], out);
|
boolean nowStalled = ImprovedAero.evaluate(s, v, w, r, input, flap, weight, tuning, stalled[i], out);
|
||||||
if (commit) {
|
if (commit) {
|
||||||
stalled[i] = nowStalled;
|
stalled[i] = nowStalled;
|
||||||
wingStalled |= nowStalled && s.type() == SurfaceType.WING;
|
wingStalled |= nowStalled && s.type() == SurfaceType.WING;
|
||||||
|
if (s.type() == SurfaceType.WING || s.type() == SurfaceType.CONTROL_SURFACE && s.wingGroup()) {
|
||||||
|
maxLift += ImprovedAero.maxLift(s, v, w, r, flap, weight, tuning);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
WariumAero.evaluate(s, v, w, r, input, weight, out);
|
WariumAero.evaluate(s, v, w, r, input, weight, out);
|
||||||
@@ -263,7 +299,7 @@ public final class AeroState implements PhysicsBridge.Publishable {
|
|||||||
double delta = 0.05;
|
double delta = 0.05;
|
||||||
probe.clear();
|
probe.clear();
|
||||||
if (improved) {
|
if (improved) {
|
||||||
ImprovedAero.evaluate(s, v, w, r, input, weight, tuning, stalled[i], probe);
|
ImprovedAero.evaluate(s, v, w, r, input, flap, weight, tuning, stalled[i], probe);
|
||||||
} else {
|
} else {
|
||||||
WariumAero.evaluate(s, v, w, r, input, weight, probe);
|
WariumAero.evaluate(s, v, w, r, input, weight, probe);
|
||||||
}
|
}
|
||||||
@@ -271,7 +307,7 @@ public final class AeroState implements PhysicsBridge.Publishable {
|
|||||||
probe.clear();
|
probe.clear();
|
||||||
double nudged = input(s, node, state, axis, delta);
|
double nudged = input(s, node, state, axis, delta);
|
||||||
if (improved) {
|
if (improved) {
|
||||||
ImprovedAero.evaluate(s, v, w, r, nudged, weight, tuning, stalled[i], probe);
|
ImprovedAero.evaluate(s, v, w, r, nudged, flap, weight, tuning, stalled[i], probe);
|
||||||
} else {
|
} else {
|
||||||
WariumAero.evaluate(s, v, w, r, nudged, weight, probe);
|
WariumAero.evaluate(s, v, w, r, nudged, weight, probe);
|
||||||
}
|
}
|
||||||
@@ -292,6 +328,37 @@ public final class AeroState implements PhysicsBridge.Publishable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For every node cursor aim flies: the steady pitch rate its pitch surfaces can hold, full deflection torque over
|
||||||
|
* the craft's pitch damping, both measured about the axis the pitch surfaces turn the craft about.
|
||||||
|
*/
|
||||||
|
private void measureControlRates(Frame frame, Vector3dc centerOfMass, double[] v, double[] w, boolean improved, double dt) {
|
||||||
|
for (NodeData node : frame.nodes.values()) {
|
||||||
|
NodeState state = nodeStates.get(node.key());
|
||||||
|
if (state == null || !CursorAimRegistry.isActive(node.key())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
double response = state.pitchResponse.length();
|
||||||
|
if (response < 1.0E-9) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Vector3d axis = state.pitchResponse.div(response, new Vector3d());
|
||||||
|
double[] turned = {w[0] + ANGULAR_EPSILON * axis.x, w[1] + ANGULAR_EPSILON * axis.y, w[2] + ANGULAR_EPSILON * axis.z};
|
||||||
|
evaluate(frame, centerOfMass, v, turned, improved, false, probe);
|
||||||
|
double damping = 0.0;
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
damping -= (probe.totalTorque(i) - wrench.totalTorque(i)) * axis.get(i);
|
||||||
|
}
|
||||||
|
damping /= ANGULAR_EPSILON;
|
||||||
|
if (!(damping > 1.0E-9)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
double rate = response / damping;
|
||||||
|
state.controlRate = Double.isNaN(state.controlRate) ? rate
|
||||||
|
: state.controlRate + (rate - state.controlRate) * Math.min(1.0, dt / RATE_SMOOTHING_SECONDS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** A control surface's input, combined from its two keys and clamped like Warium does. */
|
/** A control surface's input, combined from its two keys and clamped like Warium does. */
|
||||||
private static double input(AeroSurface s, NodeData node, NodeState state, ControlAxis nudged, double extra) {
|
private static double input(AeroSurface s, NodeData node, NodeState state, ControlAxis nudged, double extra) {
|
||||||
if (node == null || state == null) {
|
if (node == null || state == null) {
|
||||||
@@ -314,7 +381,7 @@ public final class AeroState implements PhysicsBridge.Publishable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateNodes(Frame frame, Vector3dc worldVelocity, double altitude, Quaterniondc rotation, Matrix3dc inertia,
|
private void updateNodes(Frame frame, Vector3dc worldVelocity, double altitude, Quaterniondc rotation, Matrix3dc inertia,
|
||||||
double[] w, double dt, boolean improved) {
|
double[] w, double dt, boolean improved, double liftAcceleration) {
|
||||||
double step = Config.CONTROL_SMOOTHING.get() ? INPUT_RATE_PER_TICK * clock.weight() : Double.POSITIVE_INFINITY;
|
double step = Config.CONTROL_SMOOTHING.get() ? INPUT_RATE_PER_TICK * clock.weight() : Double.POSITIVE_INFINITY;
|
||||||
// Torque of the last substep, in ship axes, which the flight computer separates from its own surfaces' share
|
// Torque of the last substep, in ship axes, which the flight computer separates from its own surfaces' share
|
||||||
double[] torque = {wrench.totalTorque(0), wrench.totalTorque(1), wrench.totalTorque(2)};
|
double[] torque = {wrench.totalTorque(0), wrench.totalTorque(1), wrench.totalTorque(2)};
|
||||||
@@ -324,14 +391,36 @@ public final class AeroState implements PhysicsBridge.Publishable {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Cursor aim, if the pilot has it on, supplies the inputs the pilot is not giving with the keys
|
// Cursor aim, if the pilot has it on, supplies the inputs the pilot is not giving with the keys
|
||||||
NodeData effective = CursorPilot.apply(state, node, rotation, inertia, w, worldVelocity.length(), wingStalled);
|
NodeData effective = CursorPilot.apply(state, node, rotation, inertia, w, worldVelocity.length(), wingStalled,
|
||||||
|
liftAcceleration, dt);
|
||||||
state.pitch = moveTowards(state.pitch, effective.pitch(), step);
|
state.pitch = moveTowards(state.pitch, effective.pitch(), step);
|
||||||
state.yaw = moveTowards(state.yaw, effective.yaw(), step);
|
state.yaw = moveTowards(state.yaw, effective.yaw(), step);
|
||||||
state.roll = moveTowards(state.roll, effective.roll(), step);
|
state.roll = moveTowards(state.roll, effective.roll(), step);
|
||||||
|
updateFlaps(state, node, worldVelocity.length(), dt);
|
||||||
|
state.updatedMillis = System.currentTimeMillis();
|
||||||
AutoTrim.update(state, effective, worldVelocity, altitude, rotation, inertia, w, torque, dt, improved && wingStalled);
|
AutoTrim.update(state, effective, worldVelocity, altitude, rotation, inertia, w, torque, dt, improved && wingStalled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moves a node's flaps towards the angle its lever asks for. Above the setting's maximum speed the air pushes them
|
||||||
|
* back in, so a craft that is too fast for its flaps has them half retracted, and all the way at 25% more.
|
||||||
|
*/
|
||||||
|
private static void updateFlaps(NodeState state, NodeData node, double speed, double dt) {
|
||||||
|
FlapSetting setting = FlapSetting.of(node.flapSetting());
|
||||||
|
double target = Math.toRadians(setting.degrees());
|
||||||
|
double limit = setting.maxSpeed();
|
||||||
|
if (speed > limit) {
|
||||||
|
target *= Math.max(0.0, 1.0 - (speed - limit) / (0.25 * limit));
|
||||||
|
}
|
||||||
|
state.flapAngle = moveTowards(state.flapAngle, target, Math.toRadians(Config.FLAP_SLEW_DEGREES.get()) * dt);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The physics state of a control node, null if no physics runs for it. */
|
||||||
|
static NodeState nodeState(long nodeKey) {
|
||||||
|
return ALL_NODE_STATES.get(nodeKey);
|
||||||
|
}
|
||||||
|
|
||||||
static double moveTowards(double value, double target, double maxStep) {
|
static double moveTowards(double value, double target, double maxStep) {
|
||||||
if (Math.abs(target - value) <= maxStep) {
|
if (Math.abs(target - value) <= maxStep) {
|
||||||
return target;
|
return target;
|
||||||
|
|||||||
@@ -14,16 +14,17 @@ package dev.lumareth.improvedAerodynamics.flight;
|
|||||||
* @param brakeInput air brakes only: Warium's input value, they ignore smoothing and trim
|
* @param brakeInput air brakes only: Warium's input value, they ignore smoothing and trim
|
||||||
* @param aspectRatio span squared over area of the wing the block belongs to, 0 if not known yet
|
* @param aspectRatio span squared over area of the wing the block belongs to, 0 if not known yet
|
||||||
* @param wingGroup whether the wing the block belongs to contains WING blocks, not only control surfaces or stabilizers
|
* @param wingGroup whether the wing the block belongs to contains WING blocks, not only control surfaces or stabilizers
|
||||||
|
* @param flap whether the block was made a flap with shift-right-click, it then also follows its node's flap setting
|
||||||
*/
|
*/
|
||||||
public record AeroSurface(long key, SurfaceType type, boolean slab, double x, double y, double z, int facingX, int facingZ,
|
public record AeroSurface(long key, SurfaceType type, boolean slab, double x, double y, double z, int facingX, int facingZ,
|
||||||
double pressure, double fluidFactor, double speedMultiplier,
|
double pressure, double fluidFactor, double speedMultiplier,
|
||||||
long node, ControlAxis axis1, double multiplier1, ControlAxis axis2, double multiplier2,
|
long node, ControlAxis axis1, double multiplier1, ControlAxis axis2, double multiplier2,
|
||||||
double brakeInput, double aspectRatio, boolean wingGroup) {
|
double brakeInput, double aspectRatio, boolean wingGroup, boolean flap) {
|
||||||
public static final long NO_NODE = Long.MIN_VALUE;
|
public static final long NO_NODE = Long.MIN_VALUE;
|
||||||
|
|
||||||
AeroSurface withWingShape(double aspectRatio, boolean wingGroup) {
|
AeroSurface withWingShape(double aspectRatio, boolean wingGroup) {
|
||||||
return new AeroSurface(key, type, slab, x, y, z, facingX, facingZ, pressure, fluidFactor, speedMultiplier,
|
return new AeroSurface(key, type, slab, x, y, z, facingX, facingZ, pressure, fluidFactor, speedMultiplier,
|
||||||
node, axis1, multiplier1, axis2, multiplier2, brakeInput, aspectRatio, wingGroup);
|
node, axis1, multiplier1, axis2, multiplier2, brakeInput, aspectRatio, wingGroup, flap);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Warium's "Direction.getClockWise(Axis.Y)" of the facing, the span direction of a horizontal surface. */
|
/** Warium's "Direction.getClockWise(Axis.Y)" of the facing, the span direction of a horizontal surface. */
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public final class AutoTrimToggle {
|
|||||||
* The control node the seat under the player is linked to. Warium's control seat block finds its seat entity
|
* The control node the seat under the player is linked to. Warium's control seat block finds its seat entity
|
||||||
* within half a block of itself, so the seat block is at the entity's block or just below it.
|
* within half a block of itself, so the seat block is at the entity's block or just below it.
|
||||||
*/
|
*/
|
||||||
private static BlockEntity findNode(Level level, BlockPos seatPos) {
|
public static BlockEntity findNode(Level level, BlockPos seatPos) {
|
||||||
for (BlockPos pos : new BlockPos[]{seatPos, seatPos.below()}) {
|
for (BlockPos pos : new BlockPos[]{seatPos, seatPos.below()}) {
|
||||||
BlockEntity seat = level.getBlockEntity(pos);
|
BlockEntity seat = level.getBlockEntity(pos);
|
||||||
if (seat == null || !seat.getPersistentData().contains("ControlX")) {
|
if (seat == null || !seat.getPersistentData().contains("ControlX")) {
|
||||||
|
|||||||
@@ -1,56 +0,0 @@
|
|||||||
package dev.lumareth.improvedAerodynamics.flight;
|
|
||||||
|
|
||||||
import net.minecraftforge.common.ForgeConfigSpec;
|
|
||||||
|
|
||||||
/** Server side settings of the cursor aim virtual pilot. Lives in improved_aerodynamics-cursor-aim.toml. */
|
|
||||||
public final class CursorAimConfig {
|
|
||||||
public static final ForgeConfigSpec SPEC;
|
|
||||||
|
|
||||||
public static final ForgeConfigSpec.BooleanValue ENABLED;
|
|
||||||
public static final ForgeConfigSpec.DoubleValue FULL_DEFLECTION_DEGREES;
|
|
||||||
public static final ForgeConfigSpec.DoubleValue DEADZONE_DEGREES;
|
|
||||||
public static final ForgeConfigSpec.DoubleValue MAX_TURN_RATE_DEGREES;
|
|
||||||
public static final ForgeConfigSpec.DoubleValue MAX_ROLL_RATE_DEGREES;
|
|
||||||
public static final ForgeConfigSpec.DoubleValue MAX_BANK_DEGREES;
|
|
||||||
public static final ForgeConfigSpec.DoubleValue BANK_GAIN;
|
|
||||||
public static final ForgeConfigSpec.DoubleValue RATE_GAIN;
|
|
||||||
public static final ForgeConfigSpec.DoubleValue PUSH_FACTOR;
|
|
||||||
public static final ForgeConfigSpec.DoubleValue STALLED_PITCH_FACTOR;
|
|
||||||
public static final ForgeConfigSpec.DoubleValue MIN_SPEED;
|
|
||||||
|
|
||||||
static {
|
|
||||||
ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder();
|
|
||||||
builder.comment("Cursor aim: the mouse moves a cursor on screen, a virtual pilot flies the control node's craft by it").push("cursor_aim");
|
|
||||||
ENABLED = builder.comment("Whether pilots may use cursor aim on this server")
|
|
||||||
.define("enabled", true);
|
|
||||||
FULL_DEFLECTION_DEGREES = builder.comment("Angle of the cursor from the gun reticle at which the virtual pilot asks for full deflection: the maximum bank",
|
|
||||||
"sideways, the full pitch rate up or down")
|
|
||||||
.defineInRange("fullDeflectionDegrees", 30.0, 5.0, 90.0);
|
|
||||||
DEADZONE_DEGREES = builder.comment("Radius around the gun reticle in degrees inside which the cursor commands nothing, so the craft flies straight.",
|
|
||||||
"Outside it the command grows from zero, there is no jump at the edge")
|
|
||||||
.defineInRange("deadzoneDegrees", 3.0, 0.0, 15.0);
|
|
||||||
MAX_TURN_RATE_DEGREES = builder.comment("Turn rate in degrees per second the pilot asks for at full deflection, both for the turn at maximum bank and for pitching")
|
|
||||||
.defineInRange("maxTurnRateDegrees", 40.0, 5.0, 360.0);
|
|
||||||
MAX_ROLL_RATE_DEGREES = builder.comment("Fastest roll in degrees per second the pilot asks for when it rolls to a bank angle")
|
|
||||||
.defineInRange("maxRollRateDegrees", 150.0, 10.0, 720.0);
|
|
||||||
MAX_BANK_DEGREES = builder.comment("Bank angle the pilot rolls to when the cursor is at full sideways deflection")
|
|
||||||
.defineInRange("maxBankDegrees", 70.0, 10.0, 90.0);
|
|
||||||
BANK_GAIN = builder.comment("Roll rate in rad/s per radian of bank angle error, how eagerly the pilot rolls to the wanted bank and levels the wings")
|
|
||||||
.defineInRange("bankGain", 3.0, 0.2, 20.0);
|
|
||||||
RATE_GAIN = builder.comment("How hard the pilot corrects its turn rate, in angular acceleration per rad/s of rate error. Lower is smoother,",
|
|
||||||
"higher follows the cursor tighter and can start to oscillate")
|
|
||||||
.defineInRange("rateGain", 5.0, 0.5, 40.0);
|
|
||||||
PUSH_FACTOR = builder.comment("A cursor below the gun reticle pushes the nose down. This is how much of the pull rate that may be, since",
|
|
||||||
"negative g is harder on the craft and the pilot")
|
|
||||||
.defineInRange("pushFactor", 0.4, 0.0, 1.0);
|
|
||||||
STALLED_PITCH_FACTOR = builder.comment("Multiplier for the pitch rate the pilot asks for while the wings are stalled, so it does not keep pulling")
|
|
||||||
.defineInRange("stalledPitchFactor", 0.3, 0.0, 1.0);
|
|
||||||
MIN_SPEED = builder.comment("Below this speed in blocks per second the pilot does nothing, the surfaces have no effect anyway")
|
|
||||||
.defineInRange("minSpeed", 15.0, 0.0, 200.0);
|
|
||||||
builder.pop();
|
|
||||||
SPEC = builder.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private CursorAimConfig() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package dev.lumareth.improvedAerodynamics.flight;
|
package dev.lumareth.improvedAerodynamics.flight;
|
||||||
|
|
||||||
|
import dev.lumareth.improvedAerodynamics.Config;
|
||||||
import net.mcreator.valkyrienwarium.entity.SeatEntityEntity;
|
import net.mcreator.valkyrienwarium.entity.SeatEntityEntity;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
@@ -24,7 +25,7 @@ public final class CursorAimServer {
|
|||||||
}
|
}
|
||||||
long nodeKey = basis.nodePos().asLong();
|
long nodeKey = basis.nodePos().asLong();
|
||||||
double length = Math.sqrt(cf * cf + cr * cr + cu * cu);
|
double length = Math.sqrt(cf * cf + cr * cr + cu * cu);
|
||||||
if (!active || !CursorAimConfig.ENABLED.get() || !(length > 1.0E-6) || !Double.isFinite(length)) {
|
if (!active || !Config.CURSOR_AIM_ENABLED.get() || !(length > 1.0E-6) || !Double.isFinite(length)) {
|
||||||
CursorAimRegistry.clear(nodeKey);
|
CursorAimRegistry.clear(nodeKey);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +1,54 @@
|
|||||||
package dev.lumareth.improvedAerodynamics.flight;
|
package dev.lumareth.improvedAerodynamics.flight;
|
||||||
|
|
||||||
|
import dev.lumareth.improvedAerodynamics.Config;
|
||||||
import org.joml.Matrix3d;
|
import org.joml.Matrix3d;
|
||||||
import org.joml.Matrix3dc;
|
import org.joml.Matrix3dc;
|
||||||
import org.joml.Quaterniondc;
|
import org.joml.Quaterniondc;
|
||||||
import org.joml.Vector3d;
|
import org.joml.Vector3d;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The virtual pilot of cursor aim. The cursor is a stick that springs back to the gun reticle:
|
* The virtual pilot of cursor aim. The cursor is a direction fixed in the world, and the pilot turns the craft until
|
||||||
|
* the gun reticle sits on it, so the offset it gets shrinks to nothing as the turn completes:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>sideways it commands a bank angle and turn: the further out, the steeper the bank and the harder the pull
|
* <li>it banks towards the cursor, judged with the wings level so the bank does not hide where the cursor is: the
|
||||||
* that comes with it. Centered it levels the wings, so a centered cursor is straight flight;</li>
|
* further the cursor is to the side, the steeper the bank. While banked it pulls as much as a level turn at that
|
||||||
* <li>up and down it commands a pitch rate;</li>
|
* bank needs, so the craft turns without losing height;</li>
|
||||||
* <li>close to the reticle it steers with yaw and pitch directly instead of banking, so aiming does not rock the
|
* <li>it pitches towards the cursor as seen from the cockpit, so once banked the cursor is above the nose and the
|
||||||
* wings.</li>
|
* pull brings the nose round onto it;</li>
|
||||||
|
* <li>a cursor far below the nose (more than {@code reverseTurnDegrees}, judged with the wings level) is not reached
|
||||||
|
* by pushing: the pilot rolls until the cursor is above the canopy and pulls, a reversal or split-S. It keeps at it
|
||||||
|
* until the reticle is close to the cursor, or the cursor is moved above the nose again. A cursor only a little below
|
||||||
|
* the nose is reached with the elevators alone, gently, so the craft can still be flown down to a landing;</li>
|
||||||
|
* <li>below {@code minSpeed} there is too little airflow to fly by: the cursor moves elevators and rudder directly;</li>
|
||||||
|
* <li>close to the reticle it levels the wings and puts the reticle on the cursor with rudder and elevator, so
|
||||||
|
* aiming does not rock the wings.</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
* The wanted rotation is turned into stick inputs by the measured effect of each input on the craft (torque per unit
|
* The wanted rotation is turned into stick inputs by the measured effect of each input on the craft (torque per unit
|
||||||
* of input, see {@link AeroState}), so it works for any craft however its surfaces are mixed or oriented: angular
|
* of input, see {@link AeroState}), so it works for any craft however its surfaces are mixed or oriented: angular
|
||||||
* acceleration wanted times inertia, solved for the three inputs with a little regularization for axes that have no
|
* acceleration wanted times inertia, solved for the three inputs with a little regularization for axes that have no
|
||||||
* surfaces. Keys the pilot holds win over it, per axis.
|
* surfaces. Keys the pilot holds win over it, per axis.
|
||||||
|
* <p>
|
||||||
|
* How hard the craft can turn is worked out live, not configured: the lift its wings can make at the edge of the stall
|
||||||
|
* at the current speed and altitude, over its mass and speed, and the steady pitch rate its pitch surfaces can hold
|
||||||
|
* against its pitch damping, whichever is lower. The same lift limit caps the bank to what the craft can hold level, so
|
||||||
|
* a heavy bomber banks gently and turns wide while a light fighter racks into a steep, tight turn.
|
||||||
*/
|
*/
|
||||||
final class CursorPilot {
|
final class CursorPilot {
|
||||||
private static final double FINE_START = Math.toRadians(4.0);
|
private static final double FINE_START = Math.toRadians(4.0);
|
||||||
private static final double FINE_END = Math.toRadians(16.0);
|
private static final double FINE_END = Math.toRadians(16.0);
|
||||||
private static final double MANUAL_OVERRIDE = 0.05;
|
private static final double MANUAL_OVERRIDE = 0.05;
|
||||||
private static final double MAX_PULL_BANK = Math.toRadians(90.0);
|
// Gravity of VS
|
||||||
|
private static final double GRAVITY = 10.0;
|
||||||
|
// Share of the stall limited lift the pilot plans with, so it does not ride the stall
|
||||||
|
private static final double LIFT_MARGIN = 0.85;
|
||||||
|
// Bank the pilot rolls to at full sideways deflection even when the wings cannot hold the turn level
|
||||||
|
private static final double MIN_BANK = Math.toRadians(20.0);
|
||||||
|
// Smallest pull allowed, as a share of the turn rate, when gravity takes most of the lift
|
||||||
|
private static final double MIN_PULL_SHARE = 0.2;
|
||||||
|
// Time constant of easing the pull back in and out of a stall
|
||||||
|
private static final double STALL_EASE_SECONDS = 0.4;
|
||||||
|
// Turn rate when neither limit can be measured, like the first moments of a flight
|
||||||
|
private static final double FALLBACK_TURN_RATE = Math.toRadians(30.0);
|
||||||
|
|
||||||
private CursorPilot() {
|
private CursorPilot() {
|
||||||
}
|
}
|
||||||
@@ -32,57 +57,128 @@ final class CursorPilot {
|
|||||||
* @return the node with the pilot's wanted inputs in place of the keys, or the node itself if cursor aim is off
|
* @return the node with the pilot's wanted inputs in place of the keys, or the node itself if cursor aim is off
|
||||||
*/
|
*/
|
||||||
static NodeData apply(AeroState.NodeState state, NodeData node, Quaterniondc rotation, Matrix3dc inertia, double[] w,
|
static NodeData apply(AeroState.NodeState state, NodeData node, Quaterniondc rotation, Matrix3dc inertia, double[] w,
|
||||||
double speed, boolean wingStalled) {
|
double speed, boolean wingStalled, double liftAcceleration, double dt) {
|
||||||
if (!CursorAimConfig.ENABLED.get()) {
|
if (!Config.CURSOR_AIM_ENABLED.get()) {
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
CursorAimRegistry.Aim aim = CursorAimRegistry.get(node.key());
|
CursorAimRegistry.Aim aim = CursorAimRegistry.get(node.key());
|
||||||
if (aim == null || speed < CursorAimConfig.MIN_SPEED.get()) {
|
if (aim == null) {
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
double fullAngle = Math.toRadians(CursorAimConfig.FULL_DEFLECTION_DEGREES.get());
|
double fullAngle = Math.toRadians(Config.CURSOR_AIM_FULL_DEFLECTION_DEGREES.get());
|
||||||
double maxTurn = Math.toRadians(CursorAimConfig.MAX_TURN_RATE_DEGREES.get());
|
double maxRoll = Math.toRadians(Config.CURSOR_AIM_MAX_ROLL_RATE_DEGREES.get());
|
||||||
double maxRoll = Math.toRadians(CursorAimConfig.MAX_ROLL_RATE_DEGREES.get());
|
double maxBank = Math.toRadians(Config.CURSOR_AIM_MAX_BANK_DEGREES.get());
|
||||||
double maxBank = Math.toRadians(CursorAimConfig.MAX_BANK_DEGREES.get());
|
|
||||||
|
|
||||||
double[] f = aim.forward();
|
double[] f = aim.forward();
|
||||||
double[] r = aim.right();
|
double[] r = aim.right();
|
||||||
double[] u = aim.up();
|
double[] u = aim.up();
|
||||||
|
learnSigns(state, f, r, u);
|
||||||
// Cursor as angles from the reticle: sideways (positive right) and up, both through any 270 degree cone
|
|
||||||
double sideways = Math.atan2(aim.cr(), aim.cf());
|
|
||||||
double vertical = Math.atan2(aim.cu(), Math.hypot(aim.cf(), aim.cr()));
|
|
||||||
// Deadzone around the reticle: shrink the cursor offset by its radius, direction kept
|
|
||||||
double offset = Math.hypot(sideways, vertical);
|
|
||||||
double deadzone = Math.toRadians(CursorAimConfig.DEADZONE_DEGREES.get());
|
|
||||||
if (offset > 1.0E-9) {
|
|
||||||
double scale = Math.max(0.0, offset - deadzone) / offset;
|
|
||||||
sideways *= scale;
|
|
||||||
vertical *= scale;
|
|
||||||
}
|
|
||||||
double lateral = saturate(sideways / fullAngle);
|
|
||||||
double blend = smoothstep(Math.abs(sideways), FINE_START, FINE_END);
|
|
||||||
|
|
||||||
// Bank of the craft: positive when the right wing is down, through upside down
|
// Bank of the craft: positive when the right wing is down, through upside down
|
||||||
Vector3d rightWorld = rotation.transform(new Vector3d(r[0], r[1], r[2]));
|
Vector3d rightWorld = rotation.transform(new Vector3d(r[0], r[1], r[2]));
|
||||||
Vector3d upWorld = rotation.transform(new Vector3d(u[0], u[1], u[2]));
|
Vector3d upWorld = rotation.transform(new Vector3d(u[0], u[1], u[2]));
|
||||||
double bank = Math.atan2(-rightWorld.y, upWorld.y);
|
double bank = Math.atan2(-rightWorld.y, upWorld.y);
|
||||||
|
|
||||||
double bankCommand = maxBank * lateral * blend;
|
// Deadzone around the reticle: shrink the cursor's offset by its radius, direction kept
|
||||||
double rollRate = clamp(CursorAimConfig.BANK_GAIN.get() * (bankCommand - bank), -maxRoll, maxRoll);
|
double cf = aim.cf();
|
||||||
|
double cr = aim.cr();
|
||||||
// Pitch: the stick, plus the pull that carries the turn while banked
|
double cu = aim.cu();
|
||||||
double pitchStick = saturate(vertical / fullAngle);
|
double deadzone = Math.toRadians(Config.CURSOR_AIM_DEADZONE_DEGREES.get());
|
||||||
double pitchRate = maxTurn * (pitchStick >= 0.0 ? pitchStick : pitchStick * CursorAimConfig.PUSH_FACTOR.get());
|
double offset = Math.acos(clamp(cf, -1.0, 1.0));
|
||||||
if (Math.abs(bank) < MAX_PULL_BANK) {
|
double across = Math.hypot(cr, cu);
|
||||||
pitchRate += maxTurn * Math.abs(lateral) * blend * Math.sin(Math.abs(bank));
|
if (deadzone > 0.0 && offset > 1.0E-9 && across > 1.0E-9) {
|
||||||
|
double shrunk = Math.max(0.0, offset - deadzone);
|
||||||
|
cf = Math.cos(shrunk);
|
||||||
|
cr *= Math.sin(shrunk) / across;
|
||||||
|
cu *= Math.sin(shrunk) / across;
|
||||||
}
|
}
|
||||||
if (wingStalled && pitchRate > 0.0) {
|
// Cursor as angles from the reticle as seen from the cockpit: sideways (positive right) and up, through any
|
||||||
pitchRate *= CursorAimConfig.STALLED_PITCH_FACTOR.get();
|
// 270 degree cone
|
||||||
|
double sideways = Math.atan2(cr, cf);
|
||||||
|
double vertical = Math.atan2(cu, Math.hypot(cf, cr));
|
||||||
|
// The cursor as it would be with the wings level: what the bank is chosen by
|
||||||
|
double levelRight = cr * Math.cos(bank) + cu * Math.sin(bank);
|
||||||
|
double levelUp = cu * Math.cos(bank) - cr * Math.sin(bank);
|
||||||
|
double levelVertical = Math.atan2(levelUp, Math.hypot(cf, levelRight));
|
||||||
|
|
||||||
|
if (speed < Config.CURSOR_AIM_MIN_SPEED.get()) {
|
||||||
|
// Too slow for the rate loop: the cursor moves the surfaces directly, rudder towards it (which also steers on
|
||||||
|
// the ground) and elevator up or down, so the controls follow the cursor while taxiing and rotating
|
||||||
|
state.reversing = false;
|
||||||
|
double pitch = clamp(state.pitchSign * saturate(vertical / fullAngle) - state.trimOutput, -1.0, 1.0);
|
||||||
|
double yaw = state.yawSign * saturate(sideways / fullAngle);
|
||||||
|
return withInputs(node, pitch, yaw, 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// What this craft can do right now. Lift: pitch rate at the highest usable lift (a = L / m, rate = a / v), and
|
||||||
|
// the bank whose level turn needs that load factor. Without a stall model only the control limit applies
|
||||||
|
double usableLift = LIFT_MARGIN * liftAcceleration;
|
||||||
|
double liftRate = usableLift > 0.0 ? usableLift / speed : Double.POSITIVE_INFINITY;
|
||||||
|
double controlRate = state.controlRate > 0.0 ? state.controlRate : Double.POSITIVE_INFINITY;
|
||||||
|
double maxTurn = Math.min(liftRate, controlRate);
|
||||||
|
if (!Double.isFinite(maxTurn)) {
|
||||||
|
maxTurn = FALLBACK_TURN_RATE;
|
||||||
|
}
|
||||||
|
// Fastest pull: part of the lift already holds the craft up against gravity, only the rest curves the flight
|
||||||
|
// path, so asking for the full lift rate in a steep bank would drag the wings into the stall
|
||||||
|
double maxPull = maxTurn;
|
||||||
|
if (Double.isFinite(liftAcceleration)) {
|
||||||
|
double loadFactor = usableLift / GRAVITY;
|
||||||
|
double levelBank = loadFactor > 1.0 ? Math.acos(1.0 / loadFactor) : 0.0;
|
||||||
|
maxBank = Math.max(Math.min(MIN_BANK, maxBank), Math.min(maxBank, levelBank));
|
||||||
|
double pullLift = (usableLift - GRAVITY * upWorld.y) / speed;
|
||||||
|
maxPull = clamp(Math.min(pullLift, controlRate), MIN_PULL_SHARE * maxTurn, maxTurn);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reversal: entered when the cursor is far below the nose, left once the reticle is close to it or the cursor
|
||||||
|
// is above the nose again
|
||||||
|
double offsetAngle = Math.acos(clamp(cf, -1.0, 1.0));
|
||||||
|
if (state.reversing) {
|
||||||
|
state.reversing = offsetAngle > FINE_END && levelVertical < 0.0;
|
||||||
|
} else {
|
||||||
|
state.reversing = levelVertical < -Math.toRadians(Config.CURSOR_AIM_REVERSE_TURN_DEGREES.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bank: roll so the cursor is above the canopy, which is where a pull takes the nose. Judged by the direction of
|
||||||
|
// the cursor around the nose, which stays well defined wherever the cursor is, even 90 degrees off the nose
|
||||||
|
// straight above or to the side; the angle of the cursor from the nose only sets how much of that bank is used,
|
||||||
|
// so the wings come level as the reticle closes on the cursor
|
||||||
|
double blend = state.reversing ? 1.0 : smoothstep(offsetAngle, FINE_START, FINE_END);
|
||||||
|
double bankError;
|
||||||
|
if (state.reversing) {
|
||||||
|
// All the way over, the shorter way round
|
||||||
|
bankError = wrap(Math.atan2(levelRight, levelUp) - bank);
|
||||||
|
} else {
|
||||||
|
// A cursor below the nose counts as if it were as far above it: only its sideways part banks the craft, and
|
||||||
|
// the craft is never rolled upside down for a slight descent
|
||||||
|
double overhead = Math.atan2(levelRight, Math.abs(levelUp));
|
||||||
|
double bankCommand = clamp(overhead, -maxBank, maxBank) * saturate(offsetAngle / fullAngle) * blend;
|
||||||
|
bankError = bankCommand - bank;
|
||||||
|
}
|
||||||
|
double rollRate = clamp(Config.CURSOR_AIM_BANK_GAIN.get() * bankError, -maxRoll, maxRoll);
|
||||||
|
|
||||||
|
// Pitch: the pull of a level turn at the current bank, the turn rate g tan(bank) / v seen about the pitch axis,
|
||||||
|
// plus a pull towards the cursor. Past 90 degrees of bank the level turn pull would only dive, so it is left out
|
||||||
|
double pitchStick = saturate(vertical / fullAngle);
|
||||||
|
double push = Config.CURSOR_AIM_PUSH_FACTOR.get();
|
||||||
|
// While rolling into a reversal the cursor is still below the nose, pushing there would only work against it
|
||||||
|
double pitchRate = pitchStick >= 0.0 ? maxPull * pitchStick : state.reversing ? 0.0 : maxTurn * pitchStick * push;
|
||||||
|
double cosBank = Math.cos(bank);
|
||||||
|
if (cosBank > 0.0) {
|
||||||
|
double sinBank = Math.sin(bank);
|
||||||
|
pitchRate += GRAVITY * sinBank * sinBank / (speed * Math.max(cosBank, 0.1));
|
||||||
|
}
|
||||||
|
// Stalled wings ease the pull back, and it comes back as gently once they fly again: switching it at once with
|
||||||
|
// the stall would make the craft buck in and out of the stall
|
||||||
|
double stallTarget = wingStalled ? Config.CURSOR_AIM_STALLED_PITCH_FACTOR.get() : 1.0;
|
||||||
|
state.stallEase += (stallTarget - state.stallEase) * Math.min(1.0, dt / STALL_EASE_SECONDS);
|
||||||
|
pitchRate = clamp(pitchRate, -maxTurn * push, maxPull);
|
||||||
|
if (pitchRate > 0.0) {
|
||||||
|
pitchRate *= state.stallEase;
|
||||||
}
|
}
|
||||||
// Close to the reticle the nose follows the cursor with the rudder
|
// Close to the reticle the nose follows the cursor with the rudder
|
||||||
double yawRate = maxTurn * lateral * (1.0 - blend);
|
double yawRate = maxTurn * saturate(sideways / fullAngle) * (1.0 - blend);
|
||||||
|
|
||||||
// Wanted angular velocity in ship axes: roll about forward, pitch about right, yaw (nose right) about -up
|
// Wanted angular velocity in ship axes: roll about forward, pitch about right, yaw (nose right) about -up
|
||||||
Vector3d wanted = new Vector3d(
|
Vector3d wanted = new Vector3d(
|
||||||
@@ -90,7 +186,7 @@ final class CursorPilot {
|
|||||||
rollRate * f[1] + pitchRate * r[1] - yawRate * u[1],
|
rollRate * f[1] + pitchRate * r[1] - yawRate * u[1],
|
||||||
rollRate * f[2] + pitchRate * r[2] - yawRate * u[2]);
|
rollRate * f[2] + pitchRate * r[2] - yawRate * u[2]);
|
||||||
Vector3d error = wanted.sub(w[0], w[1], w[2]);
|
Vector3d error = wanted.sub(w[0], w[1], w[2]);
|
||||||
Vector3d acceleration = error.mul(CursorAimConfig.RATE_GAIN.get());
|
Vector3d acceleration = error.mul(Config.CURSOR_AIM_RATE_GAIN.get());
|
||||||
Vector3d torque = inertia.transform(acceleration, new Vector3d());
|
Vector3d torque = inertia.transform(acceleration, new Vector3d());
|
||||||
|
|
||||||
double[] inputs = solve(state.pitchResponse, state.yawResponse, state.rollResponse, torque);
|
double[] inputs = solve(state.pitchResponse, state.yawResponse, state.rollResponse, torque);
|
||||||
@@ -101,11 +197,35 @@ final class CursorPilot {
|
|||||||
double pitch = clamp(inputs[0] - state.trimOutput, -1.0, 1.0);
|
double pitch = clamp(inputs[0] - state.trimOutput, -1.0, 1.0);
|
||||||
double yaw = clamp(inputs[1], -1.0, 1.0);
|
double yaw = clamp(inputs[1], -1.0, 1.0);
|
||||||
double roll = clamp(inputs[2], -1.0, 1.0);
|
double roll = clamp(inputs[2], -1.0, 1.0);
|
||||||
|
return withInputs(node, pitch, yaw, roll);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The node with these inputs on the axes the pilot is not holding a key for. */
|
||||||
|
private static NodeData withInputs(NodeData node, double pitch, double yaw, double roll) {
|
||||||
return new NodeData(node.key(),
|
return new NodeData(node.key(),
|
||||||
Math.abs(node.pitch()) > MANUAL_OVERRIDE ? node.pitch() : pitch,
|
Math.abs(node.pitch()) > MANUAL_OVERRIDE ? node.pitch() : pitch,
|
||||||
Math.abs(node.yaw()) > MANUAL_OVERRIDE ? node.yaw() : yaw,
|
Math.abs(node.yaw()) > MANUAL_OVERRIDE ? node.yaw() : yaw,
|
||||||
Math.abs(node.roll()) > MANUAL_OVERRIDE ? node.roll() : roll,
|
Math.abs(node.roll()) > MANUAL_OVERRIDE ? node.roll() : roll,
|
||||||
node.throttle(), node.autoTrim(), node.storedTrim());
|
node.throttle(), node.autoTrim(), node.storedTrim(), node.flapSetting());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remembers which way each input turns the craft, from the measured torque per unit of input: + nose up for pitch,
|
||||||
|
* nose right for yaw. Kept from the last time it was measurable, since with no airflow nothing can be measured.
|
||||||
|
*/
|
||||||
|
private static void learnSigns(AeroState.NodeState state, double[] f, double[] r, double[] u) {
|
||||||
|
state.pitchSign = sign(state.pitchResponse, r, 1.0, state.pitchSign);
|
||||||
|
state.yawSign = sign(state.yawResponse, u, -1.0, state.yawSign);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double sign(Vector3d response, double[] axis, double direction, double previous) {
|
||||||
|
double length = response.length();
|
||||||
|
if (!(length > 1.0E-6)) {
|
||||||
|
return previous;
|
||||||
|
}
|
||||||
|
double along = direction * (response.x * axis[0] + response.y * axis[1] + response.z * axis[2]) / length;
|
||||||
|
// Only trusted while the input clearly turns the craft about that axis
|
||||||
|
return Math.abs(along) > 0.3 ? Math.signum(along) : previous;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Least squares for the three inputs whose responses add up to the torque, ridge-regularized so unused axes stay at zero. */
|
/** Least squares for the three inputs whose responses add up to the torque, ridge-regularized so unused axes stay at zero. */
|
||||||
@@ -129,6 +249,11 @@ final class CursorPilot {
|
|||||||
return new double[]{x.x, x.y, x.z};
|
return new double[]{x.x, x.y, x.z};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The angle brought into -pi to pi. */
|
||||||
|
private static double wrap(double angle) {
|
||||||
|
return Math.atan2(Math.sin(angle), Math.cos(angle));
|
||||||
|
}
|
||||||
|
|
||||||
private static double saturate(double value) {
|
private static double saturate(double value) {
|
||||||
return clamp(value, -1.0, 1.0);
|
return clamp(value, -1.0, 1.0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,145 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.flight;
|
||||||
|
|
||||||
|
import dev.lumareth.improvedAerodynamics.Config;
|
||||||
|
import dev.lumareth.improvedAerodynamics.network.DeflectionPacket;
|
||||||
|
import dev.lumareth.improvedAerodynamics.network.Network;
|
||||||
|
import it.unimi.dsi.fastutil.longs.Long2LongOpenHashMap;
|
||||||
|
import it.unimi.dsi.fastutil.longs.Long2ShortOpenHashMap;
|
||||||
|
import it.unimi.dsi.fastutil.longs.LongArrayList;
|
||||||
|
import it.unimi.dsi.fastutil.shorts.ShortArrayList;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.resources.ResourceKey;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
import net.minecraftforge.event.TickEvent;
|
||||||
|
import net.minecraftforge.event.server.ServerStoppedEvent;
|
||||||
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
|
import net.minecraftforge.network.PacketDistributor;
|
||||||
|
import org.joml.Vector3d;
|
||||||
|
import org.valkyrienskies.core.api.ships.Ship;
|
||||||
|
import org.valkyrienskies.mod.common.VSGameUtilsKt;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tells the clients near a ship how far its control surfaces and flaps are deflected, so they can show it, see
|
||||||
|
* {@code SurfaceAnimation}. Every tick each Warium control surface block reports its deflection from the procedure that
|
||||||
|
* runs it ({@link WariumCapture#begin}); at the end of the tick what changed goes out, in one packet per ship, and
|
||||||
|
* everything again once a second so players who arrive later get it too.
|
||||||
|
* <p>
|
||||||
|
* The deflection is what the physics uses: the smoothed pilot input plus trim and flap angle of the surface's control
|
||||||
|
* node. While the ship is not flying (no physics, nothing is moving) the node's raw input and flap lever are used, and the
|
||||||
|
* flaps are moved towards their angle here, at the configured speed.
|
||||||
|
*/
|
||||||
|
public final class DeflectionSync {
|
||||||
|
/** Degrees of deflection the physics gives a surface at full input, see ImprovedAero.MAX_DEFLECTION. */
|
||||||
|
private static final double FULL_INPUT_DEGREES = 20.0;
|
||||||
|
private static final long RESEND_TICKS = 20;
|
||||||
|
private static final double RANGE = 256.0;
|
||||||
|
|
||||||
|
private record Batch(ServerLevel level, double x, double y, double z, LongArrayList positions, ShortArrayList tenths) {
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Map<ResourceKey<Level>, Long2ShortOpenHashMap> LAST_VALUE = new HashMap<>();
|
||||||
|
private static final Map<ResourceKey<Level>, Long2LongOpenHashMap> LAST_SENT = new HashMap<>();
|
||||||
|
// Flap angle (radians) shown while a node is not flying, and the tick it was last moved
|
||||||
|
private static final Map<Long, double[]> STATIC_FLAPS = new HashMap<>();
|
||||||
|
private static final Map<Long, Batch> BATCHES = new HashMap<>();
|
||||||
|
|
||||||
|
private DeflectionSync() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Called by the procedure of every control surface block each tick, before it adds its forces. */
|
||||||
|
static void report(ServerLevel level, BlockPos pos, SurfaceType type) {
|
||||||
|
if (!type.controllable) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
BlockEntity blockEntity = level.getBlockEntity(pos);
|
||||||
|
if (blockEntity == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
CompoundTag tag = blockEntity.getPersistentData();
|
||||||
|
BlockPos nodePos = BlockPos.containing(tag.getDouble("ControlX"), tag.getDouble("ControlY"), tag.getDouble("ControlZ"));
|
||||||
|
BlockEntity nodeEntity = level.getBlockEntity(nodePos);
|
||||||
|
if (nodeEntity == null || !tag.contains("ControlX")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
long nodeKey = nodePos.asLong();
|
||||||
|
CompoundTag nodeTag = nodeEntity.getPersistentData();
|
||||||
|
AeroState.NodeState state = LiveInputs.flying(nodeKey);
|
||||||
|
boolean flying = state != null;
|
||||||
|
|
||||||
|
double input = axisInput(nodeKey, nodeTag, tag.getString("Key")) + axisInput(nodeKey, nodeTag, tag.getString("Key2"));
|
||||||
|
double degrees = FULL_INPUT_DEGREES * Math.max(-1.0, Math.min(1.0, input));
|
||||||
|
if (type == SurfaceType.CONTROL_SURFACE && tag.getBoolean(WariumCapture.FLAP_TAG)) {
|
||||||
|
degrees += Math.toDegrees(flying ? state.flapAngle : staticFlap(level, nodeKey, nodeTag));
|
||||||
|
}
|
||||||
|
|
||||||
|
short tenths = (short) Math.round(Math.max(-90.0, Math.min(90.0, degrees)) * 10.0);
|
||||||
|
ResourceKey<Level> dimension = level.dimension();
|
||||||
|
Long2ShortOpenHashMap lastValue = LAST_VALUE.computeIfAbsent(dimension, key -> new Long2ShortOpenHashMap());
|
||||||
|
Long2LongOpenHashMap lastSent = LAST_SENT.computeIfAbsent(dimension, key -> new Long2LongOpenHashMap());
|
||||||
|
long posKey = pos.asLong();
|
||||||
|
long now = level.getGameTime();
|
||||||
|
if (lastSent.containsKey(posKey) && lastValue.get(posKey) == tenths && now - lastSent.get(posKey) < RESEND_TICKS) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lastValue.put(posKey, tenths);
|
||||||
|
lastSent.put(posKey, now);
|
||||||
|
|
||||||
|
Ship ship = VSGameUtilsKt.getShipManagingPos(level, pos);
|
||||||
|
long shipId = ship != null ? ship.getId() : Long.MIN_VALUE;
|
||||||
|
Batch batch = BATCHES.get(shipId);
|
||||||
|
if (batch == null) {
|
||||||
|
Vector3d world = new Vector3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
|
||||||
|
if (ship != null) {
|
||||||
|
ship.getShipToWorld().transformPosition(world);
|
||||||
|
}
|
||||||
|
batch = new Batch(level, world.x, world.y, world.z, new LongArrayList(), new ShortArrayList());
|
||||||
|
BATCHES.put(shipId, batch);
|
||||||
|
}
|
||||||
|
batch.positions.add(posKey);
|
||||||
|
batch.tenths.add(tenths);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** One key's share of a surface's input, like Warium reads "Pitch+" / "Roll-". Throttle keys do not deflect it. */
|
||||||
|
private static double axisInput(long nodeKey, CompoundTag nodeTag, String key) {
|
||||||
|
return ControlAxis.of(key) == ControlAxis.THROTTLE ? 0.0 : LiveInputs.key(nodeKey, nodeTag, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Flap angle of a node that is not flying: moves towards the lever's angle, once per tick however many flaps ask. */
|
||||||
|
private static double staticFlap(ServerLevel level, long nodeKey, CompoundTag nodeTag) {
|
||||||
|
double target = Math.toRadians(FlapSetting.of(nodeTag.getInt(WariumCapture.FLAP_SETTING_TAG)).degrees());
|
||||||
|
double[] entry = STATIC_FLAPS.computeIfAbsent(nodeKey, key -> new double[]{target, Double.NaN});
|
||||||
|
long now = level.getGameTime();
|
||||||
|
if (entry[1] != now) {
|
||||||
|
entry[1] = now;
|
||||||
|
entry[0] = AeroState.moveTowards(entry[0], target, Math.toRadians(Config.FLAP_SLEW_DEGREES.get()) / 20.0);
|
||||||
|
}
|
||||||
|
return entry[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onServerTick(TickEvent.ServerTickEvent event) {
|
||||||
|
if (event.phase != TickEvent.Phase.END || BATCHES.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (Batch batch : BATCHES.values()) {
|
||||||
|
DeflectionPacket packet = new DeflectionPacket(batch.positions.toLongArray(), batch.tenths.toShortArray());
|
||||||
|
Network.CHANNEL.send(PacketDistributor.NEAR.with(() -> new PacketDistributor.TargetPoint(batch.x, batch.y, batch.z,
|
||||||
|
RANGE, batch.level.dimension())), packet);
|
||||||
|
}
|
||||||
|
BATCHES.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onServerStopped(ServerStoppedEvent event) {
|
||||||
|
BATCHES.clear();
|
||||||
|
LAST_VALUE.clear();
|
||||||
|
LAST_SENT.clear();
|
||||||
|
STATIC_FLAPS.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.flight;
|
||||||
|
|
||||||
|
import net.mcreator.valkyrienwarium.entity.SeatEntityEntity;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
|
||||||
|
/** Server side of the flap keys: moves the flap lever of the control node the pilot's seat is linked to. */
|
||||||
|
public final class FlapControl {
|
||||||
|
private FlapControl() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @param step +1 for more flaps, -1 for fewer */
|
||||||
|
public static void step(ServerPlayer player, int step) {
|
||||||
|
Entity vehicle = player.getVehicle();
|
||||||
|
if (!(vehicle instanceof SeatEntityEntity)) {
|
||||||
|
player.displayClientMessage(Component.translatable("message.improved_aerodynamics.flaps.no_seat"), true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
BlockEntity node = AutoTrimToggle.findNode(vehicle.level(), vehicle.blockPosition());
|
||||||
|
if (node == null) {
|
||||||
|
player.displayClientMessage(Component.translatable("message.improved_aerodynamics.flaps.no_node"), true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
CompoundTag tag = node.getPersistentData();
|
||||||
|
int current = FlapSetting.of(tag.getInt(WariumCapture.FLAP_SETTING_TAG)).ordinal();
|
||||||
|
int next = Math.max(0, Math.min(FlapSetting.values().length - 1, current + (step > 0 ? 1 : -1)));
|
||||||
|
if (next != current) {
|
||||||
|
tag.putInt(WariumCapture.FLAP_SETTING_TAG, next);
|
||||||
|
node.setChanged();
|
||||||
|
}
|
||||||
|
player.displayClientMessage(Component.translatable("message.improved_aerodynamics.flaps",
|
||||||
|
Component.translatable(FlapSetting.of(next).translationKey())), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.flight;
|
||||||
|
|
||||||
|
import dev.lumareth.improvedAerodynamics.ImprovedAerodynamics;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.core.registries.Registries;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.tags.TagKey;
|
||||||
|
import net.minecraft.world.InteractionHand;
|
||||||
|
import net.minecraft.world.InteractionResult;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.block.Block;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||||
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shift-right-click on a block in the {@code improved_aerodynamics:flappable} tag (Warium's horizontal control
|
||||||
|
* surfaces) with empty hands makes it a flap, or a normal control surface again. A flap follows the flap lever of the
|
||||||
|
* control node it is linked to, on top of the pilot's input.
|
||||||
|
*/
|
||||||
|
public final class FlapInteraction {
|
||||||
|
public static final TagKey<Block> FLAPPABLE = TagKey.create(Registries.BLOCK,
|
||||||
|
new ResourceLocation(ImprovedAerodynamics.MOD_ID, "flappable"));
|
||||||
|
|
||||||
|
private FlapInteraction() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onRightClickBlock(PlayerInteractEvent.RightClickBlock event) {
|
||||||
|
Player player = event.getEntity();
|
||||||
|
if (event.getHand() != InteractionHand.MAIN_HAND || !player.isShiftKeyDown() || player.isPassenger()
|
||||||
|
|| !player.getMainHandItem().isEmpty() || !player.getOffhandItem().isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Level level = event.getLevel();
|
||||||
|
BlockPos pos = event.getPos();
|
||||||
|
BlockState state = level.getBlockState(pos);
|
||||||
|
if (!state.is(FLAPPABLE)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Handled on both sides so the block's own right-click action does not run on either
|
||||||
|
event.setCanceled(true);
|
||||||
|
event.setCancellationResult(InteractionResult.sidedSuccess(level.isClientSide));
|
||||||
|
if (level.isClientSide) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
BlockEntity blockEntity = level.getBlockEntity(pos);
|
||||||
|
if (blockEntity == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
CompoundTag tag = blockEntity.getPersistentData();
|
||||||
|
boolean flap = !tag.getBoolean(WariumCapture.FLAP_TAG);
|
||||||
|
tag.putBoolean(WariumCapture.FLAP_TAG, flap);
|
||||||
|
blockEntity.setChanged();
|
||||||
|
if (flap && !tag.contains("ControlX")) {
|
||||||
|
player.displayClientMessage(Component.translatable("message.improved_aerodynamics.flap.unlinked"), true);
|
||||||
|
} else {
|
||||||
|
player.displayClientMessage(Component.translatable(flap
|
||||||
|
? "message.improved_aerodynamics.flap.on" : "message.improved_aerodynamics.flap.off"), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.flight;
|
||||||
|
|
||||||
|
import dev.lumareth.improvedAerodynamics.Config;
|
||||||
|
|
||||||
|
/** Positions of a control node's flap lever. */
|
||||||
|
public enum FlapSetting {
|
||||||
|
UP,
|
||||||
|
TAKEOFF,
|
||||||
|
LANDING;
|
||||||
|
|
||||||
|
/** The setting for a stored number, UP for anything that is not one. */
|
||||||
|
public static FlapSetting of(int ordinal) {
|
||||||
|
FlapSetting[] values = values();
|
||||||
|
return ordinal >= 0 && ordinal < values.length ? values[ordinal] : UP;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Deflection in degrees the flaps move to at this setting. */
|
||||||
|
double degrees() {
|
||||||
|
return switch (this) {
|
||||||
|
case UP -> 0.0;
|
||||||
|
case TAKEOFF -> Config.FLAP_TAKEOFF_DEGREES.get();
|
||||||
|
case LANDING -> Config.FLAP_LANDING_DEGREES.get();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Airspeed in blocks per second above which the air starts to push the flaps back in. Infinite when they are up. */
|
||||||
|
double maxSpeed() {
|
||||||
|
return switch (this) {
|
||||||
|
case UP -> Double.POSITIVE_INFINITY;
|
||||||
|
case TAKEOFF -> Config.FLAP_TAKEOFF_MAX_SPEED.get();
|
||||||
|
case LANDING -> Config.FLAP_LANDING_MAX_SPEED.get();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public String translationKey() {
|
||||||
|
return "message.improved_aerodynamics.flaps." + name().toLowerCase(java.util.Locale.ROOT);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,6 +27,12 @@ final class ImprovedAero {
|
|||||||
private static final double MAX_DEFLECTION = Math.toRadians(20.0);
|
private static final double MAX_DEFLECTION = Math.toRadians(20.0);
|
||||||
// Share of the deflection that acts as angle of attack, gives Warium's control authority at the design speed
|
// Share of the deflection that acts as angle of attack, gives Warium's control authority at the design speed
|
||||||
private static final double FLAP_EFFECTIVENESS = 0.75;
|
private static final double FLAP_EFFECTIVENESS = 0.75;
|
||||||
|
// How much of the lift a flap adds raises the stall angle, and the parasitic drag coefficient per radian² of flap
|
||||||
|
// Share of the flap's deflection that acts as angle of attack: 35 degrees of landing flap adds about 1.1 to the
|
||||||
|
// lift coefficient, like a real plain or slotted flap
|
||||||
|
private static final double FLAP_ALPHA_FACTOR = 0.4;
|
||||||
|
private static final double FLAP_STALL_GAIN = 0.7;
|
||||||
|
private static final double FLAP_DRAG = 0.35;
|
||||||
// Angle of attack of a level cambered wing, where K is calibrated
|
// Angle of attack of a level cambered wing, where K is calibrated
|
||||||
private static final double REFERENCE_ANGLE = Math.toRadians(4.0);
|
private static final double REFERENCE_ANGLE = Math.toRadians(4.0);
|
||||||
private static final double REFERENCE_SPEED = 40.0;
|
private static final double REFERENCE_SPEED = 40.0;
|
||||||
@@ -62,10 +68,11 @@ final class ImprovedAero {
|
|||||||
* @param w ship angular velocity, ship axes
|
* @param w ship angular velocity, ship axes
|
||||||
* @param r block center relative to the center of mass, ship axes
|
* @param r block center relative to the center of mass, ship axes
|
||||||
* @param input control input of the surface, -1 to 1
|
* @param input control input of the surface, -1 to 1
|
||||||
|
* @param flap flap deflection in radians, 0 for surfaces that are not flaps
|
||||||
* @param stalled whether the surface was stalled in the previous substep
|
* @param stalled whether the surface was stalled in the previous substep
|
||||||
* @return whether the surface is stalled now
|
* @return whether the surface is stalled now
|
||||||
*/
|
*/
|
||||||
static boolean evaluate(AeroSurface s, double[] v, double[] w, double[] r, double input, double weight,
|
static boolean evaluate(AeroSurface s, double[] v, double[] w, double[] r, double input, double flap, double weight,
|
||||||
Tuning tuning, boolean stalled, Wrench out) {
|
Tuning tuning, boolean stalled, Wrench out) {
|
||||||
// Airflow at the block: ship velocity plus w x r
|
// Airflow at the block: ship velocity plus w x r
|
||||||
double vx = v[0] + w[1] * r[2] - w[2] * r[1];
|
double vx = v[0] + w[1] * r[2] - w[2] * r[1];
|
||||||
@@ -114,16 +121,20 @@ final class ImprovedAero {
|
|||||||
// Same sign convention as Warium: positive input pushes along n while moving against the facing
|
// Same sign convention as Warium: positive input pushes along n while moving against the facing
|
||||||
alpha += FLAP_EFFECTIVENESS * MAX_DEFLECTION * input * (u <= 0.0 ? 1.0 : -1.0);
|
alpha += FLAP_EFFECTIVENESS * MAX_DEFLECTION * input * (u <= 0.0 ? 1.0 : -1.0);
|
||||||
}
|
}
|
||||||
|
// A flap bends the airfoil's camber whichever way the air comes, so it always adds lift, and it moves the stall
|
||||||
|
// up with it: a flap raises the highest lift a wing can make
|
||||||
|
double flapShift = FLAP_ALPHA_FACTOR * flap;
|
||||||
|
alpha += flapShift;
|
||||||
alpha = Math.max(-Math.PI / 2.0, Math.min(Math.PI / 2.0, alpha));
|
alpha = Math.max(-Math.PI / 2.0, Math.min(Math.PI / 2.0, alpha));
|
||||||
|
|
||||||
// Low aspect ratio wings keep their flow attached longer thanks to leading-edge vortices. Control surfaces
|
// Low aspect ratio wings keep their flow attached longer thanks to leading-edge vortices. Control surfaces
|
||||||
// in a wing's group stall with the wing instead of before it
|
// in a wing's group stall with the wing instead of before it
|
||||||
double vortexFactor = tuning.vortex() && (s.type() == SurfaceType.WING || s.wingGroup() && s.type().controllable)
|
double vortexFactor = vortexFactor(s, tuning);
|
||||||
? VortexLift.factor(s.aspectRatio()) : 0.0;
|
double critical = criticalAngle(s, tuning, vortexFactor);
|
||||||
double baseStall = s.slab() ? SurfaceType.SLAB_STALL_ANGLE
|
|
||||||
: s.wingGroup() && s.type().controllable ? SurfaceType.WING.stallAngle : s.type().stallAngle;
|
|
||||||
double critical = Math.toRadians(baseStall) * (1.0 + tuning.vortexStallBonus() * vortexFactor) * tuning.stallAngleScale();
|
|
||||||
double absAlpha = Math.abs(alpha);
|
double absAlpha = Math.abs(alpha);
|
||||||
|
if (alpha >= 0.0) {
|
||||||
|
critical += FLAP_STALL_GAIN * flapShift;
|
||||||
|
}
|
||||||
// Flips only where both blends agree, so the hysteresis never makes the force jump
|
// Flips only where both blends agree, so the hysteresis never makes the force jump
|
||||||
if (!stalled && absAlpha > critical + STALL_BLEND) {
|
if (!stalled && absAlpha > critical + STALL_BLEND) {
|
||||||
stalled = true;
|
stalled = true;
|
||||||
@@ -135,9 +146,8 @@ final class ImprovedAero {
|
|||||||
|
|
||||||
// Finite wing theory: lift slope and induced drag follow from the wing's aspect ratio
|
// Finite wing theory: lift slope and induced drag follow from the wing's aspect ratio
|
||||||
double aspectRatio = s.aspectRatio();
|
double aspectRatio = s.aspectRatio();
|
||||||
double slope = aspectRatio > 0.0 ? 2.0 * Math.PI / (1.0 + 2.0 / aspectRatio) : LIFT_SLOPE;
|
|
||||||
double inducedDrag = aspectRatio > 0.0 ? 1.0 / (Math.PI * EFFICIENCY * aspectRatio) : INDUCED_DRAG;
|
double inducedDrag = aspectRatio > 0.0 ? 1.0 / (Math.PI * EFFICIENCY * aspectRatio) : INDUCED_DRAG;
|
||||||
double attachedLift = slope * alpha;
|
double attachedLift = liftSlope(s) * alpha;
|
||||||
if (s.type() == SurfaceType.WING) {
|
if (s.type() == SurfaceType.WING) {
|
||||||
attachedLift += VortexLift.liftCoefficient(alpha, vortexFactor, tuning.vortexLiftStrength());
|
attachedLift += VortexLift.liftCoefficient(alpha, vortexFactor, tuning.vortexLiftStrength());
|
||||||
}
|
}
|
||||||
@@ -156,11 +166,49 @@ final class ImprovedAero {
|
|||||||
double dy = -(vn * ny) / planeSpeed;
|
double dy = -(vn * ny) / planeSpeed;
|
||||||
double dz = -(u * cz + vn * nz) / planeSpeed;
|
double dz = -(u * cz + vn * nz) / planeSpeed;
|
||||||
double liftForce = q * lift * tuning.liftScale();
|
double liftForce = q * lift * tuning.liftScale();
|
||||||
double dragForce = q * drag / m;
|
double dragForce = q * (drag + FLAP_DRAG * flap * flap) / m;
|
||||||
out.addForce(r, lx * liftForce + dx * dragForce, ly * liftForce + dy * dragForce, lz * liftForce + dz * dragForce);
|
out.addForce(r, lx * liftForce + dx * dragForce, ly * liftForce + dy * dragForce, lz * liftForce + dz * dragForce);
|
||||||
return stalled;
|
return stalled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lift (along the surface's normal) the surface would make in the airflow it sees now at the highest angle of
|
||||||
|
* attack it can fly without starting to stall, flaps included. Only meaningful for horizontal surfaces.
|
||||||
|
*/
|
||||||
|
static double maxLift(AeroSurface s, double[] v, double[] w, double[] r, double flap, double weight, Tuning tuning) {
|
||||||
|
double vx = v[0] + w[1] * r[2] - w[2] * r[1];
|
||||||
|
double vy = v[1] + w[2] * r[0] - w[0] * r[2];
|
||||||
|
double vz = v[2] + w[0] * r[1] - w[1] * r[0];
|
||||||
|
double u = vx * s.facingX() + vz * s.facingZ();
|
||||||
|
double planeSpeedSq = u * u + vy * vy;
|
||||||
|
double vortexFactor = vortexFactor(s, tuning);
|
||||||
|
double flapShift = FLAP_ALPHA_FACTOR * flap;
|
||||||
|
double alpha = criticalAngle(s, tuning, vortexFactor) + FLAP_STALL_GAIN * flapShift - STALL_BLEND;
|
||||||
|
double lift = liftSlope(s) * alpha;
|
||||||
|
if (s.type() == SurfaceType.WING) {
|
||||||
|
lift += VortexLift.liftCoefficient(alpha, vortexFactor, tuning.vortexLiftStrength());
|
||||||
|
}
|
||||||
|
return LIFT_CONSTANT * s.pressure() * weight * s.fluidFactor() * planeSpeedSq * lift * tuning.liftScale();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double vortexFactor(AeroSurface s, Tuning tuning) {
|
||||||
|
return tuning.vortex() && (s.type() == SurfaceType.WING || s.wingGroup() && s.type().controllable)
|
||||||
|
? VortexLift.factor(s.aspectRatio()) : 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Angle of attack (radians, camber and flaps included) at which the surface starts to stall, without flaps. */
|
||||||
|
private static double criticalAngle(AeroSurface s, Tuning tuning, double vortexFactor) {
|
||||||
|
double baseStall = s.slab() ? SurfaceType.SLAB_STALL_ANGLE
|
||||||
|
: s.wingGroup() && s.type().controllable ? SurfaceType.WING.stallAngle : s.type().stallAngle;
|
||||||
|
return Math.toRadians(baseStall) * (1.0 + tuning.vortexStallBonus() * vortexFactor) * tuning.stallAngleScale();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Lift slope per radian from finite wing theory, from the wing's aspect ratio. */
|
||||||
|
private static double liftSlope(AeroSurface s) {
|
||||||
|
double aspectRatio = s.aspectRatio();
|
||||||
|
return aspectRatio > 0.0 ? 2.0 * Math.PI / (1.0 + 2.0 / aspectRatio) : LIFT_SLOPE;
|
||||||
|
}
|
||||||
|
|
||||||
static double smoothstep(double edge0, double edge1, double x) {
|
static double smoothstep(double edge0, double edge1, double x) {
|
||||||
double t = Math.max(0.0, Math.min(1.0, (x - edge0) / (edge1 - edge0)));
|
double t = Math.max(0.0, Math.min(1.0, (x - edge0) / (edge1 - edge0)));
|
||||||
return t * t * (3.0 - 2.0 * t);
|
return t * t * (3.0 - 2.0 * t);
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.flight;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The pilot inputs a control node's devices should follow, for everything that is not an aerodynamic surface (thrust
|
||||||
|
* vectoring nozzles). While the node's ship is flying these are the inputs the flight physics uses: the pilot's keys
|
||||||
|
* smoothed, or what cursor aim asks for in their place, plus the flight computer's pitch trim. A node without physics
|
||||||
|
* (on the ground, nothing moving, physics rate aerodynamics off) gives Warium's raw key values, as before.
|
||||||
|
*/
|
||||||
|
public final class LiveInputs {
|
||||||
|
// A node state the physics thread has not touched for this long is not flying any more
|
||||||
|
private static final long FRESH_MILLIS = 500;
|
||||||
|
|
||||||
|
private LiveInputs() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The node's physics state if its ship is flying now, else null. */
|
||||||
|
static AeroState.NodeState flying(long nodeKey) {
|
||||||
|
AeroState.NodeState state = AeroState.nodeState(nodeKey);
|
||||||
|
return state != null && System.currentTimeMillis() - state.updatedMillis < FRESH_MILLIS ? state : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One axis of a node, in Warium's node units (-1 to 1), without any key multiplier.
|
||||||
|
*
|
||||||
|
* @param nodeTag the node block entity's persistent data, for the raw value
|
||||||
|
*/
|
||||||
|
public static double value(long nodeKey, CompoundTag nodeTag, ControlAxis axis) {
|
||||||
|
AeroState.NodeState state = flying(nodeKey);
|
||||||
|
return switch (axis) {
|
||||||
|
case PITCH -> state != null ? state.pitch + state.trimOutput : nodeTag.getDouble("Pitch");
|
||||||
|
case YAW -> state != null ? state.yaw : nodeTag.getDouble("Yaw");
|
||||||
|
case ROLL -> state != null ? state.roll : nodeTag.getDouble("Roll");
|
||||||
|
case THROTTLE -> nodeTag.getDouble("Throttle");
|
||||||
|
case NONE -> 0.0;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A Warium key such as "Pitch+" or "Roll-" read from the node: its axis' value times the key's sign. */
|
||||||
|
public static double key(long nodeKey, CompoundTag nodeTag, String key) {
|
||||||
|
return value(nodeKey, nodeTag, ControlAxis.of(key)) * ControlAxis.multiplier(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,16 +18,18 @@ import java.util.Set;
|
|||||||
*/
|
*/
|
||||||
public final class MixinPlugin implements IMixinConfigPlugin {
|
public final class MixinPlugin implements IMixinConfigPlugin {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger("improved_aerodynamics");
|
private static final Logger LOGGER = LoggerFactory.getLogger("improved_aerodynamics");
|
||||||
private static final String WARIUM_VERSION = "1.1.6";
|
private static final String WARIUM_VERSION = "1.1.7";
|
||||||
private static final String FUTURISM_VERSION = "0.0.4";
|
private static final String FUTURISM_VERSION = "0.0.4";
|
||||||
|
|
||||||
private boolean warium;
|
private boolean warium;
|
||||||
private boolean futurism;
|
private boolean futurism;
|
||||||
|
private boolean geckolib;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad(String mixinPackage) {
|
public void onLoad(String mixinPackage) {
|
||||||
warium = supported("valkyrien_warium", WARIUM_VERSION, "Warium VS");
|
warium = supported("valkyrien_warium", WARIUM_VERSION, "Warium VS");
|
||||||
futurism = supported("futurism", FUTURISM_VERSION, "Futurism");
|
futurism = supported("futurism", FUTURISM_VERSION, "Futurism");
|
||||||
|
geckolib = LoadingModList.get().getModFileById("geckolib") != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean supported(String modId, String version, String name) {
|
private static boolean supported(String modId, String version, String name) {
|
||||||
@@ -49,6 +51,10 @@ public final class MixinPlugin implements IMixinConfigPlugin {
|
|||||||
if (mixinClassName.contains(".mixin.warium.")) {
|
if (mixinClassName.contains(".mixin.warium.")) {
|
||||||
return warium;
|
return warium;
|
||||||
}
|
}
|
||||||
|
if (mixinClassName.contains(".mixin.gecko.")) {
|
||||||
|
// Animates Warium's control surfaces, which are GeckoLib models
|
||||||
|
return warium && geckolib;
|
||||||
|
}
|
||||||
if (mixinClassName.contains(".mixin.futurism.")) {
|
if (mixinClassName.contains(".mixin.futurism.")) {
|
||||||
return futurism;
|
return futurism;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ package dev.lumareth.improvedAerodynamics.flight;
|
|||||||
* trim state.
|
* trim state.
|
||||||
*
|
*
|
||||||
* @param storedTrim trim saved in the node, used when the physics thread first sees the node
|
* @param storedTrim trim saved in the node, used when the physics thread first sees the node
|
||||||
|
* @param flapSetting the node's flap lever, see {@link FlapSetting#ordinal()}
|
||||||
*/
|
*/
|
||||||
public record NodeData(long key, double pitch, double yaw, double roll, double throttle, boolean autoTrim, double storedTrim) {
|
public record NodeData(long key, double pitch, double yaw, double roll, double throttle, boolean autoTrim, double storedTrim, int flapSetting) {
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package dev.lumareth.improvedAerodynamics.flight;
|
package dev.lumareth.improvedAerodynamics.flight;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Warium VS 1.1.6's aerodynamic forces, term for term as its block procedures compute them, but evaluated from the
|
* Warium VS 1.1.7's aerodynamic forces, term for term as its block procedures compute them, but evaluated from the
|
||||||
* ship's current motion. Like in Warium every block uses the velocity of the ship's center of mass. The procedures'
|
* ship's current motion. Like in Warium every block uses the velocity of the ship's center of mass. The procedures'
|
||||||
* conditions (air around the block, minimum speed, linked control node) were already checked on the server thread.
|
* conditions (air around the block, minimum speed, linked control node) were already checked on the server thread.
|
||||||
* Quirks are kept on purpose so craft fly exactly as before: vertical wings have no drag (Warium never sets the
|
* Quirks are kept on purpose so craft fly exactly as before: vertical wings have no drag (Warium never sets the
|
||||||
@@ -31,7 +31,8 @@ final class WariumAero {
|
|||||||
switch (s.type()) {
|
switch (s.type()) {
|
||||||
case WING -> {
|
case WING -> {
|
||||||
out.addForce(r, 0.0, v[1] * Math.abs(v[1]) * -45.0 * p / m, 0.0);
|
out.addForce(r, 0.0, v[1] * Math.abs(v[1]) * -45.0 * p / m, 0.0);
|
||||||
out.addForce(r, 0.0, Math.abs(fx * v[0] + fz * v[2]) * 160.0 * p, 0.0);
|
// Lift follows the horizontal speed whichever way the wing faces
|
||||||
|
out.addForce(r, 0.0, Math.hypot(v[0], v[2]) * 160.0 * p, 0.0);
|
||||||
double damping = speed * 600.0 * p / m;
|
double damping = speed * 600.0 * p / m;
|
||||||
out.addTorque(-w[0] * damping, -0.1 * w[1] * damping, -w[2] * damping);
|
out.addTorque(-w[0] * damping, -0.1 * w[1] * damping, -w[2] * damping);
|
||||||
double drag = -speed * p / m;
|
double drag = -speed * p / m;
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ import org.valkyrienskies.mod.common.VSGameUtilsKt;
|
|||||||
public final class WariumCapture {
|
public final class WariumCapture {
|
||||||
public static final String AUTO_TRIM_TAG = "improved_aerodynamics_autotrim";
|
public static final String AUTO_TRIM_TAG = "improved_aerodynamics_autotrim";
|
||||||
public static final String TRIM_TAG = "improved_aerodynamics_trim";
|
public static final String TRIM_TAG = "improved_aerodynamics_trim";
|
||||||
|
/** Block entity flag of a surface that is a flap, and the flap lever of a control node. */
|
||||||
|
public static final String FLAP_TAG = "improved_aerodynamics_flap";
|
||||||
|
public static final String FLAP_SETTING_TAG = "improved_aerodynamics_flap_setting";
|
||||||
private static final int TRIM_SAVE_INTERVAL = 20;
|
private static final int TRIM_SAVE_INTERVAL = 20;
|
||||||
|
|
||||||
// The procedure currently running, procedures run one at a time on the server thread
|
// The procedure currently running, procedures run one at a time on the server thread
|
||||||
@@ -47,6 +50,9 @@ public final class WariumCapture {
|
|||||||
world = level;
|
world = level;
|
||||||
pos = BlockPos.containing(x, y, z);
|
pos = BlockPos.containing(x, y, z);
|
||||||
state = blockState;
|
state = blockState;
|
||||||
|
if (surfaceType.controllable && level instanceof ServerLevel serverLevel && Config.PHYSICS_RATE_AERODYNAMICS.get()) {
|
||||||
|
DeflectionSync.report(serverLevel, pos, surfaceType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -77,10 +83,12 @@ public final class WariumCapture {
|
|||||||
String key = "Null";
|
String key = "Null";
|
||||||
String key2 = "Null";
|
String key2 = "Null";
|
||||||
double brakeInput = 0.0;
|
double brakeInput = 0.0;
|
||||||
|
boolean flap = false;
|
||||||
if (type.controllable || type == SurfaceType.AIR_BRAKE) {
|
if (type.controllable || type == SurfaceType.AIR_BRAKE) {
|
||||||
BlockEntity blockEntity = level.getBlockEntity(pos);
|
BlockEntity blockEntity = level.getBlockEntity(pos);
|
||||||
if (blockEntity != null) {
|
if (blockEntity != null) {
|
||||||
CompoundTag tag = blockEntity.getPersistentData();
|
CompoundTag tag = blockEntity.getPersistentData();
|
||||||
|
flap = type == SurfaceType.CONTROL_SURFACE && tag.getBoolean(FLAP_TAG);
|
||||||
key = tag.getString("Key");
|
key = tag.getString("Key");
|
||||||
key2 = type == SurfaceType.AIR_BRAKE ? "Null" : tag.getString("Key2");
|
key2 = type == SurfaceType.AIR_BRAKE ? "Null" : tag.getString("Key2");
|
||||||
BlockPos nodePos = BlockPos.containing(tag.getDouble("ControlX"), tag.getDouble("ControlY"), tag.getDouble("ControlZ"));
|
BlockPos nodePos = BlockPos.containing(tag.getDouble("ControlX"), tag.getDouble("ControlY"), tag.getDouble("ControlZ"));
|
||||||
@@ -97,7 +105,7 @@ public final class WariumCapture {
|
|||||||
return new AeroSurface(pos.asLong(), type, slab, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5,
|
return new AeroSurface(pos.asLong(), type, slab, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5,
|
||||||
facing.getStepX(), facing.getStepZ(), pressure, fluidFactor(level), speedMultiplier,
|
facing.getStepX(), facing.getStepZ(), pressure, fluidFactor(level), speedMultiplier,
|
||||||
node, ControlAxis.of(key), ControlAxis.multiplier(key), ControlAxis.of(key2), ControlAxis.multiplier(key2),
|
node, ControlAxis.of(key), ControlAxis.multiplier(key), ControlAxis.of(key2), ControlAxis.multiplier(key2),
|
||||||
brakeInput, 0.0, false);
|
brakeInput, 0.0, false, flap);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Registers a node's inputs once per tick, and saves its trim to it now and then so it survives reloading. */
|
/** Registers a node's inputs once per tick, and saves its trim to it now and then so it survives reloading. */
|
||||||
@@ -119,7 +127,8 @@ public final class WariumCapture {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
aero.addNode(new NodeData(nodeKey, tag.getDouble("Pitch"), tag.getDouble("Yaw"), tag.getDouble("Roll"),
|
aero.addNode(new NodeData(nodeKey, tag.getDouble("Pitch"), tag.getDouble("Yaw"), tag.getDouble("Roll"),
|
||||||
tag.getDouble("Throttle"), autoTrim, storedTrim));
|
tag.getDouble("Throttle"), autoTrim, storedTrim,
|
||||||
|
FlapSetting.of(tag.getInt(FLAP_SETTING_TAG)).ordinal()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Raw node value for a key like "Pitch+", as Warium's air brakes read it. */
|
/** Raw node value for a key like "Pitch+", as Warium's air brakes read it. */
|
||||||
|
|||||||
+55
@@ -0,0 +1,55 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.flight.mixin.futurism;
|
||||||
|
|
||||||
|
import dev.lumareth.improvedAerodynamics.flight.LiveInputs;
|
||||||
|
import net.mcreator.futurism.procedures.VectoredAfterburnerSystemProcedure;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.world.level.LevelAccessor;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Futurism's vectored afterburner reads the raw key values of its control node, so it ignored cursor aim and the flight
|
||||||
|
* computer. This hands it the same inputs the control surfaces follow ({@link LiveInputs}), through the same Key and Key2
|
||||||
|
* it is configured with. It stays what Futurism made it, 2D vectoring: the procedure still only tilts the thrust up or
|
||||||
|
* down. The value is kept on Warium's 0.2 key steps, since every change of it plays Futurism's servo sound and sends a
|
||||||
|
* block update.
|
||||||
|
*/
|
||||||
|
@Mixin(value = VectoredAfterburnerSystemProcedure.class, remap = false)
|
||||||
|
public abstract class VectoredAfterburnerSystemProcedureMixin {
|
||||||
|
private static final double STEP = 0.2;
|
||||||
|
|
||||||
|
@ModifyVariable(method = "execute", at = @At("STORE"), name = "input")
|
||||||
|
private static double improvedAerodynamics$liveInput(double input, LevelAccessor world, double x, double y, double z, BlockState blockstate) {
|
||||||
|
if (!(world instanceof ServerLevel level)) {
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
BlockEntity own = level.getBlockEntity(BlockPos.containing(x, y, z));
|
||||||
|
if (own == null) {
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
CompoundTag tag = own.getPersistentData();
|
||||||
|
BlockPos nodePos = BlockPos.containing(tag.getDouble("ControlX"), tag.getDouble("ControlY"), tag.getDouble("ControlZ"));
|
||||||
|
BlockEntity node = level.getBlockEntity(nodePos);
|
||||||
|
if (node == null) {
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
long nodeKey = nodePos.asLong();
|
||||||
|
CompoundTag nodeTag = node.getPersistentData();
|
||||||
|
double live = keyInput(nodeKey, nodeTag, tag.getString("Key")) + keyInput(nodeKey, nodeTag, tag.getString("Key2"));
|
||||||
|
live = Math.max(-1.0, Math.min(1.0, live));
|
||||||
|
return Math.round(live / STEP) * STEP;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Like Futurism reads a key: pitch, yaw or roll with its sign, anything else (Throttle, Null) adds nothing. */
|
||||||
|
private static double keyInput(long nodeKey, CompoundTag nodeTag, String key) {
|
||||||
|
if (key.startsWith("Pitch") || key.startsWith("Yaw") || key.startsWith("Roll")) {
|
||||||
|
return LiveInputs.key(nodeKey, nodeTag, key);
|
||||||
|
}
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.flight.mixin.gecko;
|
||||||
|
|
||||||
|
import dev.lumareth.improvedAerodynamics.client.animation.SurfaceAnimation;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
import software.bernie.geckolib.core.animatable.GeoAnimatable;
|
||||||
|
import software.bernie.geckolib.core.animation.AnimationState;
|
||||||
|
import software.bernie.geckolib.model.GeoModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs after GeckoLib has played an animatable's animations, to put Warium's control surfaces at the deflection the
|
||||||
|
* flight physics gives them, see {@link SurfaceAnimation}.
|
||||||
|
*/
|
||||||
|
@Mixin(value = GeoModel.class, remap = false)
|
||||||
|
public abstract class GeoModelMixin {
|
||||||
|
@Inject(method = "handleAnimations", at = @At("RETURN"))
|
||||||
|
private void improvedAerodynamics$deflectSurface(GeoAnimatable animatable, long instanceId, AnimationState animationState, CallbackInfo ci) {
|
||||||
|
if (animatable instanceof BlockEntity blockEntity) {
|
||||||
|
SurfaceAnimation.apply(blockEntity, (GeoModel<?>) (Object) this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+33
@@ -0,0 +1,33 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.flight.mixin.warium;
|
||||||
|
|
||||||
|
import dev.lumareth.improvedAerodynamics.exhaust.ImprovedExhaust;
|
||||||
|
import net.mcreator.valkyrienwarium.procedures.BypassedCompressorScriptProcedure;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.level.LevelAccessor;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
/** The improved exhaust style for the medium bypassed compressor, whose jet effect is an exhaust too: no effect entity, the flame of this mod, see {@link ImprovedExhaust}. */
|
||||||
|
@Mixin(value = BypassedCompressorScriptProcedure.class, remap = false)
|
||||||
|
public abstract class BypassedCompressorScriptProcedureMixin {
|
||||||
|
@Inject(method = "execute", at = @At("HEAD"))
|
||||||
|
private static void improvedAerodynamics$begin(LevelAccessor world, double x, double y, double z, BlockState blockstate, CallbackInfo ci) {
|
||||||
|
ImprovedExhaust.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Redirect(method = "execute", at = @At(value = "INVOKE",
|
||||||
|
target = "Lnet/minecraft/server/level/ServerLevel;m_7967_(Lnet/minecraft/world/entity/Entity;)Z"))
|
||||||
|
private static boolean improvedAerodynamics$addEffect(ServerLevel level, Entity entity) {
|
||||||
|
return ImprovedExhaust.addEffectEntity(level, entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "execute", at = @At("TAIL"))
|
||||||
|
private static void improvedAerodynamics$plume(LevelAccessor world, double x, double y, double z, BlockState blockstate, CallbackInfo ci) {
|
||||||
|
ImprovedExhaust.plume(world, x, y, z, blockstate);
|
||||||
|
}
|
||||||
|
}
|
||||||
+33
@@ -0,0 +1,33 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.flight.mixin.warium;
|
||||||
|
|
||||||
|
import dev.lumareth.improvedAerodynamics.exhaust.ImprovedExhaust;
|
||||||
|
import net.mcreator.valkyrienwarium.procedures.JetExhaustOnTickUpdateProcedure;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.level.LevelAccessor;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
/** The improved exhaust style: no effect entities, a bigger particle plume, see {@link ImprovedExhaust}. */
|
||||||
|
@Mixin(value = JetExhaustOnTickUpdateProcedure.class, remap = false)
|
||||||
|
public abstract class JetExhaustOnTickUpdateProcedureMixin {
|
||||||
|
@Inject(method = "execute", at = @At("HEAD"))
|
||||||
|
private static void improvedAerodynamics$begin(LevelAccessor world, double x, double y, double z, BlockState blockstate, CallbackInfo ci) {
|
||||||
|
ImprovedExhaust.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Redirect(method = "execute", at = @At(value = "INVOKE",
|
||||||
|
target = "Lnet/minecraft/server/level/ServerLevel;m_7967_(Lnet/minecraft/world/entity/Entity;)Z"))
|
||||||
|
private static boolean improvedAerodynamics$addEffect(ServerLevel level, Entity entity) {
|
||||||
|
return ImprovedExhaust.addEffectEntity(level, entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "execute", at = @At("TAIL"))
|
||||||
|
private static void improvedAerodynamics$plume(LevelAccessor world, double x, double y, double z, BlockState blockstate, CallbackInfo ci) {
|
||||||
|
ImprovedExhaust.plume(world, x, y, z, blockstate);
|
||||||
|
}
|
||||||
|
}
|
||||||
+33
@@ -0,0 +1,33 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.flight.mixin.warium;
|
||||||
|
|
||||||
|
import dev.lumareth.improvedAerodynamics.exhaust.ImprovedExhaust;
|
||||||
|
import net.mcreator.valkyrienwarium.procedures.VTOLExhaustTickProcedure;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.level.LevelAccessor;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
/** The improved exhaust style for the VTOL exhaust: no effect entity, the flame of this mod, see {@link ImprovedExhaust}. */
|
||||||
|
@Mixin(value = VTOLExhaustTickProcedure.class, remap = false)
|
||||||
|
public abstract class VTOLExhaustTickProcedureMixin {
|
||||||
|
@Inject(method = "execute", at = @At("HEAD"))
|
||||||
|
private static void improvedAerodynamics$begin(LevelAccessor world, double x, double y, double z, BlockState blockstate, CallbackInfo ci) {
|
||||||
|
ImprovedExhaust.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Redirect(method = "execute", at = @At(value = "INVOKE",
|
||||||
|
target = "Lnet/minecraft/server/level/ServerLevel;m_7967_(Lnet/minecraft/world/entity/Entity;)Z"))
|
||||||
|
private static boolean improvedAerodynamics$addEffect(ServerLevel level, Entity entity) {
|
||||||
|
return ImprovedExhaust.addEffectEntity(level, entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "execute", at = @At("TAIL"))
|
||||||
|
private static void improvedAerodynamics$plume(LevelAccessor world, double x, double y, double z, BlockState blockstate, CallbackInfo ci) {
|
||||||
|
ImprovedExhaust.plume(world, x, y, z, blockstate);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.network;
|
||||||
|
|
||||||
|
import dev.lumareth.improvedAerodynamics.client.animation.SurfaceAnimation;
|
||||||
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
|
import net.minecraftforge.fml.DistExecutor;
|
||||||
|
import net.minecraftforge.network.NetworkEvent;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
/** How far control surfaces are deflected, for the clients near a ship: block positions and tenths of a degree. */
|
||||||
|
public final class DeflectionPacket {
|
||||||
|
private final long[] positions;
|
||||||
|
private final short[] tenths;
|
||||||
|
|
||||||
|
public DeflectionPacket(long[] positions, short[] tenths) {
|
||||||
|
this.positions = positions;
|
||||||
|
this.tenths = tenths;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void encode(FriendlyByteBuf buffer) {
|
||||||
|
buffer.writeVarInt(positions.length);
|
||||||
|
for (int i = 0; i < positions.length; i++) {
|
||||||
|
buffer.writeLong(positions[i]);
|
||||||
|
buffer.writeShort(tenths[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DeflectionPacket decode(FriendlyByteBuf buffer) {
|
||||||
|
int count = buffer.readVarInt();
|
||||||
|
long[] positions = new long[count];
|
||||||
|
short[] tenths = new short[count];
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
positions[i] = buffer.readLong();
|
||||||
|
tenths[i] = buffer.readShort();
|
||||||
|
}
|
||||||
|
return new DeflectionPacket(positions, tenths);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(Supplier<NetworkEvent.Context> context) {
|
||||||
|
long[] pos = positions;
|
||||||
|
short[] values = tenths;
|
||||||
|
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> {
|
||||||
|
for (int i = 0; i < pos.length; i++) {
|
||||||
|
SurfaceAnimation.set(pos[i], values[i] / 10.0F);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
context.get().setPacketHandled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.network;
|
||||||
|
|
||||||
|
import dev.lumareth.improvedAerodynamics.exhaust.client.ExhaustFlames;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
|
import net.minecraftforge.fml.DistExecutor;
|
||||||
|
import net.minecraftforge.network.NetworkEvent;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One jet exhaust that burns right now, sent to the players near it every few ticks: where the flame starts and which
|
||||||
|
* way it points, in the coordinates of the block, which are ship coordinates on a ship. The offset is relative to the
|
||||||
|
* block because ship coordinates are far out, where floats are too coarse.
|
||||||
|
*
|
||||||
|
* @param intensity 0 to 100
|
||||||
|
*/
|
||||||
|
public record ExhaustPacket(BlockPos pos, Vec3 exitOffset, Vec3 direction, int intensity, boolean afterburner) {
|
||||||
|
public void encode(FriendlyByteBuf buffer) {
|
||||||
|
buffer.writeBlockPos(pos);
|
||||||
|
buffer.writeFloat((float) exitOffset.x).writeFloat((float) exitOffset.y).writeFloat((float) exitOffset.z);
|
||||||
|
buffer.writeFloat((float) direction.x).writeFloat((float) direction.y).writeFloat((float) direction.z);
|
||||||
|
buffer.writeByte(intensity);
|
||||||
|
buffer.writeBoolean(afterburner);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ExhaustPacket decode(FriendlyByteBuf buffer) {
|
||||||
|
BlockPos pos = buffer.readBlockPos();
|
||||||
|
Vec3 exit = new Vec3(buffer.readFloat(), buffer.readFloat(), buffer.readFloat());
|
||||||
|
Vec3 direction = new Vec3(buffer.readFloat(), buffer.readFloat(), buffer.readFloat());
|
||||||
|
return new ExhaustPacket(pos, exit, direction, buffer.readByte(), buffer.readBoolean());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(Supplier<NetworkEvent.Context> context) {
|
||||||
|
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> ExhaustFlames.accept(this));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.network;
|
||||||
|
|
||||||
|
import dev.lumareth.improvedAerodynamics.flight.FlapControl;
|
||||||
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraftforge.fml.ModList;
|
||||||
|
import net.minecraftforge.network.NetworkEvent;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
/** Sent when a pilot moves the flap lever: more flaps (true) or fewer. */
|
||||||
|
public final class FlapPacket {
|
||||||
|
private final boolean extend;
|
||||||
|
|
||||||
|
public FlapPacket(boolean extend) {
|
||||||
|
this.extend = extend;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void encode(FriendlyByteBuf buffer) {
|
||||||
|
buffer.writeBoolean(extend);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FlapPacket decode(FriendlyByteBuf buffer) {
|
||||||
|
return new FlapPacket(buffer.readBoolean());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(Supplier<NetworkEvent.Context> context) {
|
||||||
|
ServerPlayer player = context.get().getSender();
|
||||||
|
if (player != null && ModList.get().isLoaded("valkyrien_warium")) {
|
||||||
|
FlapControl.step(player, extend ? 1 : -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,6 +23,16 @@ public final class Network {
|
|||||||
.decoder(ToggleAutoTrimPacket::decode)
|
.decoder(ToggleAutoTrimPacket::decode)
|
||||||
.consumerMainThread(ToggleAutoTrimPacket::handle)
|
.consumerMainThread(ToggleAutoTrimPacket::handle)
|
||||||
.add();
|
.add();
|
||||||
|
CHANNEL.messageBuilder(ToggleAfterburnerPacket.class, 1, NetworkDirection.PLAY_TO_SERVER)
|
||||||
|
.encoder(ToggleAfterburnerPacket::encode)
|
||||||
|
.decoder(ToggleAfterburnerPacket::decode)
|
||||||
|
.consumerMainThread(ToggleAfterburnerPacket::handle)
|
||||||
|
.add();
|
||||||
|
CHANNEL.messageBuilder(ExhaustPacket.class, 2, NetworkDirection.PLAY_TO_CLIENT)
|
||||||
|
.encoder(ExhaustPacket::encode)
|
||||||
|
.decoder(ExhaustPacket::decode)
|
||||||
|
.consumerMainThread(ExhaustPacket::handle)
|
||||||
|
.add();
|
||||||
// High id so it cannot collide with packets added on other branches
|
// High id so it cannot collide with packets added on other branches
|
||||||
CHANNEL.messageBuilder(AimPacket.class, 50, NetworkDirection.PLAY_TO_SERVER)
|
CHANNEL.messageBuilder(AimPacket.class, 50, NetworkDirection.PLAY_TO_SERVER)
|
||||||
.encoder(AimPacket::encode)
|
.encoder(AimPacket::encode)
|
||||||
@@ -34,5 +44,16 @@ public final class Network {
|
|||||||
.decoder(ControlModePacket::decode)
|
.decoder(ControlModePacket::decode)
|
||||||
.consumerMainThread(ControlModePacket::handle)
|
.consumerMainThread(ControlModePacket::handle)
|
||||||
.add();
|
.add();
|
||||||
|
CHANNEL.messageBuilder(DeflectionPacket.class, 11, NetworkDirection.PLAY_TO_CLIENT)
|
||||||
|
.encoder(DeflectionPacket::encode)
|
||||||
|
.decoder(DeflectionPacket::decode)
|
||||||
|
.consumerMainThread(DeflectionPacket::handle)
|
||||||
|
.add();
|
||||||
|
// Higher id than the neighbours so it does not collide with packets added on other branches
|
||||||
|
CHANNEL.messageBuilder(FlapPacket.class, 10, NetworkDirection.PLAY_TO_SERVER)
|
||||||
|
.encoder(FlapPacket::encode)
|
||||||
|
.decoder(FlapPacket::decode)
|
||||||
|
.consumerMainThread(FlapPacket::handle)
|
||||||
|
.add();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.network;
|
||||||
|
|
||||||
|
import dev.lumareth.improvedAerodynamics.exhaust.AfterburnerToggle;
|
||||||
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraftforge.fml.ModList;
|
||||||
|
import net.minecraftforge.network.NetworkEvent;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
/** Sent when a player presses the afterburner key, toggles the afterburner on the control node of the seat they sit in. */
|
||||||
|
public final class ToggleAfterburnerPacket {
|
||||||
|
public void encode(FriendlyByteBuf buffer) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ToggleAfterburnerPacket decode(FriendlyByteBuf buffer) {
|
||||||
|
return new ToggleAfterburnerPacket();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(Supplier<NetworkEvent.Context> context) {
|
||||||
|
ServerPlayer player = context.get().getSender();
|
||||||
|
if (player != null && ModList.get().isLoaded("valkyrien_warium")) {
|
||||||
|
AfterburnerToggle.toggle(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
package dev.lumareth.improvedAerodynamics.terrain;
|
||||||
|
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.resources.ResourceKey;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.world.level.ChunkPos;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||||
|
import net.minecraft.world.level.saveddata.SavedData;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.OptionalInt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Per dimension, the height above which terrain is known to be air, measured from one real chunk with
|
||||||
|
* {@code /aero seedgen}. The air placeholder hands VS only air above it, which beats the noise based estimate in
|
||||||
|
* worlds where that does not work, like flat or void worlds. Saved with the world.
|
||||||
|
*/
|
||||||
|
public final class AirCeiling extends SavedData {
|
||||||
|
private static final String NAME = "improved_aerodynamics_air_ceilings";
|
||||||
|
/** The blocks that are read, clamped to the dimension's build height. */
|
||||||
|
public static final int SCAN_MIN_Y = -64;
|
||||||
|
public static final int SCAN_MAX_Y = 100;
|
||||||
|
|
||||||
|
/** Outcome of reading a chunk. */
|
||||||
|
public record Analysis(boolean complete, int highestSolid, int airHeight) {
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Map<ResourceLocation, Integer> ceilings = new HashMap<>();
|
||||||
|
|
||||||
|
public static AirCeiling get(ServerLevel level) {
|
||||||
|
return level.getServer().overworld().getDataStorage().computeIfAbsent(AirCeiling::load, AirCeiling::new, NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static AirCeiling load(CompoundTag tag) {
|
||||||
|
AirCeiling ceiling = new AirCeiling();
|
||||||
|
CompoundTag saved = tag.getCompound("ceilings");
|
||||||
|
for (String key : saved.getAllKeys()) {
|
||||||
|
ceiling.ceilings.put(new ResourceLocation(key), saved.getInt(key));
|
||||||
|
}
|
||||||
|
return ceiling;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompoundTag save(CompoundTag tag) {
|
||||||
|
CompoundTag saved = new CompoundTag();
|
||||||
|
ceilings.forEach((dimension, height) -> saved.putInt(dimension.toString(), height));
|
||||||
|
tag.put("ceilings", saved);
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Lowest Y at or above which this dimension has only air, if it was measured. */
|
||||||
|
public OptionalInt ceiling(ResourceKey<Level> dimension) {
|
||||||
|
Integer height = ceilings.get(dimension.location());
|
||||||
|
return height != null ? OptionalInt.of(height) : OptionalInt.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(ResourceKey<Level> dimension, int height) {
|
||||||
|
ceilings.put(dimension.location(), height);
|
||||||
|
setDirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean clear(ResourceKey<Level> dimension) {
|
||||||
|
boolean removed = ceilings.remove(dimension.location()) != null;
|
||||||
|
if (removed) {
|
||||||
|
setDirty();
|
||||||
|
}
|
||||||
|
return removed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the chunk's blocks (generating the chunk if it does not exist yet) from the top of the scan range down
|
||||||
|
* and finds the first layer with anything but air in it. Not complete if that layer is the top of the range,
|
||||||
|
* since then the air may start higher up than what was read.
|
||||||
|
*/
|
||||||
|
public static Analysis analyze(ServerLevel level, ChunkPos pos) {
|
||||||
|
ChunkAccess chunk = level.getChunk(pos.x, pos.z);
|
||||||
|
int bottom = Math.max(SCAN_MIN_Y, level.getMinBuildHeight());
|
||||||
|
int top = Math.min(SCAN_MAX_Y, level.getMaxBuildHeight() - 1);
|
||||||
|
BlockPos.MutableBlockPos cursor = new BlockPos.MutableBlockPos();
|
||||||
|
for (int y = top; y >= bottom; y--) {
|
||||||
|
for (int x = 0; x < 16; x++) {
|
||||||
|
for (int z = 0; z < 16; z++) {
|
||||||
|
if (!chunk.getBlockState(cursor.set(pos.getMinBlockX() + x, y, pos.getMinBlockZ() + z)).isAir()) {
|
||||||
|
return new Analysis(y < top, y, y + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new Analysis(true, bottom - 1, bottom);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,11 +22,13 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.OptionalInt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optional: hands VS empty sections for not yet loaded chunks on a ship's path, so physics sees air there instead of
|
* Optional: hands VS empty sections for not yet loaded chunks on a ship's path, so physics sees air there instead of
|
||||||
* its solid "unloaded" fallback. Only sections fully above the generator's estimated surface (plus a margin) are
|
* its solid "unloaded" fallback. Only sections fully above the generator's estimated surface (plus a margin) are
|
||||||
* replaced, everything lower stays solid so a ship can never end up inside terrain that has not loaded yet.
|
* replaced, everything lower stays solid so a ship can never end up inside terrain that has not loaded yet.
|
||||||
|
* If a height was measured with /aero seedgen, every section from there up is replaced instead.
|
||||||
* Once the real chunk loads, VS overwrites every section of it with the actual terrain.
|
* Once the real chunk loads, VS overwrites every section of it with the actual terrain.
|
||||||
* <p>
|
* <p>
|
||||||
* This uses VS internals (its terrain update API and the mixin field listing its loaded chunks), so it switches
|
* This uses VS internals (its terrain update API and the mixin field listing its loaded chunks), so it switches
|
||||||
@@ -76,6 +78,8 @@ final class AirPlaceholder {
|
|||||||
if (enabled) {
|
if (enabled) {
|
||||||
int budget = Config.MAX_NEW_CHUNKS_PER_TICK.get();
|
int budget = Config.MAX_NEW_CHUNKS_PER_TICK.get();
|
||||||
int surfaceMargin = Config.PLACEHOLDER_SURFACE_MARGIN.get();
|
int surfaceMargin = Config.PLACEHOLDER_SURFACE_MARGIN.get();
|
||||||
|
// Measured with /aero seedgen, replaces the estimate (and its margin) for this dimension
|
||||||
|
OptionalInt airHeight = AirCeiling.get(level).ceiling(level.dimension());
|
||||||
for (long chunk : corridor) {
|
for (long chunk : corridor) {
|
||||||
Placeholder placeholder = placeholders.get(chunk);
|
Placeholder placeholder = placeholders.get(chunk);
|
||||||
if (placeholder != null) {
|
if (placeholder != null) {
|
||||||
@@ -90,7 +94,8 @@ final class AirPlaceholder {
|
|||||||
if (budget-- <= 0) {
|
if (budget-- <= 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
int minSectionY = Math.floorDiv(estimateSurface(level, pos) + surfaceMargin, 16) + 1;
|
int minSectionY = airHeight.isPresent() ? Math.floorDiv(airHeight.getAsInt() + 15, 16)
|
||||||
|
: Math.floorDiv(estimateSurface(level, pos) + surfaceMargin, 16) + 1;
|
||||||
int maxSectionY = level.getMaxSection() - 1;
|
int maxSectionY = level.getMaxSection() - 1;
|
||||||
if (minSectionY > maxSectionY) {
|
if (minSectionY > maxSectionY) {
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -45,3 +45,11 @@ mandatory = false
|
|||||||
versionRange = "[0.0.4,)"
|
versionRange = "[0.0.4,)"
|
||||||
ordering = "AFTER"
|
ordering = "AFTER"
|
||||||
side = "BOTH"
|
side = "BOTH"
|
||||||
|
|
||||||
|
# Optional, animated block models
|
||||||
|
[[dependencies."${mod_id}"]]
|
||||||
|
modId = "azurelib"
|
||||||
|
mandatory = false
|
||||||
|
versionRange = "[3.2.7,)"
|
||||||
|
ordering = "AFTER"
|
||||||
|
side = "BOTH"
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"format_version": "1.8.0",
|
||||||
|
"animations": {
|
||||||
|
"animation.model.nozzle": {
|
||||||
|
"loop": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"variants": {
|
||||||
|
"": {
|
||||||
|
"model": "improved_aerodynamics:block/vectored_afterburner_nozzle"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+113
@@ -0,0 +1,113 @@
|
|||||||
|
{
|
||||||
|
"format_version": "1.21.20",
|
||||||
|
"minecraft:geometry": [
|
||||||
|
{
|
||||||
|
"description": {
|
||||||
|
"identifier": "geometry.unknown",
|
||||||
|
"texture_width": 16,
|
||||||
|
"texture_height": 16,
|
||||||
|
"visible_bounds_width": 3,
|
||||||
|
"visible_bounds_height": 2.5,
|
||||||
|
"visible_bounds_offset": [0, 0.75, 0]
|
||||||
|
},
|
||||||
|
"bones": [
|
||||||
|
{
|
||||||
|
"name": "bb_main",
|
||||||
|
"pivot": [0, 0, 0],
|
||||||
|
"cubes": [
|
||||||
|
{
|
||||||
|
"origin": [-16, 0, 10],
|
||||||
|
"size": [16, 16, 6],
|
||||||
|
"uv": {
|
||||||
|
"north": {"uv": [1.5, 1.5], "uv_size": [4, 4]},
|
||||||
|
"east": {"uv": [0, 1.5], "uv_size": [1.5, 4]},
|
||||||
|
"south": {"uv": [7, 1.5], "uv_size": [4, 4]},
|
||||||
|
"west": {"uv": [5.5, 1.5], "uv_size": [1.5, 4]},
|
||||||
|
"up": {"uv": [1.5, 0], "uv_size": [4, 1.5]},
|
||||||
|
"down": {"uv": [5.5, 1.5], "uv_size": [4, -1.5]}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "hinge",
|
||||||
|
"pivot": [-8, 8, 10],
|
||||||
|
"rotation": [0, 0, 32.5]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "rotation",
|
||||||
|
"parent": "hinge",
|
||||||
|
"pivot": [-8, 8, 10]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "counter",
|
||||||
|
"parent": "rotation",
|
||||||
|
"pivot": [-8, 8, 10],
|
||||||
|
"rotation": [0, 0, -32.5],
|
||||||
|
"cubes": [
|
||||||
|
{
|
||||||
|
"origin": [-15, 1, 0],
|
||||||
|
"size": [14, 2, 10],
|
||||||
|
"uv": {
|
||||||
|
"north": {"uv": [2.5, 8], "uv_size": [3.5, 0.5]},
|
||||||
|
"east": {"uv": [0, 8], "uv_size": [2.5, 0.5]},
|
||||||
|
"south": {"uv": [8.5, 8], "uv_size": [3.5, 0.5]},
|
||||||
|
"west": {"uv": [6, 8], "uv_size": [2.5, 0.5]},
|
||||||
|
"up": {"uv": [2.5, 5.5], "uv_size": [3.5, 2.5]},
|
||||||
|
"down": {"uv": [6, 8], "uv_size": [3.5, -2.5]}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"origin": [-15, 13, 0],
|
||||||
|
"size": [14, 2, 10],
|
||||||
|
"uv": {
|
||||||
|
"north": {"uv": [6.5, 15.5], "uv_size": [3.5, 0.5]},
|
||||||
|
"east": {"uv": [4, 15.5], "uv_size": [2.5, 0.5]},
|
||||||
|
"south": {"uv": [12.5, 15.5], "uv_size": [3.5, 0.5]},
|
||||||
|
"west": {"uv": [10, 15.5], "uv_size": [2.5, 0.5]},
|
||||||
|
"up": {"uv": [6.5, 13], "uv_size": [3.5, 2.5]},
|
||||||
|
"down": {"uv": [10, 15.5], "uv_size": [3.5, -2.5]}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"origin": [-15, 3, 0],
|
||||||
|
"size": [2, 10, 10],
|
||||||
|
"uv": {
|
||||||
|
"north": {"uv": [2.5, 11], "uv_size": [0.5, 2.5]},
|
||||||
|
"east": {"uv": [0, 11], "uv_size": [2.5, 2.5]},
|
||||||
|
"south": {"uv": [5.5, 11], "uv_size": [0.5, 2.5]},
|
||||||
|
"west": {"uv": [3, 11], "uv_size": [2.5, 2.5]},
|
||||||
|
"up": {"uv": [2.5, 8.5], "uv_size": [0.5, 2.5]},
|
||||||
|
"down": {"uv": [3, 11], "uv_size": [0.5, -2.5]}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"origin": [-3, 3, 0],
|
||||||
|
"size": [2, 10, 10],
|
||||||
|
"uv": {
|
||||||
|
"north": {"uv": [3, 11], "uv_size": [-0.5, 2.5]},
|
||||||
|
"east": {"uv": [5.5, 11], "uv_size": [-2.5, 2.5]},
|
||||||
|
"south": {"uv": [6, 11], "uv_size": [-0.5, 2.5]},
|
||||||
|
"west": {"uv": [2.5, 11], "uv_size": [-2.5, 2.5]},
|
||||||
|
"up": {"uv": [3, 8.5], "uv_size": [-0.5, 2.5]},
|
||||||
|
"down": {"uv": [3.5, 11], "uv_size": [-0.5, -2.5]}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"origin": [-11, 5, 4],
|
||||||
|
"size": [6, 6, 6],
|
||||||
|
"uv": {
|
||||||
|
"north": {"uv": [7.5, 10], "uv_size": [1.5, 1.5]},
|
||||||
|
"east": {"uv": [6, 10], "uv_size": [1.5, 1.5]},
|
||||||
|
"south": {"uv": [10.5, 10], "uv_size": [1.5, 1.5]},
|
||||||
|
"west": {"uv": [9, 10], "uv_size": [1.5, 1.5]},
|
||||||
|
"up": {"uv": [7.5, 8.5], "uv_size": [1.5, 1.5]},
|
||||||
|
"down": {"uv": [9, 10], "uv_size": [1.5, -1.5]}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -13,9 +13,30 @@
|
|||||||
"config.improved_aerodynamics.vortexLift": "Wirbelauftrieb: Flügel mit kleiner Streckung (Deltaflügel) überziehen später und liefern bei großen Anstellwinkeln mehr Auftrieb (verbessertes Flugmodell)",
|
"config.improved_aerodynamics.vortexLift": "Wirbelauftrieb: Flügel mit kleiner Streckung (Deltaflügel) überziehen später und liefern bei großen Anstellwinkeln mehr Auftrieb (verbessertes Flugmodell)",
|
||||||
"config.improved_aerodynamics.vortexStallBonus": "Zusätzlicher Überziehwinkel der Flügel mit der kleinsten Streckung, als Anteil des normalen Überziehwinkels",
|
"config.improved_aerodynamics.vortexStallBonus": "Zusätzlicher Überziehwinkel der Flügel mit der kleinsten Streckung, als Anteil des normalen Überziehwinkels",
|
||||||
"config.improved_aerodynamics.vortexLiftStrength": "Multiplikator für den zusätzlichen Auftrieb der Vorderkantenwirbel",
|
"config.improved_aerodynamics.vortexLiftStrength": "Multiplikator für den zusätzlichen Auftrieb der Vorderkantenwirbel",
|
||||||
|
"block.improved_aerodynamics.vectored_afterburner_nozzle": "Schubvektor-Nachbrennerdüse",
|
||||||
|
"itemGroup.improved_aerodynamics": "Improved Aerodynamics",
|
||||||
|
"message.improved_aerodynamics.nozzle.left": "Düse auf linkes Triebwerk gestellt",
|
||||||
|
"message.improved_aerodynamics.nozzle.right": "Düse auf rechtes Triebwerk gestellt",
|
||||||
|
"key.improved_aerodynamics.toggle_afterburner": "Nachbrenner umschalten",
|
||||||
|
"message.improved_aerodynamics.afterburner.on": "Nachbrenner an",
|
||||||
|
"message.improved_aerodynamics.afterburner.off": "Nachbrenner aus",
|
||||||
|
"message.improved_aerodynamics.afterburner.throttle": "Der Nachbrenner braucht mindestens Schub %s",
|
||||||
|
"message.improved_aerodynamics.afterburner.no_seat": "Setz dich in einen Warium-Steuersitz, um den Nachbrenner zu nutzen",
|
||||||
|
"message.improved_aerodynamics.afterburner.no_node": "Dieser Sitz ist mit keinem Vehicle Control Node verbunden",
|
||||||
"key.improved_aerodynamics.cursor_aim_free_look": "Cursor-Steuerung: Freie Sicht (halten)",
|
"key.improved_aerodynamics.cursor_aim_free_look": "Cursor-Steuerung: Freie Sicht (halten)",
|
||||||
"message.improved_aerodynamics.cursor_aim.on": "Cursor-Steuerung an",
|
"message.improved_aerodynamics.cursor_aim.on": "Cursor-Steuerung an",
|
||||||
"message.improved_aerodynamics.cursor_aim.off": "Cursor-Steuerung aus",
|
"message.improved_aerodynamics.cursor_aim.off": "Cursor-Steuerung aus",
|
||||||
"message.improved_aerodynamics.cursor_aim.no_seat": "Setz dich in einen Warium-Steuersitz, um die Cursor-Steuerung zu nutzen",
|
"message.improved_aerodynamics.cursor_aim.no_seat": "Setz dich in einen Warium-Steuersitz, um die Cursor-Steuerung zu nutzen",
|
||||||
"message.improved_aerodynamics.cursor_aim.no_server": "Dieser Server hat Improved Aerodynamics nicht, die Cursor-Steuerung braucht es"
|
"message.improved_aerodynamics.cursor_aim.no_server": "Dieser Server hat Improved Aerodynamics nicht, die Cursor-Steuerung braucht es",
|
||||||
|
"key.improved_aerodynamics.flaps_down": "Klappen runter (eine Stufe)",
|
||||||
|
"key.improved_aerodynamics.flaps_up": "Klappen rauf (eine Stufe)",
|
||||||
|
"message.improved_aerodynamics.flaps": "Klappen: %s",
|
||||||
|
"message.improved_aerodynamics.flaps.up": "eingefahren",
|
||||||
|
"message.improved_aerodynamics.flaps.takeoff": "Start",
|
||||||
|
"message.improved_aerodynamics.flaps.landing": "Landung",
|
||||||
|
"message.improved_aerodynamics.flaps.no_seat": "Setz dich in einen Warium-Steuersitz, um die Klappen zu nutzen",
|
||||||
|
"message.improved_aerodynamics.flaps.no_node": "Dieser Sitz ist mit keinem Vehicle Control Node verbunden",
|
||||||
|
"message.improved_aerodynamics.flap.on": "Das Ruder ist jetzt eine Klappe",
|
||||||
|
"message.improved_aerodynamics.flap.off": "Das Ruder ist wieder ein normales Ruder",
|
||||||
|
"message.improved_aerodynamics.flap.unlinked": "Das Ruder ist jetzt eine Klappe, aber noch mit keinem Vehicle Control Node verbunden"
|
||||||
}
|
}
|
||||||
@@ -13,9 +13,30 @@
|
|||||||
"config.improved_aerodynamics.vortexLift": "Vortex lift: low aspect ratio (delta) wings stall later and lift more at high angles of attack (improved flight model)",
|
"config.improved_aerodynamics.vortexLift": "Vortex lift: low aspect ratio (delta) wings stall later and lift more at high angles of attack (improved flight model)",
|
||||||
"config.improved_aerodynamics.vortexStallBonus": "Extra stall angle of the lowest aspect ratio wings, as a fraction of the normal stall angle",
|
"config.improved_aerodynamics.vortexStallBonus": "Extra stall angle of the lowest aspect ratio wings, as a fraction of the normal stall angle",
|
||||||
"config.improved_aerodynamics.vortexLiftStrength": "Multiplier for the extra lift the leading-edge vortices make",
|
"config.improved_aerodynamics.vortexLiftStrength": "Multiplier for the extra lift the leading-edge vortices make",
|
||||||
|
"block.improved_aerodynamics.vectored_afterburner_nozzle": "Vectored Afterburner Nozzle",
|
||||||
|
"itemGroup.improved_aerodynamics": "Improved Aerodynamics",
|
||||||
|
"message.improved_aerodynamics.nozzle.left": "Nozzle set to left engine",
|
||||||
|
"message.improved_aerodynamics.nozzle.right": "Nozzle set to right engine",
|
||||||
|
"key.improved_aerodynamics.toggle_afterburner": "Toggle afterburner",
|
||||||
|
"message.improved_aerodynamics.afterburner.on": "Afterburner on",
|
||||||
|
"message.improved_aerodynamics.afterburner.off": "Afterburner off",
|
||||||
|
"message.improved_aerodynamics.afterburner.throttle": "The afterburner needs a throttle of at least %s",
|
||||||
|
"message.improved_aerodynamics.afterburner.no_seat": "Sit in a Warium control seat to use the afterburner",
|
||||||
|
"message.improved_aerodynamics.afterburner.no_node": "This seat is not linked to a vehicle control node",
|
||||||
"key.improved_aerodynamics.cursor_aim_free_look": "Cursor aim: free look (hold)",
|
"key.improved_aerodynamics.cursor_aim_free_look": "Cursor aim: free look (hold)",
|
||||||
"message.improved_aerodynamics.cursor_aim.on": "Cursor aim on",
|
"message.improved_aerodynamics.cursor_aim.on": "Cursor aim on",
|
||||||
"message.improved_aerodynamics.cursor_aim.off": "Cursor aim off",
|
"message.improved_aerodynamics.cursor_aim.off": "Cursor aim off",
|
||||||
"message.improved_aerodynamics.cursor_aim.no_seat": "Sit in a Warium control seat to use cursor aim",
|
"message.improved_aerodynamics.cursor_aim.no_seat": "Sit in a Warium control seat to use cursor aim",
|
||||||
"message.improved_aerodynamics.cursor_aim.no_server": "This server does not have Improved Aerodynamics, cursor aim needs it"
|
"message.improved_aerodynamics.cursor_aim.no_server": "This server does not have Improved Aerodynamics, cursor aim needs it",
|
||||||
|
"key.improved_aerodynamics.flaps_down": "Flaps down (one step)",
|
||||||
|
"key.improved_aerodynamics.flaps_up": "Flaps up (one step)",
|
||||||
|
"message.improved_aerodynamics.flaps": "Flaps: %s",
|
||||||
|
"message.improved_aerodynamics.flaps.up": "up",
|
||||||
|
"message.improved_aerodynamics.flaps.takeoff": "takeoff",
|
||||||
|
"message.improved_aerodynamics.flaps.landing": "landing",
|
||||||
|
"message.improved_aerodynamics.flaps.no_seat": "Sit in a Warium control seat to use the flaps",
|
||||||
|
"message.improved_aerodynamics.flaps.no_node": "This seat is not linked to a vehicle control node",
|
||||||
|
"message.improved_aerodynamics.flap.on": "Control surface is now a flap",
|
||||||
|
"message.improved_aerodynamics.flap.off": "Control surface is a normal control surface again",
|
||||||
|
"message.improved_aerodynamics.flap.unlinked": "Control surface is now a flap, but it is not linked to a vehicle control node yet"
|
||||||
}
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"textures": {
|
||||||
|
"particle": "minecraft:block/iron_block"
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"parent": "minecraft:block/cube_all",
|
||||||
|
"textures": {
|
||||||
|
"all": "minecraft:block/iron_block"
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 2.3 KiB |
+20
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"type": "minecraft:block",
|
||||||
|
"pools": [
|
||||||
|
{
|
||||||
|
"rolls": 1.0,
|
||||||
|
"bonus_rolls": 0.0,
|
||||||
|
"entries": [
|
||||||
|
{
|
||||||
|
"type": "minecraft:item",
|
||||||
|
"name": "improved_aerodynamics:vectored_afterburner_nozzle"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"conditions": [
|
||||||
|
{
|
||||||
|
"condition": "minecraft:survives_explosion"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,233 @@
|
|||||||
|
{
|
||||||
|
"replace": false,
|
||||||
|
"values": [
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:control_surface",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:control_surface_offset_top",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:control_surface_offset_bottom",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:control_surface_dark_gray",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:control_surface_offset_top_dark_gray",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:control_surface_offset_bottom_dark_gray",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:wooden_control_surface",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:wooden_control_surface_offset_top",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:wooden_control_surface_offset_bottom",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:red_control_surface",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:red_control_surface_offset_top",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:red_control_surface_offset_bottom",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:blue_control_surface",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:blue_control_surface_offset_top",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:blue_control_surface_offset_bottom",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:brown_control_surface",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:brown_control_surface_offset_top",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:brown_control_surface_offset_bottom",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:green_control_surface",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:green_control_surface_offset_bottom",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:cyan_control_surface",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:cyan_control_surface_offset_top",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:cyan_control_surface_offset_bottom",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:orange_control_surface",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:orange_control_surface_offset_top",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:orange_control_surface_offset_bottom",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:yellow_control_surface",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:yellow_control_surface_offset_top",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:yellow_control_surface_offset_bottom",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:gray_control_surface",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:gray_control_surface_offset_top",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:gray_control_surface_offset_bottom",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:light_gray_control_surface",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:light_gray_control_surface_offset_top",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:light_gray_control_surface_offset_bottom",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:light_blue_control_surface",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:light_blue_control_surface_offset_top",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:light_blue_control_surface_offset_bottom",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:pink_control_surface",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:pink_control_surface_offset_top",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:pink_control_surface_offset_bottom",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:magenta_control_surface",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:magenta_control_surface_offset_top",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:magenta_control_surface_offset_bottom",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:purple_control_surface",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:purple_control_surface_offset_top",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:purple_control_surface_offset_bottom",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:white_control_surface",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:white_control_surface_offset_top",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:white_control_surface_offset_bottom",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:black_control_surface",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:black_control_surface_offset_top",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:black_control_surface_offset_bottom",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "valkyrien_warium:green_control_surface_offset_top",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "warframes:airframe_control_surface",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "warframes:airframe_half_control_surface",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "warframes:airframe_stepped_control_surface",
|
||||||
|
"required": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"block": "improved_aerodynamics:vectored_afterburner_nozzle",
|
||||||
|
"mass": 500.0,
|
||||||
|
"priority": 101
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"replace": false,
|
||||||
|
"values": [
|
||||||
|
"improved_aerodynamics:vectored_afterburner_nozzle"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"replace": false,
|
||||||
|
"values": [
|
||||||
|
"improved_aerodynamics:vectored_afterburner_nozzle"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"replace": false,
|
||||||
|
"values": [
|
||||||
|
"improved_aerodynamics:vectored_afterburner_nozzle"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"replace": false,
|
||||||
|
"values": [
|
||||||
|
"improved_aerodynamics:vectored_afterburner_nozzle"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"replace": false,
|
||||||
|
"values": [
|
||||||
|
{ "id": "valkyrien_warium:slim_landing_gear_bay", "required": false },
|
||||||
|
{ "id": "valkyrien_warium:open_slim_landing_gear_bay", "required": false },
|
||||||
|
{ "id": "warframes:airframe_slim_landing_gear_bay", "required": false },
|
||||||
|
{ "id": "warframes:airframe_slab_landing_gear_bay", "required": false }
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -6,11 +6,16 @@
|
|||||||
"compatibilityLevel": "JAVA_17",
|
"compatibilityLevel": "JAVA_17",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"futurism.ForceInducedShipsMixin",
|
"futurism.ForceInducedShipsMixin",
|
||||||
|
"futurism.VectoredAfterburnerSystemProcedureMixin",
|
||||||
|
"gecko.GeoModelMixin",
|
||||||
"warium.AirBrakeTickProcedureMixin",
|
"warium.AirBrakeTickProcedureMixin",
|
||||||
|
"warium.BypassedCompressorScriptProcedureMixin",
|
||||||
"warium.ControlSurfaceTickProcedureMixin",
|
"warium.ControlSurfaceTickProcedureMixin",
|
||||||
"warium.ForceInducedShipsMixin",
|
"warium.ForceInducedShipsMixin",
|
||||||
"warium.HorizontalStabilizerScriptProcedureMixin",
|
"warium.HorizontalStabilizerScriptProcedureMixin",
|
||||||
"warium.HorizontalWingScriptProcedureMixin",
|
"warium.HorizontalWingScriptProcedureMixin",
|
||||||
|
"warium.JetExhaustOnTickUpdateProcedureMixin",
|
||||||
|
"warium.VTOLExhaustTickProcedureMixin",
|
||||||
"warium.VerticalAirBrakeTickProcedureMixin",
|
"warium.VerticalAirBrakeTickProcedureMixin",
|
||||||
"warium.VerticalControlSurfaceTickProcedureMixin",
|
"warium.VerticalControlSurfaceTickProcedureMixin",
|
||||||
"warium.VerticalWingScriptProcedureMixin"
|
"warium.VerticalWingScriptProcedureMixin"
|
||||||
|
|||||||
Reference in new issue
Block a user