-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
165 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/ru/octol1ttle/flightassistant/alerts/nav/UnloadedChunkAlert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package ru.octol1ttle.flightassistant.alerts.nav; | ||
|
||
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.AlertSoundData; | ||
import ru.octol1ttle.flightassistant.alerts.BaseAlert; | ||
import ru.octol1ttle.flightassistant.alerts.IECAMAlert; | ||
import ru.octol1ttle.flightassistant.computers.safety.ChunkStatusComputer; | ||
|
||
public class UnloadedChunkAlert extends BaseAlert implements IECAMAlert { | ||
|
||
private final ChunkStatusComputer chunkStatus; | ||
|
||
public UnloadedChunkAlert(ChunkStatusComputer chunkStatus) { | ||
this.chunkStatus = chunkStatus; | ||
} | ||
|
||
@Override | ||
public boolean isTriggered() { | ||
return chunkStatus.isInWarning(); | ||
} | ||
|
||
@Override | ||
public int render(TextRenderer textRenderer, DrawContext context, int x, int y, boolean highlight) { | ||
return HudComponent.drawHighlightedText(textRenderer, context, Text.translatable("alerts.flightassistant.unloaded_chunk"), x, y, | ||
chunkStatus.getIndicator(), highlight); | ||
} | ||
|
||
@Override | ||
public @NotNull AlertSoundData getSoundData() { | ||
return AlertSoundData.MASTER_WARNING; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
src/main/java/ru/octol1ttle/flightassistant/computers/safety/ChunkStatusComputer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package ru.octol1ttle.flightassistant.computers.safety; | ||
|
||
import net.minecraft.client.MinecraftClient; | ||
import ru.octol1ttle.flightassistant.computers.AirDataComputer; | ||
import ru.octol1ttle.flightassistant.computers.ComputerHost; | ||
import ru.octol1ttle.flightassistant.computers.ITickableComputer; | ||
import ru.octol1ttle.flightassistant.computers.TimeComputer; | ||
import ru.octol1ttle.flightassistant.config.FAConfig; | ||
|
||
import java.awt.Color; | ||
|
||
public class ChunkStatusComputer implements ITickableComputer { | ||
|
||
private final ComputerHost host; | ||
private final MinecraftClient mc; | ||
private final AirDataComputer data; | ||
private final TimeComputer time; | ||
|
||
public final float recoverPitch = 10f; | ||
private boolean isInWarning; | ||
private boolean isLoaded; | ||
private float lastEncounteredMS = 0f; | ||
private float lastDiffMS = 0f; | ||
private float offsetMS = 0f; // for single player pause | ||
|
||
// milliseconds difference | ||
private static final float WARN_THRESHOLD = 3200f; | ||
|
||
public ChunkStatusComputer(ComputerHost host, MinecraftClient mc, AirDataComputer data, TimeComputer time) { | ||
this.host = host; | ||
this.mc = mc; | ||
this.data = data; | ||
this.time = time; | ||
} | ||
|
||
@Override | ||
public void tick() { | ||
if (!data.isFlying()) { | ||
return; | ||
} | ||
|
||
isLoaded = data.isCurrentChunkLoaded; | ||
|
||
if (isLoaded) { | ||
if (!host.faulted.contains(time) && time.prevMillis != null) { | ||
lastEncounteredMS = time.prevMillis; | ||
} | ||
isLoaded = false; | ||
offsetMS = 0f; | ||
} | ||
|
||
final boolean isSinglePlayerPause = (mc.isInSingleplayer() && mc.isPaused()); | ||
if (isSinglePlayerPause && !isLoaded) { | ||
offsetMS = ((time.prevMillis - lastEncounteredMS) - lastDiffMS); | ||
} | ||
|
||
if (time.prevMillis != null && lastEncounteredMS > 0f) { | ||
lastDiffMS = (time.prevMillis - offsetMS) - lastEncounteredMS; | ||
} | ||
|
||
isInWarning = shouldWarn(); | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return "chunk_state"; | ||
} | ||
|
||
@Override | ||
public void reset() { | ||
isInWarning = false; | ||
isLoaded = true; | ||
lastDiffMS = 0f; | ||
lastEncounteredMS = 0f; | ||
offsetMS = 0f; | ||
} | ||
|
||
public boolean shouldCorrectTerrain() { | ||
return FAConfig.computer().unloadedChunkProtection.recover() && isInWarning(); | ||
} | ||
|
||
public boolean isInWarning() { | ||
return isInWarning; | ||
} | ||
|
||
public float getLastDiffMS() { | ||
return lastDiffMS; | ||
} | ||
|
||
public Color getIndicator() { | ||
return FAConfig.indicator().warningColor; | ||
} | ||
|
||
private boolean shouldWarn() { | ||
if (data.isFlying() && !data.isCurrentChunkLoaded) { | ||
return lastDiffMS >= WARN_THRESHOLD; | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters