Skip to content

Commit

Permalink
Allow maximum flight protections mode in the config screen, refactor …
Browse files Browse the repository at this point in the history
…config (again)

Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
  • Loading branch information
Octol1ttle committed Feb 28, 2024
1 parent 00c5ca4 commit 25cb6bd
Show file tree
Hide file tree
Showing 38 changed files with 496 additions and 375 deletions.
8 changes: 4 additions & 4 deletions src/main/java/ru/octol1ttle/flightassistant/Dimensions.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ public class Dimensions {
public int bFrame;

public void update(DrawContext context, double fov) {
hScreen = MathHelper.floor(context.getScaledWindowHeight() / FAConfig.get().hudScale);
wScreen = MathHelper.floor(context.getScaledWindowWidth() / FAConfig.get().hudScale);
hScreen = MathHelper.floor(context.getScaledWindowHeight() / FAConfig.hud().hudScale);
wScreen = MathHelper.floor(context.getScaledWindowWidth() / FAConfig.hud().hudScale);

degreesPerPixel = MathHelper.floor(hScreen / fov);
xMid = wScreen / 2;
yMid = hScreen / 2;

wFrame = (int) (wScreen * FAConfig.get().frameWidth);
hFrame = (int) (hScreen * FAConfig.get().frameHeight);
wFrame = (int) (wScreen * FAConfig.hud().frameWidth);
hFrame = (int) (hScreen * FAConfig.hud().frameHeight);

lFrame = (wScreen - wFrame) / 2;
rFrame = lFrame + wFrame;
Expand Down
182 changes: 106 additions & 76 deletions src/main/java/ru/octol1ttle/flightassistant/FAModMenuImpl.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.octol1ttle.flightassistant.config.FAConfig;
import ru.octol1ttle.flightassistant.config.HUDConfig;

public class FlightAssistant implements ClientModInitializer {
public static final String MODID = "flightassistant";
Expand All @@ -18,7 +19,7 @@ public void onInitializeClient() {
}

public static boolean isHUDBatched() {
return canUseBatching() && FAConfig.get().batchedRendering != FAConfig.BatchedRendering.NO_BATCHING;
return canUseBatching() && FAConfig.hud().batchedRendering != HUDConfig.BatchedRendering.NO_BATCHING;
}

public static boolean canUseBatching() {
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 @@ -9,6 +9,7 @@
import ru.octol1ttle.flightassistant.compatibility.ImmediatelyFastBatchingAccessor;
import ru.octol1ttle.flightassistant.computers.ComputerHost;
import ru.octol1ttle.flightassistant.config.FAConfig;
import ru.octol1ttle.flightassistant.config.HUDConfig;
import ru.octol1ttle.flightassistant.indicators.AlertIndicator;
import ru.octol1ttle.flightassistant.indicators.AltitudeIndicator;
import ru.octol1ttle.flightassistant.indicators.ElytraHealthIndicator;
Expand Down Expand Up @@ -53,8 +54,8 @@ public void render(MinecraftClient mc, DrawContext context, float tickDelta) {
GameRendererInvoker renderer = (GameRendererInvoker) mc.gameRenderer;
dim.update(context, renderer.getFov(mc.gameRenderer.getCamera(), tickDelta, true));

float hudScale = FAConfig.get().hudScale;
boolean batchAll = FlightAssistant.canUseBatching() && FAConfig.get().batchedRendering == FAConfig.BatchedRendering.SINGLE_BATCH;
float hudScale = FAConfig.hud().hudScale;
boolean batchAll = FlightAssistant.canUseBatching() && FAConfig.hud().batchedRendering == HUDConfig.BatchedRendering.SINGLE_BATCH;

context.getMatrices().push();
context.getMatrices().scale(hudScale, hudScale, hudScale);
Expand Down Expand Up @@ -92,7 +93,7 @@ public void render(MinecraftClient mc, DrawContext context, float tickDelta) {
}

public void drawBatchedComponent(Runnable draw) {
boolean batch = FlightAssistant.canUseBatching() && FAConfig.get().batchedRendering == FAConfig.BatchedRendering.BATCH_PER_COMPONENT;
boolean batch = FlightAssistant.canUseBatching() && FAConfig.hud().batchedRendering == HUDConfig.BatchedRendering.PER_COMPONENT;
if (batch) {
ImmediatelyFastBatchingAccessor.beginHudBatching();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public boolean isTriggered() {
@Override
public int renderECAM(TextRenderer textRenderer, DrawContext context, int x, int y, boolean highlight) {
return HudComponent.drawHighlightedText(textRenderer, context, Text.translatable("alerts.flightassistant.autoflight.auto_firework_off"), x, y,
FAConfig.hud().cautionColor,
FAConfig.indicator().cautionColor,
highlight && autoflight.afrwkDisconnectionForced);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public boolean isTriggered() {
@Override
public int renderECAM(TextRenderer textRenderer, DrawContext context, int x, int y, boolean highlight) {
return HudComponent.drawHighlightedText(textRenderer, context, Text.translatable("alerts.flightassistant.autoflight.autopilot_off"), x, y,
FAConfig.hud().warningColor,
FAConfig.indicator().warningColor,
highlight && autoflight.apDisconnectionForced);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public int renderECAM(TextRenderer textRenderer, DrawContext context, int x, int
int i = 0;
for (IComputer computer : host.faulted) {
i += HudComponent.drawHighlightedText(textRenderer, context, Text.translatable("alerts.flightassistant.fault.computers." + computer.getId()), x, y,
FAConfig.hud().warningColor, highlight);
FAConfig.indicator().warningColor, highlight);
y += 10;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public int renderECAM(TextRenderer textRenderer, DrawContext context, int x, int
int i = 0;
for (HudComponent component : renderer.faulted) {
i += HudComponent.drawText(textRenderer, context, Text.translatable("alerts.flightassistant.fault.indicators." + component.getId()), x, y,
FAConfig.hud().cautionColor);
FAConfig.indicator().cautionColor);
y += 10;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ public boolean isTriggered() {
@Override
public int renderECAM(TextRenderer textRenderer, DrawContext context, int x, int y, boolean highlight) {
return HudComponent.drawHighlightedText(textRenderer, context, Text.translatable("alerts.flightassistant.firework.no_response"), x, y,
FAConfig.hud().warningColor, highlight);
FAConfig.indicator().warningColor, highlight);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ public boolean isTriggered() {
@Override
public int renderECAM(TextRenderer textRenderer, DrawContext context, int x, int y, boolean highlight) {
return HudComponent.drawHighlightedText(textRenderer, context, Text.translatable("alerts.flightassistant.firework.unsafe"), x, y,
FAConfig.hud().warningColor, highlight && data.isFlying);
FAConfig.indicator().warningColor, highlight && data.isFlying);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public int renderECAM(TextRenderer textRenderer, DrawContext context, int x, int
: Text.translatable("alerts.flightassistant.approaching_void_damage_level");

return HudComponent.drawHighlightedText(textRenderer, context, text, x, y,
FAConfig.hud().warningColor, highlight);
FAConfig.indicator().warningColor, highlight);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public boolean isTriggered() {
@Override
public int renderECAM(TextRenderer textRenderer, DrawContext context, int x, int y, boolean highlight) {
return HudComponent.drawHighlightedText(textRenderer, context, Text.translatable("alerts.flightassistant.reached_minimums"), x, y,
FAConfig.hud().cautionColor, false);
FAConfig.indicator().cautionColor, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ public boolean isTriggered() {
public boolean renderCentered(TextRenderer textRenderer, DrawContext context, int x, int y, boolean highlight) {
if (gpws.descentImpactTime <= PULL_UP_THRESHOLD) {
HudComponent.drawHighlightedMiddleAlignedText(textRenderer, context, Text.translatable("alerts.flightassistant.pull_up"), x, y,
FAConfig.hud().warningColor, highlight);
FAConfig.indicator().warningColor, highlight);

return true;
}

if (gpws.descentImpactTime <= SINK_RATE_THRESHOLD) {
HudComponent.drawHighlightedMiddleAlignedText(textRenderer, context, Text.translatable("alerts.flightassistant.sink_rate"), x, y,
FAConfig.hud().cautionColor, highlight);
FAConfig.indicator().cautionColor, highlight);

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ public boolean isTriggered() {
public boolean renderCentered(TextRenderer textRenderer, DrawContext context, int x, int y, boolean highlight) {
if (gpws.terrainImpactTime <= PULL_UP_THRESHOLD) {
HudComponent.drawHighlightedMiddleAlignedText(textRenderer, context, Text.translatable("alerts.flightassistant.pull_up"), x, y,
FAConfig.hud().warningColor, highlight);
FAConfig.indicator().warningColor, highlight);

return true;
}

if (gpws.terrainImpactTime <= TERRAIN_THRESHOLD) {
HudComponent.drawHighlightedMiddleAlignedText(textRenderer, context, Text.translatable("alerts.flightassistant.terrain_ahead"), x, y,
FAConfig.hud().cautionColor, highlight);
FAConfig.indicator().cautionColor, highlight);

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public boolean isTriggered() {
@Override
public int renderECAM(TextRenderer textRenderer, DrawContext context, int x, int y, boolean highlight) {
return HudComponent.drawHighlightedText(textRenderer, context, Text.translatable("alerts.flightassistant.elytra_health_low"), x, y,
FAConfig.hud().warningColor, highlight && data.isFlying);
FAConfig.indicator().warningColor, highlight && data.isFlying);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public boolean isTriggered() {

@Override
public boolean renderCentered(TextRenderer textRenderer, DrawContext context, int x, int y, boolean highlight) {
HudComponent.drawHighlightedMiddleAlignedText(textRenderer, context, Text.translatable("alerts.flightassistant.stall"), x, y, FAConfig.hud().warningColor, highlight);
HudComponent.drawHighlightedMiddleAlignedText(textRenderer, context, Text.translatable("alerts.flightassistant.stall"), x, y, FAConfig.indicator().warningColor, highlight);

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import net.minecraft.world.World;
import org.joml.Matrix3f;
import ru.octol1ttle.flightassistant.FAMathHelper;
import ru.octol1ttle.flightassistant.config.ComputerConfig;
import ru.octol1ttle.flightassistant.config.FAConfig;

import static net.minecraft.SharedConstants.TICKS_PER_SECOND;

Expand Down Expand Up @@ -52,7 +54,12 @@ public boolean canAutomationsActivate() {
}

public boolean canAutomationsActivate(boolean checkFlying) {
return (!checkFlying || isFlying) && mc.currentScreen == null && mc.getOverlay() == null;
ComputerConfig.FlightProtectionsMode mode = FAConfig.computer().protectionsMode;
return switch (mode) {
case FULL -> true; // TODO: wtf? this works even with singleplayer paused
case NO_OVERLAYS -> (!checkFlying || isFlying) && mc.currentScreen == null && mc.getOverlay() == null;
case DISABLED -> false;
};
}

public boolean isGround(BlockPos pos) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public AutoFlightComputer(AirDataComputer data, GPWSComputer gpws, FlightPlanner

@Override
public void tick() {
if (autoFireworkEnabled && gpws.getGPWSLampColor() == FAConfig.hud().frameColor) {
if (autoFireworkEnabled && gpws.getGPWSLampColor() == FAConfig.indicator().frameColor) {
Integer targetSpeed = getTargetSpeed();
Integer targetAltitude = getTargetAltitude();
if (targetSpeed != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public void smoothSetPitch(Float pitch, float delta) {
newPitch = data.pitch + (pitch - data.pitch) * delta;
}

// TODO: wtf? interpolation is missing when opening the inventory
data.player.setPitch(-newPitch);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void tick() {
}

public boolean isInDanger() {
return getGPWSLampColor() == FAConfig.hud().warningColor;
return getGPWSLampColor() == FAConfig.indicator().warningColor;
}

public boolean shouldCorrectSinkrate() {
Expand All @@ -60,13 +60,13 @@ public boolean shouldCorrectTerrain() {

public Color getGPWSLampColor() {
if (positiveLessOrEquals(descentImpactTime, PULL_UP_THRESHOLD) || positiveLessOrEquals(terrainImpactTime, PULL_UP_THRESHOLD)) {
return FAConfig.hud().warningColor;
return FAConfig.indicator().warningColor;
}
if (positiveLessOrEquals(descentImpactTime, CAUTION_THRESHOLD) || positiveLessOrEquals(terrainImpactTime, CAUTION_THRESHOLD)) {
return FAConfig.hud().cautionColor;
return FAConfig.indicator().cautionColor;
}

return FAConfig.hud().frameColor;
return FAConfig.indicator().frameColor;
}

public boolean shouldBlockPitchChanges() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ru.octol1ttle.flightassistant.config;

import dev.isxander.yacl3.api.NameableEnum;
import dev.isxander.yacl3.config.v2.api.SerialEntry;
import java.util.Locale;
import net.minecraft.text.Text;

public class ComputerConfig {
@SerialEntry
public FlightProtectionsMode protectionsMode = FlightProtectionsMode.NO_OVERLAYS;

public enum FlightProtectionsMode implements NameableEnum {
FULL,
// TODO: LIMIT TO NO_OVERLAYS ON SERVERS
NO_OVERLAYS,
DISABLED;

@Override
public Text getDisplayName() {
return Text.translatable("config.flightassistant.computers.protections." + name().toLowerCase(Locale.ROOT));
}
}
}
73 changes: 35 additions & 38 deletions src/main/java/ru/octol1ttle/flightassistant/config/FAConfig.java
Original file line number Diff line number Diff line change
@@ -1,80 +1,77 @@
package ru.octol1ttle.flightassistant.config;

import com.google.gson.GsonBuilder;
import dev.isxander.yacl3.api.NameableEnum;
import dev.isxander.yacl3.config.v2.api.ConfigClassHandler;
import dev.isxander.yacl3.config.v2.api.SerialEntry;
import dev.isxander.yacl3.config.v2.api.serializer.GsonConfigSerializerBuilder;
import dev.isxander.yacl3.platform.YACLPlatform;
import java.util.Locale;
import net.minecraft.client.MinecraftClient;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import ru.octol1ttle.flightassistant.FlightAssistant;

public class FAConfig {
public static ConfigClassHandler<FAConfig> HANDLER = ConfigClassHandler.createBuilder(FAConfig.class)
.id(new Identifier(FlightAssistant.MODID, "main"))
private static final ConfigClassHandler<HUDConfig> HUD_HANDLER = ConfigClassHandler.createBuilder(HUDConfig.class)
.id(new Identifier(FlightAssistant.MODID, "hud"))
.serializer(config -> GsonConfigSerializerBuilder.create(config)
.setPath(YACLPlatform.getConfigDir().resolve("flightassistant.json5"))
.setPath(YACLPlatform.getConfigDir().resolve("flightassistant_hud.json5"))
.appendGsonBuilder(GsonBuilder::setPrettyPrinting) // not needed, pretty print by default
.setJson5(true)
.build())
.build();

@SerialEntry
public HudConfig flying = new HudConfig();
@SerialEntry
public HudConfig notFlyingHasElytra = new HudConfig().setMinimal();
@SerialEntry
public HudConfig notFlyingNoElytra = new HudConfig().disableAll();
private static final ConfigClassHandler<IndicatorConfigStorage> INDICATORS_STORAGE_HANDLER = ConfigClassHandler.createBuilder(IndicatorConfigStorage.class)
.id(new Identifier(FlightAssistant.MODID, "indicators"))
.serializer(config -> GsonConfigSerializerBuilder.create(config)
.setPath(YACLPlatform.getConfigDir().resolve("flightassistant_indicators.json5"))
.appendGsonBuilder(GsonBuilder::setPrettyPrinting) // not needed, pretty print by default
.setJson5(true)
.build())
.build();

@SerialEntry
public BatchedRendering batchedRendering = BatchedRendering.SINGLE_BATCH;
@SerialEntry
public float hudScale = 1.0f;
@SerialEntry
public float frameWidth = 0.6f;
@SerialEntry
public float frameHeight = 0.6f;
private static final ConfigClassHandler<ComputerConfig> COMPUTER_HANDLER = ConfigClassHandler.createBuilder(ComputerConfig.class)
.id(new Identifier(FlightAssistant.MODID, "computers"))
.serializer(config -> GsonConfigSerializerBuilder.create(config)
.setPath(YACLPlatform.getConfigDir().resolve("flightassistant_computers.json5"))
.appendGsonBuilder(GsonBuilder::setPrettyPrinting) // not needed, pretty print by default
.setJson5(true)
.build())
.build();

public static void setup() {
HANDLER.load();
HUD_HANDLER.load();
INDICATORS_STORAGE_HANDLER.load();
COMPUTER_HANDLER.load();
}

public static FAConfig get() {
return HANDLER.instance();
public static HUDConfig hud() {
return HUD_HANDLER.instance();
}

public static HudConfig hud() {
public static IndicatorConfigStorage getIndicatorConfigStorage() {
return INDICATORS_STORAGE_HANDLER.instance();
}

public static IndicatorConfigStorage.IndicatorConfig indicator() {
MinecraftClient client = MinecraftClient.getInstance();
if (client.player == null) {
throw new IllegalStateException("Attempted to retrieve HUD settings when there is no player");
throw new IllegalStateException("Attempted to retrieve indicator settings when there is no player");
}

if (client.player.isFallFlying()) {
return HANDLER.instance().flying;
return INDICATORS_STORAGE_HANDLER.instance().flying;
}

for (ItemStack stack : client.player.getItemsEquipped()) {
if (Items.ELYTRA.equals(stack.getItem())) {
return HANDLER.instance().notFlyingHasElytra;
return INDICATORS_STORAGE_HANDLER.instance().notFlyingHasElytra;
}
}

return HANDLER.instance().notFlyingNoElytra;
return INDICATORS_STORAGE_HANDLER.instance().notFlyingNoElytra;
}

public enum BatchedRendering implements NameableEnum {
NO_BATCHING,
BATCH_PER_COMPONENT,
SINGLE_BATCH;

@Override
public Text getDisplayName() {
return Text.translatable("config.flightassistant.options.batching." + name().toLowerCase(Locale.ROOT));
}
public static ComputerConfig computer() {
return COMPUTER_HANDLER.instance();
}
}
Loading

0 comments on commit 25cb6bd

Please sign in to comment.