Skip to content

Commit

Permalink
i wanted to add TOGA LK but ended up implementing 31 features...
Browse files Browse the repository at this point in the history
Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
  • Loading branch information
Octol1ttle committed Oct 27, 2023
1 parent 5a3bb97 commit 348a2fc
Show file tree
Hide file tree
Showing 27 changed files with 377 additions and 72 deletions.
13 changes: 10 additions & 3 deletions src/main/java/ru/octol1ttle/flightassistant/FlightAssistant.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ru.octol1ttle.flightassistant;

import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.tree.LiteralCommandNode;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
Expand All @@ -12,12 +13,14 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.octol1ttle.flightassistant.alerts.ECAMSoundData;
import ru.octol1ttle.flightassistant.commands.SetAutoThrustSpeedCommand;
import ru.octol1ttle.flightassistant.commands.SwitchDisplayModeCommand;
import ru.octol1ttle.flightassistant.computers.FlightComputer;
import ru.octol1ttle.flightassistant.config.HudConfig;
import ru.octol1ttle.flightassistant.config.SettingsConfig;
import ru.octol1ttle.flightassistant.config.loader.ConfigLoader;

import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument;
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal;

public class FlightAssistant implements ClientModInitializer {
Expand Down Expand Up @@ -76,15 +79,15 @@ private static void setupKeycCode() {
FlightComputer computer = HudRenderer.getComputer();
if (computer != null) {
while (toggleAutoThrust.wasPressed()) {
computer.autoflight.toggleAutoThrust();
computer.autoflight.autoThrustEnabled = !computer.autoflight.autoThrustEnabled;
}

while (dismissMasterWarning.wasPressed()) {
computer.alertController.dismiss(ECAMSoundData.MASTER_WARNING);
computer.alert.dismiss(ECAMSoundData.MASTER_WARNING);
}

while (dismissMasterCaution.wasPressed()) {
computer.alertController.dismiss(ECAMSoundData.MASTER_CAUTION);
computer.alert.dismiss(ECAMSoundData.MASTER_CAUTION);
}
}
});
Expand All @@ -95,7 +98,11 @@ private static void setupCommand() {

LiteralCommandNode<FabricClientCommandSource> node = dispatcher.register(literal("flightassistant")
.then(literal("toggle").executes(new SwitchDisplayModeCommand()))
.then(literal("speed")
.then(argument("targetSpeed", IntegerArgumentType.integer(10, 30))
.executes(new SetAutoThrustSpeedCommand())))
);
dispatcher.register(literal("flas").redirect(node));
dispatcher.register(literal("fhud").redirect(node));
dispatcher.register(literal("fh").redirect(node));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static int drawFont(TextRenderer textRenderer, DrawContext context, Strin
return 1;
}

public static int drawHighlightedFont(TextRenderer textRenderer, DrawContext context, float x, float y, Text text, int highlightColor, boolean highlight) {
public static int drawHighlightedFont(TextRenderer textRenderer, DrawContext context, Text text, float x, float y, int highlightColor, boolean highlight) {
if (highlight) {
drawUnbatched(context, ctx -> {
HudComponent.fill(context, x - 1.5f, y - 1.5f, x + textRenderer.getWidth(text), y + 8.0f, highlightColor);
Expand Down
54 changes: 33 additions & 21 deletions src/main/java/ru/octol1ttle/flightassistant/HudRenderer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ru.octol1ttle.flightassistant;

import java.util.ArrayList;
import java.util.List;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
Expand All @@ -11,6 +13,7 @@
import ru.octol1ttle.flightassistant.indicators.AlertIndicator;
import ru.octol1ttle.flightassistant.indicators.AltitudeIndicator;
import ru.octol1ttle.flightassistant.indicators.ElytraHealthIndicator;
import ru.octol1ttle.flightassistant.indicators.FlightModeIndicator;
import ru.octol1ttle.flightassistant.indicators.FlightPathIndicator;
import ru.octol1ttle.flightassistant.indicators.HeadingIndicator;
import ru.octol1ttle.flightassistant.indicators.LocationIndicator;
Expand All @@ -24,16 +27,18 @@ public class HudRenderer extends HudComponent {
@NotNull
public final FlightComputer computer;
private final Dimensions dim = new Dimensions();
private final HudComponent[] components;
private final List<HudComponent> components;
private final List<HudComponent> toDelete;

public HudRenderer(MinecraftClient mc) {
this.computer = new FlightComputer(mc);
this.components = new HudComponent[]{
this.components = new ArrayList<>(List.of(
new FlightPathIndicator(computer, dim), new LocationIndicator(computer, dim),
new HeadingIndicator(computer, dim), new SpeedIndicator(computer, dim),
new AltitudeIndicator(computer, dim), new PitchIndicator(computer, dim),
new ElytraHealthIndicator(computer, dim), new AlertIndicator(computer, dim)
};
new ElytraHealthIndicator(computer, dim), new AlertIndicator(computer, dim),
new FlightModeIndicator(computer, dim)));
this.toDelete = new ArrayList<>();
}

public static FlightComputer getComputer() {
Expand Down Expand Up @@ -67,30 +72,37 @@ public void render(DrawContext context, MinecraftClient mc) {
return;
}

try {
context.getMatrices().push();
context.getMatrices().push();

if (HudComponent.CONFIG.scale != 1d) {
float scale = 1 / HudComponent.CONFIG.scale;
context.getMatrices().scale(scale, scale, scale);
}
if (HudComponent.CONFIG.scale != 1d) {
float scale = 1 / HudComponent.CONFIG.scale;
context.getMatrices().scale(scale, scale, scale);
}

dim.update(mc);
dim.update(mc);

for (HudComponent component : components) {
if (FabricLoader.getInstance().isModLoaded("immediatelyfast")) {
ImmediatelyFastBatchingAccessor.beginHudBatching();
}
for (HudComponent component : components) {
if (FabricLoader.getInstance().isModLoaded("immediatelyfast")) {
ImmediatelyFastBatchingAccessor.beginHudBatching();
}
try {
component.render(context, mc.textRenderer);
if (FabricLoader.getInstance().isModLoaded("immediatelyfast")) {
ImmediatelyFastBatchingAccessor.endHudBatching();
} catch (Exception e) {
FlightAssistant.LOGGER.error("Exception rendering component", e);
toDelete.add(component);
if (getComputer() != null) {
getComputer().internalError = true;
}
}
context.getMatrices().pop();
} catch (Exception e) {
// TODO: alert? lmao
FlightAssistant.LOGGER.error("Exception rendering components", e);
if (FabricLoader.getInstance().isModLoaded("immediatelyfast")) {
ImmediatelyFastBatchingAccessor.endHudBatching();
}
}

components.removeAll(toDelete);
toDelete.clear();

context.getMatrices().pop();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package ru.octol1ttle.flightassistant.alerts;

import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.Text;
import org.jetbrains.annotations.NotNull;
import ru.octol1ttle.flightassistant.HudComponent;
import ru.octol1ttle.flightassistant.computers.FlightComputer;

public class InternalErrorAlert extends AbstractAlert {
private final FlightComputer computer;

public InternalErrorAlert(FlightComputer computer) {
this.computer = computer;
}

@Override
public boolean isTriggered() {
return computer.internalError;
}

@Override
public @NotNull AlertSoundData getAlertSoundData() {
return ECAMSoundData.MASTER_WARNING;
}

@Override
public int renderECAM(TextRenderer textRenderer, DrawContext context, float x, float y, boolean highlight) {
return HudComponent.drawHighlightedFont(textRenderer, context, Text.translatable("alerts.flightassistant.internal_mod_error"), x, y,
HudComponent.CONFIG.alertColor,
!dismissed && highlight);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public boolean isTriggered() {
public boolean renderCentered(TextRenderer textRenderer, DrawContext context, float width, float y, boolean highlight) {
Text text = Text.translatable("alerts.flightassistant.stall");
float startX = (width - textRenderer.getWidth(text)) * 0.5f;
HudComponent.drawHighlightedFont(textRenderer, context, startX, y, text,
HudComponent.drawHighlightedFont(textRenderer, context, text, startX, y,
-computer.velocityPerSecond.y >= GPWSComputer.MAX_SAFE_SINK_RATE ?
CONFIG.alertColor :
CONFIG.amberColor, highlight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@

import static ru.octol1ttle.flightassistant.HudComponent.CONFIG;

public class ATHRSpeedNotSetAlert extends AbstractAlert {
public class ATHRNoFireworksInHotbarAlert extends AbstractAlert {

private final FlightComputer computer;

public ATHRSpeedNotSetAlert(FlightComputer computer) {
public ATHRNoFireworksInHotbarAlert(FlightComputer computer) {
this.computer = computer;
}

@Override
public boolean isTriggered() {
return computer.autoflight.autoThrustEnabled && computer.autoflight.targetSpeed == null;
return computer.firework.noFireworks;
}

@Override
Expand All @@ -32,9 +32,8 @@ public boolean isTriggered() {

@Override
public int renderECAM(TextRenderer textRenderer, DrawContext context, float x, float y, boolean highlight) {
return HudComponent.drawHighlightedFont(textRenderer, context, x, y,
Text.translatable("alerts.flightassistant.autoflight.athr_speed_not_set"),
return HudComponent.drawHighlightedFont(textRenderer, context, Text.translatable("alerts.flightassistant.firework.no_fireworks"), x, y,
CONFIG.amberColor,
!dismissed);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package ru.octol1ttle.flightassistant.alerts.firework;

import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.Text;
import org.jetbrains.annotations.NotNull;
import ru.octol1ttle.flightassistant.HudComponent;
import ru.octol1ttle.flightassistant.alerts.AbstractAlert;
import ru.octol1ttle.flightassistant.alerts.AlertSoundData;
import ru.octol1ttle.flightassistant.alerts.ECAMSoundData;
import ru.octol1ttle.flightassistant.computers.FlightComputer;

import static ru.octol1ttle.flightassistant.HudComponent.CONFIG;

public class FireworkDelayedResponseAlert extends AbstractAlert {

private final FlightComputer computer;

public FireworkDelayedResponseAlert(FlightComputer computer) {
this.computer = computer;
}

@Override
public boolean isTriggered() {
return !computer.firework.fireworkResponded
&& computer.firework.lastDiff > 750 && computer.firework.lastDiff < 1500;
}

@Override
public @NotNull AlertSoundData getAlertSoundData() {
return ECAMSoundData.MASTER_CAUTION;
}

@Override
public int renderECAM(TextRenderer textRenderer, DrawContext context, float x, float y, boolean highlight) {
return HudComponent.drawHighlightedFont(textRenderer, context, Text.translatable("alerts.flightassistant.firework.delayed_response"), x, y,
CONFIG.amberColor,
!dismissed);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package ru.octol1ttle.flightassistant.alerts.firework;

import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.Text;
import org.jetbrains.annotations.NotNull;
import ru.octol1ttle.flightassistant.HudComponent;
import ru.octol1ttle.flightassistant.alerts.AbstractAlert;
import ru.octol1ttle.flightassistant.alerts.AlertSoundData;
import ru.octol1ttle.flightassistant.alerts.ECAMSoundData;
import ru.octol1ttle.flightassistant.computers.FlightComputer;

import static ru.octol1ttle.flightassistant.HudComponent.CONFIG;

public class FireworkNoResponseAlert extends AbstractAlert {

private final FlightComputer computer;

public FireworkNoResponseAlert(FlightComputer computer) {
this.computer = computer;
}

@Override
public boolean isTriggered() {
return !computer.firework.fireworkResponded && computer.firework.lastDiff > 1500;
}

@Override
public @NotNull AlertSoundData getAlertSoundData() {
return ECAMSoundData.MASTER_WARNING;
}

@Override
public int renderECAM(TextRenderer textRenderer, DrawContext context, float x, float y, boolean highlight) {
return HudComponent.drawHighlightedFont(textRenderer, context, Text.translatable("alerts.flightassistant.firework.no_response"), x, y,
CONFIG.alertColor,
!dismissed && highlight);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public int renderECAM(TextRenderer textRenderer, DrawContext context, float x, f
? Text.translatable("alerts.flightassistant.nav.reached_void_damage_level")
: Text.translatable("alerts.flightassistant.nav.approaching_void_damage_level");

return HudComponent.drawHighlightedFont(textRenderer, context, x, y, text,
return HudComponent.drawHighlightedFont(textRenderer, context, text, x, y,
HudComponent.CONFIG.alertColor,
!dismissed && highlight);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public boolean renderCentered(TextRenderer textRenderer, DrawContext context, fl
if (computer.gpws.descentImpactTime <= PULL_UP_THRESHOLD) {
Text text = Text.translatable("alerts.flightassistant.pull_up");
float startX = (width - textRenderer.getWidth(text)) * 0.5f;
HudComponent.drawHighlightedFont(textRenderer, context, startX, y, text,
HudComponent.drawHighlightedFont(textRenderer, context, text, startX, y,
CONFIG.alertColor, highlight);

return true;
Expand All @@ -48,7 +48,7 @@ public boolean renderCentered(TextRenderer textRenderer, DrawContext context, fl
if (computer.gpws.descentImpactTime <= SINK_RATE_THRESHOLD) {
Text text = Text.translatable("alerts.flightassistant.sink_rate");
float startX = (width - textRenderer.getWidth(text)) * 0.5f;
HudComponent.drawHighlightedFont(textRenderer, context, startX, y, text,
HudComponent.drawHighlightedFont(textRenderer, context, text, startX, y,
CONFIG.amberColor, highlight);

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public boolean renderCentered(TextRenderer textRenderer, DrawContext context, fl
if (computer.gpws.terrainImpactTime <= PULL_UP_THRESHOLD) {
Text text = Text.translatable("alerts.flightassistant.pull_up");
float startX = (width - textRenderer.getWidth(text)) * 0.5f;
HudComponent.drawHighlightedFont(textRenderer, context, startX, y, text,
HudComponent.drawHighlightedFont(textRenderer, context, text, startX, y,
HudComponent.CONFIG.alertColor, highlight);

return true;
Expand All @@ -67,7 +67,7 @@ public boolean renderCentered(TextRenderer textRenderer, DrawContext context, fl
if (computer.gpws.terrainImpactTime <= TERRAIN_THRESHOLD) {
Text text = Text.translatable("alerts.flightassistant.terrain_ahead");
float startX = (width - textRenderer.getWidth(text)) * 0.5f;
HudComponent.drawHighlightedFont(textRenderer, context, startX, y, text,
HudComponent.drawHighlightedFont(textRenderer, context, text, startX, y,
HudComponent.CONFIG.amberColor, highlight);

return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
package ru.octol1ttle.flightassistant.commands;

public class SetAutoThrustSpeedCommand {
import com.mojang.brigadier.Command;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.context.CommandContext;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import ru.octol1ttle.flightassistant.HudRenderer;

public class SetAutoThrustSpeedCommand implements Command<FabricClientCommandSource> {
@Override
public int run(CommandContext<FabricClientCommandSource> context) {
if (HudRenderer.getComputer() != null) {
HudRenderer.getComputer().autoflight.targetSpeed = IntegerArgumentType.getInteger(context, "targetSpeed");
}
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
import ru.octol1ttle.flightassistant.FlightAssistant;

public class SwitchDisplayModeCommand implements Command<FabricClientCommandSource> {

@Override
public int run(CommandContext<FabricClientCommandSource> context) {
FlightAssistant.CONFIG_SETTINGS.toggleDisplayMode(context.getSource().getClient());
return 0;
}

}
Loading

0 comments on commit 348a2fc

Please sign in to comment.