diff --git a/src/main/java/ru/octol1ttle/flightassistant/FAKeyBindings.java b/src/main/java/ru/octol1ttle/flightassistant/FAKeyBindings.java index 11810b29..c6b23c4f 100644 --- a/src/main/java/ru/octol1ttle/flightassistant/FAKeyBindings.java +++ b/src/main/java/ru/octol1ttle/flightassistant/FAKeyBindings.java @@ -53,8 +53,8 @@ public static void setup() { } while (toggleAutoFirework.wasPressed()) { - if (!autoflight.autoFireworkEnabled) { - autoflight.autoFireworkEnabled = true; + if (!autoflight.autoThrustEnabled) { + autoflight.autoThrustEnabled = true; } else { autoflight.disconnectAutoFirework(false); } diff --git a/src/main/java/ru/octol1ttle/flightassistant/alerts/impl/autoflight/AutoFireworkOffAlert.java b/src/main/java/ru/octol1ttle/flightassistant/alerts/impl/autoflight/AutoFireworkOffAlert.java index 452b2319..9e46872a 100644 --- a/src/main/java/ru/octol1ttle/flightassistant/alerts/impl/autoflight/AutoFireworkOffAlert.java +++ b/src/main/java/ru/octol1ttle/flightassistant/alerts/impl/autoflight/AutoFireworkOffAlert.java @@ -5,9 +5,9 @@ import net.minecraft.text.Text; import org.jetbrains.annotations.NotNull; import ru.octol1ttle.flightassistant.DrawHelper; -import ru.octol1ttle.flightassistant.alerts.impl.AlertSoundData; import ru.octol1ttle.flightassistant.alerts.api.BaseAlert; import ru.octol1ttle.flightassistant.alerts.api.IECAMAlert; +import ru.octol1ttle.flightassistant.alerts.impl.AlertSoundData; import ru.octol1ttle.flightassistant.computers.impl.autoflight.AutoFlightComputer; import ru.octol1ttle.flightassistant.config.FAConfig; import ru.octol1ttle.flightassistant.registries.ComputerRegistry; @@ -21,18 +21,19 @@ public AutoFireworkOffAlert() { @Override public boolean isTriggered() { - return !autoflight.autoFireworkEnabled; + return !autoflight.autoThrustEnabled; } @Override public @NotNull AlertSoundData getSoundData() { - return autoflight.afrwkDisconnectionForced ? AlertSoundData.MASTER_CAUTION : AlertSoundData.EMPTY; + return autoflight.athrDisconnectionForced ? AlertSoundData.MASTER_CAUTION : AlertSoundData.EMPTY; } @Override public int render(TextRenderer textRenderer, DrawContext context, int x, int y, boolean highlight) { return DrawHelper.drawHighlightedText(textRenderer, context, Text.translatable("alerts.flightassistant.autoflight.auto_firework_off"), x, y, FAConfig.indicator().cautionColor, - highlight && autoflight.afrwkDisconnectionForced); + highlight && autoflight.athrDisconnectionForced + ); } } diff --git a/src/main/java/ru/octol1ttle/flightassistant/compatibility/doabarrelroll/DaBRThrustHandler.java b/src/main/java/ru/octol1ttle/flightassistant/compatibility/doabarrelroll/DaBRThrustHandler.java new file mode 100644 index 00000000..921654ad --- /dev/null +++ b/src/main/java/ru/octol1ttle/flightassistant/compatibility/doabarrelroll/DaBRThrustHandler.java @@ -0,0 +1,27 @@ +package ru.octol1ttle.flightassistant.compatibility.doabarrelroll; + +import nl.enjarai.doabarrelroll.api.event.ThrustEvents; +import ru.octol1ttle.flightassistant.computers.api.IThrustHandler; +import ru.octol1ttle.flightassistant.computers.impl.TimeComputer; +import ru.octol1ttle.flightassistant.computers.impl.autoflight.AutoFlightComputer; +import ru.octol1ttle.flightassistant.computers.impl.autoflight.ThrustController; +import ru.octol1ttle.flightassistant.registries.ComputerRegistry; + +public class DaBRThrustHandler implements IThrustHandler { + private final AutoFlightComputer autoflight = ComputerRegistry.resolve(AutoFlightComputer.class); + private final ThrustController thrust = ComputerRegistry.resolve(ThrustController.class); + private final TimeComputer time = ComputerRegistry.resolve(TimeComputer.class); + + public DaBRThrustHandler() { + ThrustEvents.MODIFY_THRUST_INPUT.register(v -> { + if (Math.abs(v) > 0.001f) { + autoflight.disconnectAutoFirework(true); + } + return thrust.targetThrust += (float) (v * time.deltaTime * 0.5f); + }); + } + + @Override + public void reset() { + } +} diff --git a/src/main/java/ru/octol1ttle/flightassistant/computers/ComputerHost.java b/src/main/java/ru/octol1ttle/flightassistant/computers/ComputerHost.java index c3d46a44..0ca389c7 100644 --- a/src/main/java/ru/octol1ttle/flightassistant/computers/ComputerHost.java +++ b/src/main/java/ru/octol1ttle/flightassistant/computers/ComputerHost.java @@ -14,6 +14,7 @@ import ru.octol1ttle.flightassistant.computers.impl.autoflight.HeadingController; import ru.octol1ttle.flightassistant.computers.impl.autoflight.PitchController; import ru.octol1ttle.flightassistant.computers.impl.autoflight.RollController; +import ru.octol1ttle.flightassistant.computers.impl.autoflight.ThrustController; import ru.octol1ttle.flightassistant.computers.impl.navigation.FlightPlanner; import ru.octol1ttle.flightassistant.computers.impl.safety.AlertController; import ru.octol1ttle.flightassistant.computers.impl.safety.ChunkStatusComputer; @@ -36,8 +37,8 @@ public ComputerHost(@NotNull MinecraftClient mc) { ComputerRegistry.register(new TimeComputer(mc)); ComputerRegistry.register(new FireworkController(mc)); ComputerRegistry.register(new PitchLimitComputer()); - ComputerRegistry.register(new PitchController()); ComputerRegistry.register(new FlightProtectionsComputer()); + ComputerRegistry.register(new PitchController()); ComputerRegistry.register(new ChunkStatusComputer()); ComputerRegistry.register(new StallComputer()); ComputerRegistry.register(new VoidLevelComputer()); @@ -49,6 +50,7 @@ public ComputerHost(@NotNull MinecraftClient mc) { ComputerRegistry.register(new AutoFlightComputer()); ComputerRegistry.register(new FlightPhaseComputer()); ComputerRegistry.register(new AutopilotControlComputer()); + ComputerRegistry.register(new ThrustController()); ComputerRegistry.register(new AlertController(mc.getSoundManager())); CustomComputerRegistrationCallback.EVENT.invoker().registerCustomComputers(); diff --git a/src/main/java/ru/octol1ttle/flightassistant/computers/api/IHeadingController.java b/src/main/java/ru/octol1ttle/flightassistant/computers/api/IHeadingController.java index 4348a0b4..1cf4f6c8 100644 --- a/src/main/java/ru/octol1ttle/flightassistant/computers/api/IHeadingController.java +++ b/src/main/java/ru/octol1ttle/flightassistant/computers/api/IHeadingController.java @@ -5,7 +5,7 @@ public interface IHeadingController extends IComputer { /** * Gets the target heading that this controller wants - * @return a {@link ControlInput} with {@link ControlInput#target} being the target heading + * @return a {@link ControlInput} with {@link ControlInput#target()} being the target heading */ @Nullable ControlInput getHeadingInput(); diff --git a/src/main/java/ru/octol1ttle/flightassistant/computers/api/IPitchController.java b/src/main/java/ru/octol1ttle/flightassistant/computers/api/IPitchController.java index 25ad9305..1bcda62c 100644 --- a/src/main/java/ru/octol1ttle/flightassistant/computers/api/IPitchController.java +++ b/src/main/java/ru/octol1ttle/flightassistant/computers/api/IPitchController.java @@ -5,8 +5,8 @@ public interface IPitchController extends IComputer { /** * Gets the target pitch that this controller wants - * @return a {@link ControlInput} with {@link ControlInput#target} being the target pitch + * @return a {@link ControlInput} with {@link ControlInput#target()} being the target pitch */ @Nullable ControlInput getPitchInput(); -} \ No newline at end of file +} diff --git a/src/main/java/ru/octol1ttle/flightassistant/computers/api/IRollController.java b/src/main/java/ru/octol1ttle/flightassistant/computers/api/IRollController.java index 2030a93f..30ae6a72 100644 --- a/src/main/java/ru/octol1ttle/flightassistant/computers/api/IRollController.java +++ b/src/main/java/ru/octol1ttle/flightassistant/computers/api/IRollController.java @@ -6,8 +6,8 @@ public interface IRollController extends IComputer { /** * Gets the target roll that this controller wants * - * @return a {@link ControlInput} with {@link ControlInput#target} being the target roll + * @return a {@link ControlInput} with {@link ControlInput#target()} being the target roll */ @Nullable ControlInput getRollInput(); -} \ No newline at end of file +} diff --git a/src/main/java/ru/octol1ttle/flightassistant/computers/api/IThrustController.java b/src/main/java/ru/octol1ttle/flightassistant/computers/api/IThrustController.java new file mode 100644 index 00000000..586eb1e7 --- /dev/null +++ b/src/main/java/ru/octol1ttle/flightassistant/computers/api/IThrustController.java @@ -0,0 +1,10 @@ +package ru.octol1ttle.flightassistant.computers.api; + +public interface IThrustController extends IComputer { + /** + * Gets the target thrust that this controller wants + * + * @return a {@link ThrustControlInput} with {@link ThrustControlInput#target()} being the target thrust + */ + ThrustControlInput getThrustInput(); +} diff --git a/src/main/java/ru/octol1ttle/flightassistant/computers/api/IThrustHandler.java b/src/main/java/ru/octol1ttle/flightassistant/computers/api/IThrustHandler.java new file mode 100644 index 00000000..ffc34a18 --- /dev/null +++ b/src/main/java/ru/octol1ttle/flightassistant/computers/api/IThrustHandler.java @@ -0,0 +1,11 @@ +package ru.octol1ttle.flightassistant.computers.api; + +import ru.octol1ttle.flightassistant.computers.impl.autoflight.ThrustController; + +/** + * Implementing classes should inject ThrustController and use {@link ThrustController#currentThrust} and {@link ThrustController#targetThrust} themselves as needed. + * Implementing this interface is required to resolve any conflicts between multiple thrust handlers. + * In case of multiple thrust handlers being present, only the first one registered + */ +public interface IThrustHandler extends IComputer { +} diff --git a/src/main/java/ru/octol1ttle/flightassistant/computers/api/ThrustControlInput.java b/src/main/java/ru/octol1ttle/flightassistant/computers/api/ThrustControlInput.java new file mode 100644 index 00000000..0dcb90b4 --- /dev/null +++ b/src/main/java/ru/octol1ttle/flightassistant/computers/api/ThrustControlInput.java @@ -0,0 +1,4 @@ +package ru.octol1ttle.flightassistant.computers.api; + +public record ThrustControlInput(float target, float deltaTimeMultiplier, InputPriority priority) { +} diff --git a/src/main/java/ru/octol1ttle/flightassistant/computers/impl/autoflight/AutoFlightComputer.java b/src/main/java/ru/octol1ttle/flightassistant/computers/impl/autoflight/AutoFlightComputer.java index f62e7cbf..a7f31939 100644 --- a/src/main/java/ru/octol1ttle/flightassistant/computers/impl/autoflight/AutoFlightComputer.java +++ b/src/main/java/ru/octol1ttle/flightassistant/computers/impl/autoflight/AutoFlightComputer.java @@ -19,10 +19,10 @@ public class AutoFlightComputer implements ITickableComputer, IAutopilotProvider private final FlightProtectionsComputer prot = ComputerRegistry.resolve(FlightProtectionsComputer.class); public boolean flightDirectorsEnabled = false; - public boolean autoFireworkEnabled = false; + public boolean autoThrustEnabled = false; public boolean autoPilotEnabled = false; - public boolean afrwkDisconnectionForced = false; + public boolean athrDisconnectionForced = false; public boolean apDisconnectionForced = false; public Integer selectedSpeed; @@ -31,7 +31,7 @@ public class AutoFlightComputer implements ITickableComputer, IAutopilotProvider @Override public void tick() { - if (autoFireworkEnabled && data.isCurrentChunkLoaded && gpws.fireworkUseSafe && gpws.getGPWSLampColor() == FAConfig.indicator().frameColor) { + if (autoThrustEnabled && data.isCurrentChunkLoaded && gpws.fireworkUseSafe && gpws.getGPWSLampColor() == FAConfig.indicator().frameColor) { Integer targetSpeed = getTargetSpeed(); Integer targetAltitude = getTargetAltitude(); if (targetSpeed != null) { @@ -73,9 +73,9 @@ public void disconnectAutopilot(boolean force) { } public void disconnectAutoFirework(boolean force) { - if (autoFireworkEnabled) { - autoFireworkEnabled = false; - afrwkDisconnectionForced = force; + if (autoThrustEnabled) { + autoThrustEnabled = false; + athrDisconnectionForced = force; } } diff --git a/src/main/java/ru/octol1ttle/flightassistant/computers/impl/autoflight/FireworkController.java b/src/main/java/ru/octol1ttle/flightassistant/computers/impl/autoflight/FireworkController.java index ddc6905f..e372b406 100644 --- a/src/main/java/ru/octol1ttle/flightassistant/computers/impl/autoflight/FireworkController.java +++ b/src/main/java/ru/octol1ttle/flightassistant/computers/impl/autoflight/FireworkController.java @@ -7,16 +7,19 @@ import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtElement; import net.minecraft.util.Hand; -import ru.octol1ttle.flightassistant.computers.api.IAutopilotProvider; +import ru.octol1ttle.flightassistant.computers.api.IThrustHandler; import ru.octol1ttle.flightassistant.computers.api.ITickableComputer; import ru.octol1ttle.flightassistant.computers.impl.AirDataComputer; import ru.octol1ttle.flightassistant.computers.impl.TimeComputer; import ru.octol1ttle.flightassistant.registries.ComputerRegistry; -public class FireworkController implements ITickableComputer, IAutopilotProvider { +public class FireworkController implements ITickableComputer, IThrustHandler { + public static final float FIREWORK_SPEED = 33.62f; + private final MinecraftClient mc; private final AirDataComputer data = ComputerRegistry.resolve(AirDataComputer.class); private final TimeComputer time = ComputerRegistry.resolve(TimeComputer.class); + private final ThrustController thrust = ComputerRegistry.resolve(ThrustController.class); public int safeFireworkCount = Integer.MAX_VALUE; public boolean fireworkResponded = true; @@ -52,6 +55,10 @@ public void tick() { i++; } + + if (data.speed() / FIREWORK_SPEED < thrust.currentThrust) { + activateFirework(false); + } } private int countSafeFireworks() { @@ -68,7 +75,7 @@ private int countSafeFireworks() { return i; } - public void activateFirework(boolean force) { + private void activateFirework(boolean force) { if (!data.canAutomationsActivate() || lastUseTime > 0 && time.millis != null && time.millis - lastUseTime < 1000) { return; } diff --git a/src/main/java/ru/octol1ttle/flightassistant/computers/impl/autoflight/HeadingController.java b/src/main/java/ru/octol1ttle/flightassistant/computers/impl/autoflight/HeadingController.java index d9b090db..ebe2610b 100644 --- a/src/main/java/ru/octol1ttle/flightassistant/computers/impl/autoflight/HeadingController.java +++ b/src/main/java/ru/octol1ttle/flightassistant/computers/impl/autoflight/HeadingController.java @@ -12,7 +12,7 @@ import ru.octol1ttle.flightassistant.computers.impl.AirDataComputer; import ru.octol1ttle.flightassistant.computers.impl.TimeComputer; import ru.octol1ttle.flightassistant.registries.ComputerRegistry; -import ru.octol1ttle.flightassistant.registries.events.ComputerRegisteredCallback; +import ru.octol1ttle.flightassistant.registries.events.AllowComputerRegisterCallback; public class HeadingController implements ITickableComputer, IAutopilotProvider { private final AirDataComputer data = ComputerRegistry.resolve(AirDataComputer.class); @@ -20,10 +20,11 @@ public class HeadingController implements ITickableComputer, IAutopilotProvider private final List controllers = new ArrayList<>(); public HeadingController() { - ComputerRegisteredCallback.EVENT.register((computer -> { + AllowComputerRegisterCallback.EVENT.register((computer -> { if (computer instanceof IHeadingController controller) { controllers.add(controller); } + return true; })); } diff --git a/src/main/java/ru/octol1ttle/flightassistant/computers/impl/autoflight/PitchController.java b/src/main/java/ru/octol1ttle/flightassistant/computers/impl/autoflight/PitchController.java index 3dda3887..a644dfaa 100644 --- a/src/main/java/ru/octol1ttle/flightassistant/computers/impl/autoflight/PitchController.java +++ b/src/main/java/ru/octol1ttle/flightassistant/computers/impl/autoflight/PitchController.java @@ -13,7 +13,7 @@ import ru.octol1ttle.flightassistant.computers.impl.TimeComputer; import ru.octol1ttle.flightassistant.computers.impl.safety.PitchLimitComputer; import ru.octol1ttle.flightassistant.registries.ComputerRegistry; -import ru.octol1ttle.flightassistant.registries.events.ComputerRegisteredCallback; +import ru.octol1ttle.flightassistant.registries.events.AllowComputerRegisterCallback; public class PitchController implements ITickableComputer, INormalLawProvider { public static final float CLIMB_PITCH = 55.0f; @@ -26,10 +26,11 @@ public class PitchController implements ITickableComputer, INormalLawProvider { private final PitchLimitComputer limit = ComputerRegistry.resolve(PitchLimitComputer.class); public PitchController() { - ComputerRegisteredCallback.EVENT.register((computer -> { + AllowComputerRegisterCallback.EVENT.register((computer -> { if (computer instanceof IPitchController controller) { controllers.add(controller); } + return true; })); } diff --git a/src/main/java/ru/octol1ttle/flightassistant/computers/impl/autoflight/RollController.java b/src/main/java/ru/octol1ttle/flightassistant/computers/impl/autoflight/RollController.java index 4e8ee5b3..3d8628eb 100644 --- a/src/main/java/ru/octol1ttle/flightassistant/computers/impl/autoflight/RollController.java +++ b/src/main/java/ru/octol1ttle/flightassistant/computers/impl/autoflight/RollController.java @@ -17,7 +17,7 @@ import ru.octol1ttle.flightassistant.computers.impl.AirDataComputer; import ru.octol1ttle.flightassistant.computers.impl.TimeComputer; import ru.octol1ttle.flightassistant.registries.ComputerRegistry; -import ru.octol1ttle.flightassistant.registries.events.ComputerRegisteredCallback; +import ru.octol1ttle.flightassistant.registries.events.AllowComputerRegisterCallback; import ru.octol1ttle.flightassistant.registries.events.CustomComputerRegistrationCallback; public class RollController implements ITickableComputer, INormalLawProvider { @@ -32,18 +32,20 @@ public RollController() { ComputerRegistry.register(new DaBRRollHandler()); } }); - ComputerRegisteredCallback.EVENT.register(computer -> { + AllowComputerRegisterCallback.EVENT.register(computer -> { if (computer instanceof IRollController controller) { controllers.add(controller); } if (computer instanceof IRollHandler handler) { if (rollHandler != null) { - FlightAssistant.LOGGER.warn("Multiple roll handlers found! Discarding handler %s".formatted(handler.getClass().getName())); + FlightAssistant.LOGGER.error("Multiple roll handlers found! Discarding handler %s".formatted(handler.getClass().getName())); + return false; } else { rollHandler = handler; FlightAssistant.LOGGER.info("Active roll handler is %s".formatted(rollHandler.getClass().getName())); } } + return true; }); } @@ -111,4 +113,4 @@ public String getId() { @Override public void reset() { } -} \ No newline at end of file +} diff --git a/src/main/java/ru/octol1ttle/flightassistant/computers/impl/autoflight/ThrustController.java b/src/main/java/ru/octol1ttle/flightassistant/computers/impl/autoflight/ThrustController.java new file mode 100644 index 00000000..9ab60ff3 --- /dev/null +++ b/src/main/java/ru/octol1ttle/flightassistant/computers/impl/autoflight/ThrustController.java @@ -0,0 +1,99 @@ +package ru.octol1ttle.flightassistant.computers.impl.autoflight; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import net.fabricmc.loader.api.FabricLoader; +import ru.octol1ttle.flightassistant.FlightAssistant; +import ru.octol1ttle.flightassistant.compatibility.doabarrelroll.DaBRThrustHandler; +import ru.octol1ttle.flightassistant.computers.api.INormalLawProvider; +import ru.octol1ttle.flightassistant.computers.api.IThrustController; +import ru.octol1ttle.flightassistant.computers.api.IThrustHandler; +import ru.octol1ttle.flightassistant.computers.api.ITickableComputer; +import ru.octol1ttle.flightassistant.computers.api.InputPriority; +import ru.octol1ttle.flightassistant.computers.api.ThrustControlInput; +import ru.octol1ttle.flightassistant.computers.impl.TimeComputer; +import ru.octol1ttle.flightassistant.config.FAConfig; +import ru.octol1ttle.flightassistant.registries.ComputerRegistry; +import ru.octol1ttle.flightassistant.registries.events.AllowComputerRegisterCallback; +import ru.octol1ttle.flightassistant.registries.events.CustomComputerRegistrationCallback; + +public class ThrustController implements ITickableComputer, INormalLawProvider { + private static final float MIN_TO_MAX_SPOOL_UP_TIME = 5.0f; + private final TimeComputer time = ComputerRegistry.resolve(TimeComputer.class); + private final List controllers = new ArrayList<>(); + public float currentThrust = 0.0f; + public float targetThrust = 0.0f; + private boolean thrustHandlerRegistered = false; + + public ThrustController() { + CustomComputerRegistrationCallback.EVENT.register(() -> { + if (FabricLoader.getInstance().isModLoaded("do_a_barrel_roll")) { + ComputerRegistry.register(new DaBRThrustHandler()); + } + }); + AllowComputerRegisterCallback.EVENT.register(computer -> { + if (computer instanceof IThrustController controller) { + controllers.add(controller); + } + if (computer instanceof IThrustHandler handler) { + if (thrustHandlerRegistered) { + FlightAssistant.LOGGER.error("Multiple thrust handlers found! Discarding handler %s".formatted(handler.getClass().getName())); + return false; + } + if (!(handler instanceof FireworkController)) { + thrustHandlerRegistered = true; + FlightAssistant.LOGGER.info("Active thrust handler is %s".formatted(handler.getClass().getName())); + } + } + return true; + }); + } + + @Override + public void tick() { + updateTargetThrust(); + + float diff = targetThrust - currentThrust; + if (!FAConfig.computer().simulateEngineSpoolUp || Math.abs(diff) < 0.001f) { + currentThrust = targetThrust; + } else { + currentThrust = currentThrust + diff * time.deltaTime / MIN_TO_MAX_SPOOL_UP_TIME * Math.max(currentThrust, 0.1f); + } + } + + private void updateTargetThrust() { + List inputs = new ArrayList<>(); + for (IThrustController controller : controllers) { + if (ComputerRegistry.isFaulted(controller.getClass())) { + continue; + } + ThrustControlInput input = controller.getThrustInput(); + if (input != null) { + inputs.add(input); + } + } + inputs.sort(Comparator.comparingInt(input -> input.priority().numerical)); + + InputPriority lastPriority = null; + for (ThrustControlInput input : inputs) { + if (lastPriority != null && input.priority() != lastPriority) { + break; + } + + targetThrust = Math.max(targetThrust, input.target()); + lastPriority = input.priority(); + } + } + + @Override + public String getId() { + return "thrust_ctl"; + } + + @Override + public void reset() { + currentThrust = 0.0f; + targetThrust = 0.0f; + } +} diff --git a/src/main/java/ru/octol1ttle/flightassistant/computers/impl/safety/GroundProximityComputer.java b/src/main/java/ru/octol1ttle/flightassistant/computers/impl/safety/GroundProximityComputer.java index 0227efe4..5ca6e10e 100644 --- a/src/main/java/ru/octol1ttle/flightassistant/computers/impl/safety/GroundProximityComputer.java +++ b/src/main/java/ru/octol1ttle/flightassistant/computers/impl/safety/GroundProximityComputer.java @@ -14,6 +14,7 @@ import ru.octol1ttle.flightassistant.computers.api.ITickableComputer; import ru.octol1ttle.flightassistant.computers.api.InputPriority; import ru.octol1ttle.flightassistant.computers.impl.AirDataComputer; +import ru.octol1ttle.flightassistant.computers.impl.autoflight.FireworkController; import ru.octol1ttle.flightassistant.computers.impl.navigation.FlightPlanner; import ru.octol1ttle.flightassistant.config.FAConfig; import ru.octol1ttle.flightassistant.registries.ComputerRegistry; @@ -24,7 +25,6 @@ public class GroundProximityComputer implements ITickableComputer, IPitchLimiter private static final int STATUS_SPEED_SAFE = -3; private static final int STATUS_NO_TERRAIN_AHEAD = -4; private static final int STATUS_UNKNOWN = -5; - private static final float FIREWORK_SPEED = 33.62f; private static final float TERRAIN_RAYCAST_AHEAD_SECONDS = 10.0f; private static final float MAX_SAFE_GROUND_SPEED = 17.5f; private static final float MAX_SAFE_SINK_RATE = 10.0f; @@ -112,7 +112,7 @@ private boolean computeFireworkUseSafe() { if (data.isInvulnerableTo(data.player().getDamageSources().flyIntoWall())) { return true; } - Vec3d end = data.position().add(Vec3d.fromPolar(data.pitch(), data.yaw()).multiply(FIREWORK_SPEED * TERRAIN_RAYCAST_AHEAD_SECONDS)); + Vec3d end = data.position().add(Vec3d.fromPolar(data.pitch(), data.yaw()).multiply(FireworkController.FIREWORK_SPEED * TERRAIN_RAYCAST_AHEAD_SECONDS)); BlockHitResult result = data.world().raycast(new RaycastContext(data.position(), end, RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.ANY, data.player())); if (result.getType() != HitResult.Type.BLOCK || result.getSide() == Direction.UP) { @@ -121,7 +121,7 @@ private boolean computeFireworkUseSafe() { double distance = result.getPos().subtract(data.position()).length(); - return distance / FIREWORK_SPEED > PULL_UP_THRESHOLD; + return distance / FireworkController.FIREWORK_SPEED > PULL_UP_THRESHOLD; } private LandingClearanceStatus computeLandingClearanceStatus() { diff --git a/src/main/java/ru/octol1ttle/flightassistant/computers/impl/safety/PitchLimitComputer.java b/src/main/java/ru/octol1ttle/flightassistant/computers/impl/safety/PitchLimitComputer.java index 8415fed8..9c1ec8ae 100644 --- a/src/main/java/ru/octol1ttle/flightassistant/computers/impl/safety/PitchLimitComputer.java +++ b/src/main/java/ru/octol1ttle/flightassistant/computers/impl/safety/PitchLimitComputer.java @@ -10,7 +10,7 @@ import ru.octol1ttle.flightassistant.computers.api.ITickableComputer; import ru.octol1ttle.flightassistant.config.ComputerConfig; import ru.octol1ttle.flightassistant.registries.ComputerRegistry; -import ru.octol1ttle.flightassistant.registries.events.ComputerRegisteredCallback; +import ru.octol1ttle.flightassistant.registries.events.AllowComputerRegisterCallback; public class PitchLimitComputer implements ITickableComputer, INormalLawProvider { private final List limiters = new ArrayList<>(); @@ -18,10 +18,11 @@ public class PitchLimitComputer implements ITickableComputer, INormalLawProvider public float maximumSafePitch = 90.0f; public PitchLimitComputer() { - ComputerRegisteredCallback.EVENT.register((computer -> { + AllowComputerRegisterCallback.EVENT.register((computer -> { if (computer instanceof IPitchLimiter limiter) { limiters.add(limiter); } + return true; })); } diff --git a/src/main/java/ru/octol1ttle/flightassistant/config/ComputerConfig.java b/src/main/java/ru/octol1ttle/flightassistant/config/ComputerConfig.java index 7ecb2012..c69bb7b9 100644 --- a/src/main/java/ru/octol1ttle/flightassistant/config/ComputerConfig.java +++ b/src/main/java/ru/octol1ttle/flightassistant/config/ComputerConfig.java @@ -45,6 +45,9 @@ public class ComputerConfig { @SerialEntry public boolean preserveAltitudeInUnloadedChunk = true; + @SerialEntry + public boolean simulateEngineSpoolUp = true; + public enum GlobalAutomationsMode implements NameableEnum { FULL, // TODO: LIMIT TO NO_OVERLAYS ON SERVERS diff --git a/src/main/java/ru/octol1ttle/flightassistant/hud/HudDisplayHost.java b/src/main/java/ru/octol1ttle/flightassistant/hud/HudDisplayHost.java index 91413508..4b505061 100644 --- a/src/main/java/ru/octol1ttle/flightassistant/hud/HudDisplayHost.java +++ b/src/main/java/ru/octol1ttle/flightassistant/hud/HudDisplayHost.java @@ -28,24 +28,26 @@ import ru.octol1ttle.flightassistant.registries.HudDisplayRegistry; import ru.octol1ttle.flightassistant.registries.events.CustomHudDisplayRegistrationCallback; +import static ru.octol1ttle.flightassistant.FlightAssistant.id; + public class HudDisplayHost { private final Dimensions dim = new Dimensions(); public HudDisplayHost() { - HudDisplayRegistry.register(FlightAssistant.id("alert"), new AlertDisplay(dim)); - HudDisplayRegistry.register(FlightAssistant.id("altitude"), new AltitudeDisplay(dim)); - HudDisplayRegistry.register(FlightAssistant.id("attitude"), new AttitudeDisplay(dim)); - HudDisplayRegistry.register(FlightAssistant.id("elytra_health"), new ElytraHealthDisplay(dim)); - HudDisplayRegistry.register(FlightAssistant.id("flight_directors"), new FlightDirectorsDisplay(dim)); - HudDisplayRegistry.register(FlightAssistant.id("flight_mode"), new FlightModeDisplay(dim)); - HudDisplayRegistry.register(FlightAssistant.id("flight_path"), new FlightPathDisplay(dim)); - HudDisplayRegistry.register(FlightAssistant.id("ground_speed"), new GroundSpeedDisplay(dim)); - HudDisplayRegistry.register(FlightAssistant.id("heading"), new HeadingDisplay(dim)); - HudDisplayRegistry.register(FlightAssistant.id("radar_altitude"), new RadarAltitudeDisplay(dim)); - HudDisplayRegistry.register(FlightAssistant.id("location"), new LocationDisplay(dim)); - HudDisplayRegistry.register(FlightAssistant.id("speed"), new SpeedDisplay(dim)); - HudDisplayRegistry.register(FlightAssistant.id("status"), new StatusDisplay(dim)); - HudDisplayRegistry.register(FlightAssistant.id("vertical_speed"), new VerticalSpeedDisplay(dim)); + HudDisplayRegistry.register(id("alert"), new AlertDisplay(dim)); + HudDisplayRegistry.register(id("altitude"), new AltitudeDisplay(dim)); + HudDisplayRegistry.register(id("attitude"), new AttitudeDisplay(dim)); + HudDisplayRegistry.register(id("elytra_health"), new ElytraHealthDisplay(dim)); + HudDisplayRegistry.register(id("flight_directors"), new FlightDirectorsDisplay(dim)); + HudDisplayRegistry.register(id("flight_mode"), new FlightModeDisplay(dim)); + HudDisplayRegistry.register(id("flight_path"), new FlightPathDisplay(dim)); + HudDisplayRegistry.register(id("ground_speed"), new GroundSpeedDisplay(dim)); + HudDisplayRegistry.register(id("heading"), new HeadingDisplay(dim)); + HudDisplayRegistry.register(id("radar_altitude"), new RadarAltitudeDisplay(dim)); + HudDisplayRegistry.register(id("location"), new LocationDisplay(dim)); + HudDisplayRegistry.register(id("speed"), new SpeedDisplay(dim)); + HudDisplayRegistry.register(id("status"), new StatusDisplay(dim)); + HudDisplayRegistry.register(id("vertical_speed"), new VerticalSpeedDisplay(dim)); CustomHudDisplayRegistrationCallback.EVENT.invoker().registerCustomDisplays(); } diff --git a/src/main/java/ru/octol1ttle/flightassistant/hud/impl/FlightModeDisplay.java b/src/main/java/ru/octol1ttle/flightassistant/hud/impl/FlightModeDisplay.java index 3cf171a5..9156944e 100644 --- a/src/main/java/ru/octol1ttle/flightassistant/hud/impl/FlightModeDisplay.java +++ b/src/main/java/ru/octol1ttle/flightassistant/hud/impl/FlightModeDisplay.java @@ -66,12 +66,12 @@ private void renderFireworkMode(DrawContext context, TextRenderer textRenderer) Text minimums = plan.formatMinimums(); if (firework.noFireworks) { - fireworkMode.update(Text.translatable("mode.flightassistant.firework.none_in_hotbar"), autoflight.autoFireworkEnabled); + fireworkMode.update(Text.translatable("mode.flightassistant.firework.none_in_hotbar"), autoflight.autoThrustEnabled); } else if (firework.lastProtTrigger != null && time.millis - firework.lastProtTrigger < 2000) { fireworkMode.update(Text.translatable("mode.flightassistant.firework.protection"), true); } else if (minimums != null && plan.isOnApproach()) { fireworkMode.update(minimums, plan.isBelowMinimums()); - } else if (autoflight.autoFireworkEnabled) { + } else if (autoflight.autoThrustEnabled) { if (targetSpeed != null) { String type = autoflight.selectedSpeed != null ? ".selected" : ".managed"; fireworkMode.update(Text.translatable("mode.flightassistant.firework.speed" + type, targetSpeed)); @@ -150,7 +150,7 @@ private void renderAutomationStatus(DrawContext context, TextRenderer textRender if (autoflight.flightDirectorsEnabled) { appendWithSeparation(automationStatus, Text.translatable("mode.flightassistant.auto.flight_directors")); } - if (autoflight.autoFireworkEnabled) { + if (autoflight.autoThrustEnabled) { appendWithSeparation(automationStatus, Text.translatable("mode.flightassistant.auto.auto_firework")); } if (autoflight.autoPilotEnabled) { @@ -183,4 +183,4 @@ public void renderFaulted(DrawContext context, TextRenderer textRenderer) { public String getId() { return "flight_mode"; } -} \ No newline at end of file +} diff --git a/src/main/java/ru/octol1ttle/flightassistant/registries/ComputerRegistry.java b/src/main/java/ru/octol1ttle/flightassistant/registries/ComputerRegistry.java index c02cda8c..73f57c69 100644 --- a/src/main/java/ru/octol1ttle/flightassistant/registries/ComputerRegistry.java +++ b/src/main/java/ru/octol1ttle/flightassistant/registries/ComputerRegistry.java @@ -10,7 +10,7 @@ import org.jetbrains.annotations.Nullable; import ru.octol1ttle.flightassistant.FlightAssistant; import ru.octol1ttle.flightassistant.computers.api.IComputer; -import ru.octol1ttle.flightassistant.registries.events.ComputerRegisteredCallback; +import ru.octol1ttle.flightassistant.registries.events.AllowComputerRegisterCallback; @SuppressWarnings("unchecked") public abstract class ComputerRegistry { @@ -24,7 +24,7 @@ public static void register(IComputer computer) { } instances.put(clazz, computer); - ComputerRegisteredCallback.EVENT.invoker().onComputerRegistered(computer); + AllowComputerRegisterCallback.EVENT.invoker().allowRegister(computer); } public static T resolve(Class clazz) { diff --git a/src/main/java/ru/octol1ttle/flightassistant/registries/events/AllowComputerRegisterCallback.java b/src/main/java/ru/octol1ttle/flightassistant/registries/events/AllowComputerRegisterCallback.java new file mode 100644 index 00000000..7e3891b5 --- /dev/null +++ b/src/main/java/ru/octol1ttle/flightassistant/registries/events/AllowComputerRegisterCallback.java @@ -0,0 +1,28 @@ +package ru.octol1ttle.flightassistant.registries.events; + +import net.fabricmc.fabric.api.event.Event; +import net.fabricmc.fabric.api.event.EventFactory; +import ru.octol1ttle.flightassistant.computers.api.IComputer; + +@FunctionalInterface +public interface AllowComputerRegisterCallback { + Event EVENT = EventFactory.createArrayBacked( + AllowComputerRegisterCallback.class, + (listeners) -> (computer) -> { + for (AllowComputerRegisterCallback event : listeners) { + if (!event.allowRegister(computer)) { + return false; + } + } + return true; + } + ); + + /** + * Called when a computer is about to be registered. + * + * @param computer the {@link IComputer} instance + * @return whether the computer should be registered + */ + boolean allowRegister(IComputer computer); +} diff --git a/src/main/java/ru/octol1ttle/flightassistant/registries/events/ComputerRegisteredCallback.java b/src/main/java/ru/octol1ttle/flightassistant/registries/events/ComputerRegisteredCallback.java deleted file mode 100644 index e1ed8311..00000000 --- a/src/main/java/ru/octol1ttle/flightassistant/registries/events/ComputerRegisteredCallback.java +++ /dev/null @@ -1,23 +0,0 @@ -package ru.octol1ttle.flightassistant.registries.events; - -import net.fabricmc.fabric.api.event.Event; -import net.fabricmc.fabric.api.event.EventFactory; -import ru.octol1ttle.flightassistant.computers.api.IComputer; - -public interface ComputerRegisteredCallback { - Event EVENT = EventFactory.createArrayBacked( - ComputerRegisteredCallback.class, - (listeners) -> (computer) -> { - for (ComputerRegisteredCallback event : listeners) { - event.onComputerRegistered(computer); - } - } - ); - - /** - * Called after a computer has been registered. - * - * @param computer the {@link IComputer} instance - */ - void onComputerRegistered(IComputer computer); -} diff --git a/src/main/java/ru/octol1ttle/flightassistant/registries/events/CustomAlertRegistrationCallback.java b/src/main/java/ru/octol1ttle/flightassistant/registries/events/CustomAlertRegistrationCallback.java index 139eef70..63897f13 100644 --- a/src/main/java/ru/octol1ttle/flightassistant/registries/events/CustomAlertRegistrationCallback.java +++ b/src/main/java/ru/octol1ttle/flightassistant/registries/events/CustomAlertRegistrationCallback.java @@ -3,6 +3,7 @@ import net.fabricmc.fabric.api.event.Event; import net.fabricmc.fabric.api.event.EventFactory; +@FunctionalInterface public interface CustomAlertRegistrationCallback { Event EVENT = EventFactory.createArrayBacked( CustomAlertRegistrationCallback.class, diff --git a/src/main/java/ru/octol1ttle/flightassistant/registries/events/CustomComputerRegistrationCallback.java b/src/main/java/ru/octol1ttle/flightassistant/registries/events/CustomComputerRegistrationCallback.java index 3a053422..21b3684e 100644 --- a/src/main/java/ru/octol1ttle/flightassistant/registries/events/CustomComputerRegistrationCallback.java +++ b/src/main/java/ru/octol1ttle/flightassistant/registries/events/CustomComputerRegistrationCallback.java @@ -3,6 +3,7 @@ import net.fabricmc.fabric.api.event.Event; import net.fabricmc.fabric.api.event.EventFactory; +@FunctionalInterface public interface CustomComputerRegistrationCallback { Event EVENT = EventFactory.createArrayBacked( CustomComputerRegistrationCallback.class, diff --git a/src/main/java/ru/octol1ttle/flightassistant/registries/events/CustomHudDisplayRegistrationCallback.java b/src/main/java/ru/octol1ttle/flightassistant/registries/events/CustomHudDisplayRegistrationCallback.java index e615a5ed..2a03ea8a 100644 --- a/src/main/java/ru/octol1ttle/flightassistant/registries/events/CustomHudDisplayRegistrationCallback.java +++ b/src/main/java/ru/octol1ttle/flightassistant/registries/events/CustomHudDisplayRegistrationCallback.java @@ -3,6 +3,7 @@ import net.fabricmc.fabric.api.event.Event; import net.fabricmc.fabric.api.event.EventFactory; +@FunctionalInterface public interface CustomHudDisplayRegistrationCallback { Event EVENT = EventFactory.createArrayBacked( CustomHudDisplayRegistrationCallback.class, diff --git a/src/main/resources/assets/flightassistant/lang/en_us.yml b/src/main/resources/assets/flightassistant/lang/en_us.yml index b75077f9..15d59ce2 100644 --- a/src/main/resources/assets/flightassistant/lang/en_us.yml +++ b/src/main/resources/assets/flightassistant/lang/en_us.yml @@ -15,7 +15,7 @@ config.flightassistant: not_flying_no_elytra: Not flying (no Elytra) not_flying_has_elytra: Not flying (with Elytra) flying: Flying - computer_settings: Flight protections + computer_settings: Flight automations hud: batching: .: Batched HUD rendering @@ -181,6 +181,7 @@ alerts.flightassistant: flight_phase: F/PHASE SYS FAULT roll_ctl: AUTO ROLL CTL FAULT dabr_roll: DABR ROLL CTL FAULT + thrust_ctl: AUTO THR CTL FAULT hud: alert: ALERT DISPLAY FAULT altitude: ALT DISPLAY FAULT diff --git a/src/main/resources/assets/flightassistant/lang/ru_ru.yml b/src/main/resources/assets/flightassistant/lang/ru_ru.yml index 19d6498a..7974d524 100644 --- a/src/main/resources/assets/flightassistant/lang/ru_ru.yml +++ b/src/main/resources/assets/flightassistant/lang/ru_ru.yml @@ -181,6 +181,7 @@ alerts.flightassistant: flight_phase: ОТКАЗ СИСТ ФАЗЫ ПОЛЕТА roll_ctl: ОТКАЗ АВТО УПР КРЕНОМ dabr_roll: ОТКАЗ УПР КРЕНОМ DABR + thrust_ctl: ОТКАЗ АВТО УПР ТЯГИ hud: alert: ОТКАЗ ИНДИК ПРЕДУПР altitude: ОТКАЗ ИНДИК ВЫС