Skip to content

Commit

Permalink
how am I supposed to split these changes
Browse files Browse the repository at this point in the history
Signed-off-by: Octol1ttle <[email protected]>
  • Loading branch information
Octol1ttle committed Oct 28, 2023
1 parent c7f9edc commit 4b3d257
Show file tree
Hide file tree
Showing 19 changed files with 206 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static int drawFont(TextRenderer textRenderer, DrawContext context, Strin
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);
HudComponent.fill(context, x - 1.5f, y - 1.0f, x + textRenderer.getWidth(text), y + 8.0f, highlightColor);
HudComponent.drawFont(textRenderer, context, text, x, y, CONFIG.white);
});
return 1;
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/ru/octol1ttle/flightassistant/HudRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public HudRenderer(MinecraftClient mc) {
new AltitudeIndicator(computer, dim), new PitchIndicator(computer, dim),
new ElytraHealthIndicator(computer, dim), new AlertIndicator(computer, dim),
new FlightModeIndicator(computer, dim)));
this.toDelete = new ArrayList<>();
this.toDelete = new ArrayList<>(components.size());
}

public static FlightComputer getComputer() {
Expand Down Expand Up @@ -99,8 +99,9 @@ public void render(DrawContext context, MinecraftClient mc) {
}
}

components.removeAll(toDelete);
toDelete.clear();
if (components.removeAll(toDelete)) {
toDelete.clear();
}

context.getMatrices().pop();
}
Expand Down
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 FireworkCountZeroAlert extends AbstractAlert {

private final FlightComputer computer;

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

@Override
public boolean isTriggered() {
return computer.firework.safeFireworkCount <= 0;
}

@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.count_zero"), x, y,
CONFIG.alertColor,
highlight && !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 FireworkLowCountAlert extends AbstractAlert {

private final FlightComputer computer;

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

@Override
public boolean isTriggered() {
return computer.firework.safeFireworkCount > 0 && computer.firework.safeFireworkCount <= 24;
}

@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.low_count"), x, y,
CONFIG.amberColor,
!dismissed);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package ru.octol1ttle.flightassistant.alerts.other;

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;

public class ElytraHealthLowAlert extends AbstractAlert {
private final FlightComputer computer;

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

@Override
public boolean isTriggered() {
return computer.elytraHealth <= 5.0f;
}

@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.elytra_health_low"), x, y,
HudComponent.CONFIG.alertColor,
!dismissed && highlight);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package ru.octol1ttle.flightassistant.alerts;
package ru.octol1ttle.flightassistant.alerts.other;

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;

public class InternalErrorAlert extends AbstractAlert {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.octol1ttle.flightassistant.alerts;
package ru.octol1ttle.flightassistant.alerts.other;

import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
Expand All @@ -7,6 +7,8 @@
import net.minecraft.util.Identifier;
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.computers.FlightComputer;
import ru.octol1ttle.flightassistant.computers.GPWSComputer;
import ru.octol1ttle.flightassistant.computers.StallComputer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,59 @@
import java.util.List;
import net.minecraft.client.sound.SoundManager;
import ru.octol1ttle.flightassistant.AlertSoundInstance;
import ru.octol1ttle.flightassistant.FlightAssistant;
import ru.octol1ttle.flightassistant.alerts.AbstractAlert;
import ru.octol1ttle.flightassistant.alerts.AlertSoundData;
import ru.octol1ttle.flightassistant.alerts.InternalErrorAlert;
import ru.octol1ttle.flightassistant.alerts.StallAlert;
import ru.octol1ttle.flightassistant.alerts.autoflight.ATHRNoFireworksInHotbarAlert;
import ru.octol1ttle.flightassistant.alerts.firework.FireworkCountZeroAlert;
import ru.octol1ttle.flightassistant.alerts.firework.FireworkDelayedResponseAlert;
import ru.octol1ttle.flightassistant.alerts.firework.FireworkLowCountAlert;
import ru.octol1ttle.flightassistant.alerts.firework.FireworkNoResponseAlert;
import ru.octol1ttle.flightassistant.alerts.nav.ApproachingVoidDamageLevelAlert;
import ru.octol1ttle.flightassistant.alerts.nav.gpws.ExcessiveDescentAlert;
import ru.octol1ttle.flightassistant.alerts.nav.gpws.ExcessiveTerrainClosureAlert;
import ru.octol1ttle.flightassistant.alerts.other.ElytraHealthLowAlert;
import ru.octol1ttle.flightassistant.alerts.other.InternalErrorAlert;
import ru.octol1ttle.flightassistant.alerts.other.StallAlert;

public class AlertController {
public final List<AbstractAlert> activeAlerts;
private final FlightComputer computer;
private final SoundManager manager;
private final AbstractAlert[] ALERTS;
private final List<AbstractAlert> allAlerts;
private final List<AbstractAlert> toDelete;

public AlertController(FlightComputer computer, SoundManager manager) {
this.computer = computer;
this.manager = manager;
// TODO: ECAM actions
ALERTS = new AbstractAlert[]{
allAlerts = new ArrayList<>(List.of(
new StallAlert(computer),
new ExcessiveDescentAlert(computer), new ExcessiveTerrainClosureAlert(computer), // GPWS
new InternalErrorAlert(computer),
new ApproachingVoidDamageLevelAlert(computer),
new ElytraHealthLowAlert(computer),
new FireworkCountZeroAlert(computer),
new FireworkNoResponseAlert(computer), new FireworkDelayedResponseAlert(computer),
new ATHRNoFireworksInHotbarAlert(computer)
};
activeAlerts = new ArrayList<>();
new FireworkLowCountAlert(computer),
new ATHRNoFireworksInHotbarAlert(computer)));
activeAlerts = new ArrayList<>(allAlerts.size());
toDelete = new ArrayList<>(allAlerts.size());
}

public void tick() {
for (AbstractAlert alert : ALERTS) {
if (alert.isTriggered()) {
if (!activeAlerts.contains(alert)) {
activeAlerts.add(alert);
for (AbstractAlert alert : allAlerts) {
try {
if (alert.isTriggered()) {
if (!activeAlerts.contains(alert)) {
activeAlerts.add(alert);
}
continue;
}
continue;
} catch (Exception e) {
FlightAssistant.LOGGER.error("Exception triggering alert", e);
toDelete.add(alert);
computer.internalError = true;
}

if (!activeAlerts.contains(alert)) {
Expand All @@ -62,6 +76,10 @@ public void tick() {
activeAlerts.remove(alert);
}

if (allAlerts.removeAll(toDelete)) {
toDelete.clear();
}

boolean interrupt = false;
activeAlerts.sort(Comparator.comparingDouble(alert -> alert.getAlertSoundData().priority()));
for (AbstractAlert alert : activeAlerts) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public AutoFlightComputer(FlightComputer computer) {
}

public void tick() {
if (autoThrustEnabled && targetSpeed != null && computer.speed < targetSpeed && computer.gpws.getGPWSLampColor() != CONFIG.alertColor) {
if (autoThrustEnabled && targetSpeed != null && computer.speed < targetSpeed && computer.gpws.getGPWSLampColor() == CONFIG.color) {
computer.firework.activateFirework(false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

public class FireworkManager {
private final FlightComputer computer;
public int safeFireworkCount;
public boolean fireworkResponded = true;
public float lastUseTime = -1.0f;
public float lastDiff = Float.MAX_VALUE;
Expand All @@ -23,6 +24,7 @@ public FireworkManager(FlightComputer computer) {

public void tick() {
// TODO: client<->server communication to confirm firework activation
safeFireworkCount = countSafeFireworks();
if (computer.speed > 30) {
fireworkResponded = true;
}
Expand All @@ -31,6 +33,20 @@ public void tick() {
}
}

private int countSafeFireworks() {
int i = 0;

PlayerInventory inventory = computer.player.getInventory();
for (int j = 0; j < inventory.size(); ++j) {
ItemStack itemStack = inventory.getStack(j);
if (isFireworkSafe(itemStack)) {
i += itemStack.getCount();
}
}

return i;
}

public boolean activateFirework(boolean togaLock) {
if (!computer.canAutomationsActivate() || lastUseTime > 0 && computer.time.prevMillis - lastUseTime < 750) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.joml.Matrix3f;
import ru.octol1ttle.flightassistant.FlightAssistant;

Expand All @@ -34,8 +33,7 @@ public class FlightComputer {
public Vec3d position;
public Vec3d velocity;
public Vec3d velocityPerSecond;
@Nullable
public Vec3d acceleration;
public Vec3d acceleration = Vec3d.ZERO;
public float speed;
public float pitch;
public float yaw;
Expand Down Expand Up @@ -102,12 +100,13 @@ public void tick() {
return;
}

gpws.tick();
autoflight.tick();
alert.tick();
stall.tick();
gpws.tick();
voidDamage.tick();
firework.tick();
autoflight.tick();

alert.tick();
}

public void updateRoll(Matrix3f normal) {
Expand Down Expand Up @@ -190,7 +189,7 @@ private int computeVoidLevel() {

private float computeDistanceFromGround(float altitude,
Integer groundLevel) {
return Math.max(-64f, altitude - groundLevel);
return Math.max(0.0f, altitude - groundLevel);
}

private float computeAltitude() {
Expand Down
Loading

0 comments on commit 4b3d257

Please sign in to comment.