Skip to content

Commit

Permalink
Check firework safety every tick instead of on use
Browse files Browse the repository at this point in the history
Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
  • Loading branch information
Octol1ttle committed Feb 28, 2024
1 parent b18ecf2 commit 00c5ca4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
5 changes: 1 addition & 4 deletions src/main/java/ru/octol1ttle/flightassistant/FACallbacks.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,11 @@ private static void setupUseItem() {
return TypedActionResult.pass(stack);
}
if (!host.data.isFlying || !(stack.getItem() instanceof FireworkRocketItem)) {
host.firework.unsafeFireworks = false;
return TypedActionResult.pass(stack);
}

host.firework.unsafeFireworks = !host.firework.isFireworkSafe(stack);

boolean gpwsDanger = !host.faulted.contains(host.gpws) && (host.gpws.isInDanger() || !host.gpws.fireworkUseSafe);
if (!host.firework.activationInProgress && (host.firework.unsafeFireworks || host.firework.lockManualFireworks || gpwsDanger)) {
if (!host.firework.activationInProgress && (!host.firework.isFireworkSafe(player.getStackInHand(hand)) || host.firework.lockManualFireworks || gpwsDanger)) {
return TypedActionResult.fail(stack);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.item.FireworkRocketItem;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import net.minecraft.util.Hand;
import org.jetbrains.annotations.NotNull;
import ru.octol1ttle.flightassistant.HudComponent;
import ru.octol1ttle.flightassistant.alerts.AbstractAlert;
Expand All @@ -24,7 +27,14 @@ public FireworkUnsafeAlert(AirDataComputer data, FireworkController firework) {

@Override
public boolean isTriggered() {
return firework.unsafeFireworks;
for (Hand hand : Hand.values()) {
ItemStack stack = data.player.getStackInHand(hand);
if (stack.getItem() instanceof FireworkRocketItem && !firework.isFireworkSafe(stack)) {
return true;
}
}

return false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class FireworkController implements ITickableComputer {
public float lastDiff = Float.MIN_VALUE;
public Float lastProtTrigger;
public boolean noFireworks = false;
public boolean unsafeFireworks = false;
public boolean activationInProgress = false;
public boolean lockManualFireworks = false;

Expand Down Expand Up @@ -140,7 +139,7 @@ public void reset() {
lastUseTime = -1.0f;
lastDiff = Float.MIN_VALUE;
noFireworks = false;
unsafeFireworks = false;
activationInProgress = false;
lockManualFireworks = false;
}
}

0 comments on commit 00c5ca4

Please sign in to comment.