Skip to content

Commit

Permalink
firework unsafe alert
Browse files Browse the repository at this point in the history
Signed-off-by: Octol1ttle <[email protected]>
  • Loading branch information
Octol1ttle committed Oct 29, 2023
1 parent 4b3d257 commit efd561c
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 17 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.0f, x + textRenderer.getWidth(text), y + 8.0f, highlightColor);
HudComponent.fill(context, x - 2.0f, y - 1.0f, x + textRenderer.getWidth(text) + 0.5f, y + 8.0f, highlightColor);
HudComponent.drawFont(textRenderer, context, text, x, y, CONFIG.white);
});
return 1;
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 FireworkUnsafeAlert extends AbstractAlert {

private final FlightComputer computer;

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

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

@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.unsafe"), x, y,
CONFIG.alertColor,
!dismissed && highlight);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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.firework.FireworkUnsafeAlert;
import ru.octol1ttle.flightassistant.alerts.nav.ApproachingVoidDamageLevelAlert;
import ru.octol1ttle.flightassistant.alerts.nav.gpws.ExcessiveDescentAlert;
import ru.octol1ttle.flightassistant.alerts.nav.gpws.ExcessiveTerrainClosureAlert;
Expand All @@ -37,6 +38,7 @@ public AlertController(FlightComputer computer, SoundManager manager) {
new InternalErrorAlert(computer),
new ApproachingVoidDamageLevelAlert(computer),
new ElytraHealthLowAlert(computer),
new FireworkUnsafeAlert(computer),
new FireworkCountZeroAlert(computer),
new FireworkNoResponseAlert(computer), new FireworkDelayedResponseAlert(computer),
new FireworkLowCountAlert(computer),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import net.minecraft.util.Hand;
import org.jetbrains.annotations.Nullable;

public class FireworkManager {
public class FireworkController {
private final FlightComputer computer;
public int safeFireworkCount;
public boolean fireworkResponded = true;
Expand All @@ -17,8 +17,9 @@ public class FireworkManager {
@Nullable
public Float lastTogaLock;
public boolean noFireworks;
public boolean unsafeFireworks;

public FireworkManager(FlightComputer computer) {
public FireworkController(FlightComputer computer) {
this.computer = computer;
}

Expand Down Expand Up @@ -97,7 +98,7 @@ private boolean tryActivateFirework(Hand hand) {
return false;
}

private boolean isFireworkSafe(ItemStack stack) {
public boolean isFireworkSafe(ItemStack stack) {
if (!(stack.getItem() instanceof FireworkRocketItem)) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class FlightComputer {
public final TimeComputer time;
public final StallComputer stall;
public final VoidDamageLevelComputer voidDamage;
public final FireworkManager firework;
public final FireworkController firework;
public final PitchController pitchControl;
public final AlertController alert;
@NotNull
Expand Down Expand Up @@ -59,7 +59,7 @@ public FlightComputer(@NotNull MinecraftClient mc) {
this.autoflight = new AutoFlightComputer(this);
this.stall = new StallComputer(this);
this.voidDamage = new VoidDamageLevelComputer(this);
this.firework = new FireworkManager(this);
this.firework = new FireworkController(this);
this.time = new TimeComputer();
this.pitchControl = new PitchController(this);
this.alert = new AlertController(this, mc.getSoundManager());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,34 @@

import net.minecraft.client.network.ClientPlayerInteractionManager;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.FireworkRocketItem;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
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.CallbackInfoReturnable;
import ru.octol1ttle.flightassistant.HudRenderer;
import ru.octol1ttle.flightassistant.computers.FlightComputer;

@Mixin(ClientPlayerInteractionManager.class)
public class ClientPlayerInteractionManagerMixin {
@Inject(method = "interactItem", at = @At("HEAD"), cancellable = true)
public void disallowUnsafeFireworks(PlayerEntity player, Hand hand, CallbackInfoReturnable<ActionResult> cir) {
/*if (!player.isFallFlying()) return;
ItemStack stack = player.getStackInHand(hand);
FlightComputer computer = HudRenderer.getComputer();
if (!player.isFallFlying() || !(stack.getItem() instanceof FireworkRocketItem) || computer == null) {
if (computer != null) {
computer.firework.unsafeFireworks = false;
}
return;
}


if (FlightSafetyMonitor.flightProtectionsEnabled && FlightSafetyMonitor.unsafeFireworkHands.contains(hand))
if (!computer.firework.isFireworkSafe(stack)) {
computer.firework.unsafeFireworks = true;
cir.setReturnValue(ActionResult.FAIL);
else if (player.getStackInHand(hand).getItem() instanceof FireworkRocketItem) {
if (FlightSafetyMonitor.flightProtectionsEnabled && !FlightSafetyMonitor.thrustSet
|| FlightSafetyMonitor.thrustLocked)
cir.setReturnValue(ActionResult.FAIL);
else {
FlightSafetyMonitor.lastFireworkActivationTimeMs = Util.getMeasuringTimeMs();
FlightSafetyMonitor.thrustSet = false;
}
}*/
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/assets/flightassistant/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"alerts.flightassistant.firework.no_fireworks": "NO FRWKS IN HOTBAR",
"alerts.flightassistant.firework.low_count": "FRWK CNT BELOW 24",
"alerts.flightassistant.firework.count_zero": "FRWK CNT AT ZERO",
"alerts.flightassistant.firework.unsafe": "FRWK UNSAFE (EXPLOSIVE)",

"flightassistant.toga_lock": "TOGA LK",
"flightassistant.thrust_mode_speed": "SPD %s",
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/flightassistant/lang/ru_ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"alerts.flightassistant.firework.no_fireworks": "НЕТ ФРВКОВ НА ПАНЕЛИ БЫСТР. ДОСТУПА",
"alerts.flightassistant.firework.low_count": "КОЛ-ВО ФРВКОВ НИЖЕ 24",
"alerts.flightassistant.firework.count_zero": "КОЛ-ВО ФРВКОВ НА НУЛЕ",
"alerts.flightassistant.firework.unsafe": "ФРВК ВЗРЫВООПАСЕН",

"flightassistant.toga_lock": "МАКС. ТЯГА",
"flightassistant.thrust_mode_speed": "СКОР %s",
Expand Down

0 comments on commit efd561c

Please sign in to comment.