-
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.
This PR add some feature for chunk status, as follow. Indicate if current chunk is unloaded, use last ground height as reference. Player will receive an alert when they fly into unloaded chunk after a certain amount of time. After 3.2 seconds, alert will be shown and will pitch up by ~10 degrees if enabled. Screenshot ![image](https://i.imgur.com/epW1ao8.png)
- Loading branch information
Showing
11 changed files
with
173 additions
and
9 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
36 changes: 36 additions & 0 deletions
36
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,36 @@ | ||
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; | ||
import ru.octol1ttle.flightassistant.config.FAConfig; | ||
|
||
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, | ||
FAConfig.indicator().warningColor, 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
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
85 changes: 85 additions & 0 deletions
85
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,85 @@ | ||
package ru.octol1ttle.flightassistant.computers.safety; | ||
|
||
import net.minecraft.client.MinecraftClient; | ||
import ru.octol1ttle.flightassistant.computers.AirDataComputer; | ||
import ru.octol1ttle.flightassistant.computers.ITickableComputer; | ||
import ru.octol1ttle.flightassistant.computers.TimeComputer; | ||
import ru.octol1ttle.flightassistant.config.FAConfig; | ||
|
||
public class ChunkStatusComputer implements ITickableComputer { | ||
private final MinecraftClient mc; | ||
private final AirDataComputer data; | ||
private final TimeComputer time; | ||
|
||
private boolean isInWarning; | ||
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(MinecraftClient mc, AirDataComputer data, TimeComputer time) { | ||
this.mc = mc; | ||
this.data = data; | ||
this.time = time; | ||
} | ||
|
||
@Override | ||
public void tick() { | ||
if (!data.isFlying()) { | ||
reset(); | ||
return; | ||
} | ||
|
||
if (data.isCurrentChunkLoaded) { | ||
if (time.prevMillis != null) { | ||
lastEncounteredMS = time.prevMillis; | ||
} | ||
offsetMS = 0f; | ||
} | ||
|
||
final boolean isSinglePlayerPause = (mc.isInSingleplayer() && mc.isPaused()); | ||
if (isSinglePlayerPause && !data.isCurrentChunkLoaded) { | ||
offsetMS = ((time.prevMillis - lastEncounteredMS) - lastDiffMS); | ||
} | ||
|
||
if (time.prevMillis != null && lastEncounteredMS > 0f) { | ||
lastDiffMS = (time.prevMillis - offsetMS) - lastEncounteredMS; | ||
} | ||
|
||
isInWarning = shouldWarn(); | ||
} | ||
|
||
public boolean shouldCorrectTerrain() { | ||
return FAConfig.computer().unloadedChunkProtection.recover() && isInWarning(); | ||
} | ||
|
||
public boolean isInWarning() { | ||
return isInWarning; | ||
} | ||
|
||
public float getLastDiffMS() { | ||
return lastDiffMS; | ||
} | ||
|
||
private boolean shouldWarn() { | ||
if (data.isFlying() && !data.isCurrentChunkLoaded) { | ||
return lastDiffMS >= WARN_THRESHOLD; | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return "chunk_state"; | ||
} | ||
|
||
@Override | ||
public void reset() { | ||
isInWarning = false; | ||
lastDiffMS = 0f; | ||
lastEncounteredMS = 0f; | ||
offsetMS = 0f; | ||
} | ||
} |
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
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