From 5d8e1d222a36d286420fbb40a90d1b7415b26f70 Mon Sep 17 00:00:00 2001 From: Markil3 <75867393+Markil3@users.noreply.github.com> Date: Mon, 1 Mar 2021 12:17:33 -0700 Subject: [PATCH] Enables the configuration of timing values, via the cloth API. --- build.gradle | 5 + gradle.properties | 2 + .../markil3/immersive_hud/ConfigManager.java | 386 ++++++++++++++++++ .../markil3/immersive_hud/ConfigScreen.java | 36 ++ .../java/markil3/immersive_hud/EventBus.java | 29 +- src/main/java/markil3/immersive_hud/Main.java | 199 ++++++++- .../markil3/immersive_hud/RenderUtils.java | 39 +- .../markil3/immersive_hud/TimerUtils.java | 310 ++++++++++---- .../assets/immersive_hud/lang/en_us.json | 49 +++ 9 files changed, 927 insertions(+), 128 deletions(-) create mode 100644 src/main/java/markil3/immersive_hud/ConfigManager.java create mode 100644 src/main/java/markil3/immersive_hud/ConfigScreen.java create mode 100644 src/main/resources/assets/immersive_hud/lang/en_us.json diff --git a/build.gradle b/build.gradle index 84dfb8d..2f1dfd7 100644 --- a/build.gradle +++ b/build.gradle @@ -13,6 +13,10 @@ apply plugin: 'net.minecraftforge.gradle' apply plugin: 'eclipse' apply plugin: 'maven-publish' +repositories { + maven { url "https://maven.shedaniel.me/" } +} + archivesBaseName = project.archives_base_name version = project.mod_version + "-" + project.minecraft_version + "-forge" group = project.maven_group // http://maven.apache.org/guides/mini/guide-naming-conventions.html @@ -96,6 +100,7 @@ dependencies { // The userdev artifact is a special name and will get all sorts of transformations applied to it. minecraft "net.minecraftforge:forge:${project.minecraft_version}-${project.forge_version}" + compile(fg.deobf("me.shedaniel.cloth:cloth-config-forge:${project.cloth_version}")) // You may put jars on which you depend on in ./libs or you may define them like so.. // compile "some.group:artifact:version:classifier" // compile "some.group:artifact:version" diff --git a/gradle.properties b/gradle.properties index dae7e30..90fddf3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,6 +8,8 @@ minecraft_version=1.16.4 mappings=20201028-1.16.3 forge_version=35.1.37 +cloth_version=4.11.14 + # Mod Properties mod_version = 0.1 maven_group = markil3 diff --git a/src/main/java/markil3/immersive_hud/ConfigManager.java b/src/main/java/markil3/immersive_hud/ConfigManager.java new file mode 100644 index 0000000..0940652 --- /dev/null +++ b/src/main/java/markil3/immersive_hud/ConfigManager.java @@ -0,0 +1,386 @@ +package markil3.immersive_hud; + +import com.electronwill.nightconfig.core.file.CommentedFileConfig; +import com.electronwill.nightconfig.core.io.WritingMode; + +import net.minecraft.util.math.MathHelper; +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.fml.common.Mod; + +import org.apache.commons.lang3.tuple.Pair; + +import java.nio.file.Path; +import java.nio.file.Paths; + +import static markil3.immersive_hud.Main.TICKS_PER_SECOND; + +/** + * Configuration manager of this mod, which reads from and writes to this mod's + * configuration file. + *

+ * The methods that change this mod's configuration do not automatically write + * those changes to the configuration file on disk. Instead, they only update + * the configuration in memory. To write any changes, use the {@link #save()} + * method. + * + * @author Markil 3 + */ +public class ConfigManager +{ + /** + * The only instance of this class + */ + private static final ConfigManager INSTANCE; + + /** + * The {@link ForgeConfigSpec} instance for this mod's configuration + */ + private static final ForgeConfigSpec SPEC; + + /** + * {@link Path} to the configuration file of this mod + */ + private static final Path CONFIG_PATH = + Paths.get("config", + Main.class.getAnnotation(Mod.class).value() + ".toml"); + + static + { + Pair specPair = + new ForgeConfigSpec.Builder().configure(ConfigManager::new); + INSTANCE = specPair.getLeft(); + SPEC = specPair.getRight(); + CommentedFileConfig config = CommentedFileConfig.builder(CONFIG_PATH) + .sync() + .autoreload() + .writingMode(WritingMode.REPLACE) + .build(); + config.load(); + config.save(); + SPEC.setConfig(config); + } + + public static class TimeValues + { + private static final int SHOW_TIME = 6 * TICKS_PER_SECOND; + private static final int FADE_IN = TICKS_PER_SECOND / 2; + private static final int FADE_OUT = TICKS_PER_SECOND; + + private final String name; + private final ForgeConfigSpec.IntValue maxTime; + private final ForgeConfigSpec.IntValue fadeIn; + private final ForgeConfigSpec.IntValue fadeOut; + + TimeValues(String name, ForgeConfigSpec.Builder configSpecBuilder) + { + final int MAX_TIME = 10 * 60 * TICKS_PER_SECOND; + + this.name = name; + this.maxTime = + configSpecBuilder.translation("immersive_hud.configGui." + name + "Time.title") + .defineInRange(name + "Time", + SHOW_TIME, + 0, + MAX_TIME); + this.fadeIn = + configSpecBuilder.translation("immersive_hud.configGui." + name + "FadeIn.title") + .defineInRange(name + "FadeIn", + FADE_IN, + 0, + MAX_TIME); + this.fadeOut = + configSpecBuilder.translation("immersive_hud.configGui." + name + "FadeOut.title") + .defineInRange(name + "FadeOUT", + FADE_OUT, + 0, + MAX_TIME); + } + + public String getName() + { + return this.name; + } + + /** + * Obtains the maximum time that the hotbar can be on the screen, + * including fading. + * + * @return The maximum hotbar display time. + */ + public int getMaxTime() + { + return this.maxTime.get(); + } + + /** + * Obtains the time that the hotbar takes to fade in. + * + * @return The hotbar fade in time. + */ + public int getFadeInTime() + { + return this.fadeIn.get(); + } + + /** + * Obtains the time that the hotbar takes to fade out. + * + * @return The hotbar fade out time. + */ + public int getFadeOutTime() + { + return this.fadeOut.get(); + } + + public void setMaxTime(int time) + { + this.maxTime.set(time); + } + + public void setFadeInTime(int time) + { + this.fadeIn.set(time); + } + + public void setFadeOutTime(int time) + { + this.fadeOut.set(time); + } + } + + private final TimeValues hotbarTime; + private final TimeValues experienceTime; + private final TimeValues jumpTime; + private final TimeValues healthTime; + private final TimeValues hungerTime; + private final TimeValues effectTime; + private final ForgeConfigSpec.IntValue crosshairTime; + private final ForgeConfigSpec.IntValue handTime; + private final ForgeConfigSpec.BooleanValue showArmor; + private final ForgeConfigSpec.DoubleValue minHealth; + private final ForgeConfigSpec.IntValue minHunger; + + /** + * Implementation of Singleton design pattern, which allows only one + * instance of this class to be created. + */ + private ConfigManager(ForgeConfigSpec.Builder configSpecBuilder) + { + // Comments are not added because there was no way to translate + // descriptions from translate keys here + + this.hotbarTime = new TimeValues("hotbar", configSpecBuilder); + this.experienceTime = new TimeValues("experience", configSpecBuilder); + this.jumpTime = new TimeValues("jump", configSpecBuilder); + this.healthTime = new TimeValues("health", configSpecBuilder); + this.hungerTime = new TimeValues("hunger", configSpecBuilder); + this.effectTime = new TimeValues("effect", configSpecBuilder); + this.crosshairTime = + configSpecBuilder.translation( + "immersive_hud.configGui.crosshairTime.title") + .defineInRange("crosshairTime", + 6 * TICKS_PER_SECOND, + 0, + 10 * 60 * TICKS_PER_SECOND); + this.handTime = + configSpecBuilder.translation( + "immersive_hud.configGui.handTime.title") + .defineInRange("handTime", + 30 * TICKS_PER_SECOND, + 0, + 10 * 60 * TICKS_PER_SECOND); + this.showArmor = configSpecBuilder.translation( + "immersive_hud.configGui.showArmor.title") + .define("showArmor", true); + this.minHealth = configSpecBuilder.translation( + "immersive_hud.configGui.minHealth.title") + .defineInRange("minHealth", 0.5, 0.0, 1.0); + this.minHunger = configSpecBuilder.translation( + "immersive_hud.configGui.minHunger.title") + .defineInRange("minHunger", 17, 0, 20); + } + + /** + * Returns the instance of this class. + * + * @return the instance of this class + */ + public static ConfigManager getInstance() + { + return INSTANCE; + } + + // Validations + + /** + * Obtains time values related to the hotbar. + * + * @return The hotbar display time values. + */ + public TimeValues getHotbarTime() + { + return this.hotbarTime; + } + + /** + * Obtains time values related to the experience bar. + * + * @return The experience bar display time values. + */ + public TimeValues getExperenceTime() + { + return this.experienceTime; + } + + /** + * Obtains time values related to the jump bar. + * + * @return The jump display time values. + */ + public TimeValues getJumpTime() + { + return this.jumpTime; + } + + /** + * Obtains time values related to the health bar. + * + * @return The health display time values. + */ + public TimeValues getHealthTime() + { + return this.healthTime; + } + + /** + * Obtains time values related to the hunger bar. + * + * @return The hunger display time values. + */ + public TimeValues getHungerTime() + { + return this.hungerTime; + } + + /** + * Obtains time values related to potion effects. + * + * @return Potion display time values. + */ + public TimeValues getPotionTime() + { + return this.effectTime; + } + + /** + * Obtains the time that the crosshairs are allowed to display. + * + * @return The crosshair display time values. + */ + public int getCrosshairTime() + { + return this.crosshairTime.get(); + } + + /** + * Obtains the time that the hands are allowed to display. + * + * @return The hand display time values. + */ + public int getHandTime() + { + return this.handTime.get(); + } + + /** + * Checks whether the armor bar should render. + * + * @return Whether or not armor shows on the HUD. + */ + public boolean shouldShowArmor() + { + return this.showArmor.get(); + } + + /** + * Obtains the minimum health for fading. Anything below that and the health + * always displays. + * + * @return The health boundary, from 0 to 1. + */ + public double getMinHealth() + { + return this.minHealth.get(); + } + + /** + * Obtains the minimum hunger for fading. Anything below that and the hunger + * always displays. + * + * @return The hunger boundary, from 0 to 20. + */ + public int getMinHunger() + { + return this.minHunger.get(); + } + + /** + * Sets the time that the hands are allowed to display. + * + * @param time - The hand display time values. + */ + public void setCrosshairTime(int time) + { + this.crosshairTime.set(time); + } + + /** + * Sets the time that the hands are allowed to display. + * + * @param time - The hand display time values. + */ + public void setHandTime(int time) + { + this.handTime.set(time); + } + + /** + * Determines whether the armor bar should render. + * + * @param show - Whether or not armor shows on the HUD. + */ + public void shouldShowArmor(boolean show) + { + this.showArmor.set(show); + } + + /** + * Sets the minimum health for fading. Anything below that and the health + * always displays. + * + * @param boundary - The health boundary, from 0 to 1. + */ + public void setMinHealth(double boundary) + { + this.minHealth.set(MathHelper.clamp(boundary, 0, 1)); + } + + /** + * Sets the minimum hunger for fading. Anything below that and the hunger + * always displays. + * + * @param boundary - The hunger boundary, from 0 to 20. + */ + public void setMinHunger(int boundary) + { + this.minHunger.set(MathHelper.clamp(boundary, 0, 20)); + } + + /** + * Saves changes to this mod's configuration. + */ + public void save() + { + SPEC.save(); + } +} diff --git a/src/main/java/markil3/immersive_hud/ConfigScreen.java b/src/main/java/markil3/immersive_hud/ConfigScreen.java new file mode 100644 index 0000000..de8bc4e --- /dev/null +++ b/src/main/java/markil3/immersive_hud/ConfigScreen.java @@ -0,0 +1,36 @@ +package markil3.immersive_hud; + +import com.mojang.blaze3d.matrix.MatrixStack; + +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TranslationTextComponent; + +public class ConfigScreen extends Screen +{ + /** + * Distance from top of the screen to this GUI's title + */ + private static final int TITLE_HEIGHT = 8; + + protected ConfigScreen() + { + super(new TranslationTextComponent("immersive_hud.configGui.title")); + } + + @Override + public void render(MatrixStack matrixStack, + int mouseX, + int mouseY, + float partialTicks) + { + this.renderBackground(matrixStack); + this.drawCenteredString(matrixStack, + this.font, + this.title.getString(), + this.width / 2, + TITLE_HEIGHT, + 0xFFFFFF); + super.render(matrixStack, mouseX, mouseY, partialTicks); + } +} diff --git a/src/main/java/markil3/immersive_hud/EventBus.java b/src/main/java/markil3/immersive_hud/EventBus.java index c5556ba..3ddcf23 100644 --- a/src/main/java/markil3/immersive_hud/EventBus.java +++ b/src/main/java/markil3/immersive_hud/EventBus.java @@ -33,7 +33,6 @@ import org.apache.logging.log4j.Logger; import java.util.Optional; -import static markil3.immersive_hud.TimerUtils.VISUAL_TIME; import static markil3.immersive_hud.TimerUtils.resetAlpha; /** @@ -107,7 +106,7 @@ public class EventBus @SubscribeEvent public static void onRenderHand(final RenderHandEvent event) { - if (TimerUtils.onRenderHand(event.getHand(), event.getMatrixStack())) + if (TimerUtils.onRenderHand(event.getHand(), event.getMatrixStack(), event.getPartialTicks())) { event.setCanceled(true); } @@ -130,7 +129,7 @@ public class EventBus case CROSSHAIRS: if (event instanceof RenderGameOverlayEvent.Pre) { - if (TimerUtils.drawCrosshair()) + if (TimerUtils.drawCrosshair(event.getPartialTicks())) { event.setCanceled(true); } @@ -150,7 +149,7 @@ public class EventBus event.setCanceled(true); RenderUtils.renderPotionIcons(mc, mc.ingameGUI, - event.getMatrixStack()); + event.getMatrixStack(), event.getPartialTicks()); resetAlpha(); } break; @@ -158,18 +157,18 @@ public class EventBus if (event instanceof RenderGameOverlayEvent.Pre) { event.setCanceled(true); - if (!TimerUtils.drawHotbar()) + if (!TimerUtils.drawHotbar(event.getPartialTicks())) { RenderUtils.renderHotbar(mc, mc.ingameGUI, event.getMatrixStack(), - event.getPartialTicks(), TimerUtils.hotbarTime, VISUAL_TIME); + event.getPartialTicks(), TimerUtils.hotbarTime); } } break; case HEALTH: if (event instanceof RenderGameOverlayEvent.Pre) { - if (TimerUtils.drawHealth(event.getMatrixStack())) + if (TimerUtils.drawHealth(event.getMatrixStack(), event.getPartialTicks())) { event.setCanceled(true); } @@ -183,7 +182,7 @@ public class EventBus case FOOD: if (event instanceof RenderGameOverlayEvent.Pre) { - if (TimerUtils.drawHunger(event.getMatrixStack())) + if (TimerUtils.drawHunger(event.getMatrixStack(), event.getPartialTicks())) { event.setCanceled(true); } @@ -200,7 +199,7 @@ public class EventBus case ARMOR: if (event instanceof RenderGameOverlayEvent.Pre) { - if (TimerUtils.drawArmor(event.getMatrixStack())) + if (TimerUtils.drawArmor(event.getMatrixStack(), event.getPartialTicks())) { event.setCanceled(true); } @@ -217,7 +216,7 @@ public class EventBus case AIR: if (event instanceof RenderGameOverlayEvent.Pre) { - if (TimerUtils.drawAir(event.getMatrixStack())) + if (TimerUtils.drawAir(event.getMatrixStack(), event.getPartialTicks())) { event.setCanceled(true); } @@ -234,7 +233,7 @@ public class EventBus case HEALTHMOUNT: if (event instanceof RenderGameOverlayEvent.Pre) { - if (TimerUtils.drawMountHealth(event.getMatrixStack())) + if (TimerUtils.drawMountHealth(event.getMatrixStack(), event.getPartialTicks())) { event.setCanceled(true); } @@ -249,10 +248,10 @@ public class EventBus if (event instanceof RenderGameOverlayEvent.Pre) { event.setCanceled(true); - if (!TimerUtils.drawJumpbar()) + if (!TimerUtils.drawJumpbar(event.getPartialTicks())) { RenderUtils.renderHorseJumpBar(mc, mc.ingameGUI, - event.getMatrixStack(), TimerUtils.jumpTime, VISUAL_TIME); + event.getMatrixStack(), event.getPartialTicks(), TimerUtils.jumpTime); } } break; @@ -260,10 +259,10 @@ public class EventBus if (event instanceof RenderGameOverlayEvent.Pre) { event.setCanceled(true); - if (!TimerUtils.drawExperience()) + if (!TimerUtils.drawExperience(event.getPartialTicks())) { RenderUtils.renderExperience(mc, mc.ingameGUI, - event.getMatrixStack(), TimerUtils.experienceTime, VISUAL_TIME); + event.getMatrixStack(), event.getPartialTicks(), TimerUtils.experienceTime); } } break; diff --git a/src/main/java/markil3/immersive_hud/Main.java b/src/main/java/markil3/immersive_hud/Main.java index 57ed111..990b00c 100644 --- a/src/main/java/markil3/immersive_hud/Main.java +++ b/src/main/java/markil3/immersive_hud/Main.java @@ -17,15 +17,28 @@ */ package markil3.immersive_hud; +import net.minecraft.util.text.TranslationTextComponent; import net.minecraftforge.fml.ExtensionPoint; +import net.minecraftforge.fml.ModList; import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.config.ModConfig; +import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.fml.network.FMLNetworkConstants; import org.apache.commons.lang3.tuple.Pair; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import me.shedaniel.clothconfig2.api.AbstractConfigListEntry; +import me.shedaniel.clothconfig2.api.ConfigBuilder; +import me.shedaniel.clothconfig2.api.ConfigCategory; +import me.shedaniel.clothconfig2.api.ConfigEntryBuilder; +import me.shedaniel.clothconfig2.gui.entries.DoubleListEntry; +import me.shedaniel.clothconfig2.gui.entries.FloatListEntry; +import me.shedaniel.clothconfig2.gui.entries.IntegerListEntry; + /** * The main entry point for the Immersive HUD mod. * @@ -34,13 +47,20 @@ import org.apache.logging.log4j.Logger; */ @Mod("immersive_hud") public class Main -{ /** +{ + /** * Class logger. */ private static final Logger LOGGER = LogManager.getLogger(); + public static final int TICKS_PER_SECOND = 20; public Main() { + FMLJavaModLoadingContext.get() + .getModEventBus() + .addListener(this::setup); + + setupScreen(); //Make sure the mod being absent on the other network side does not // cause the client to display the server as incompatible ModLoadingContext.get() @@ -49,25 +69,192 @@ public class Main (a, b) -> true)); } + private void startTimeField(ConfigEntryBuilder entryBuilder, + ConfigCategory cat, + ConfigManager.TimeValues value) + { + final float SHOW_TIME = 6; + final float FADE_IN = 0.25F; + final float FADE_OUT = 0.5F; + + DoubleListEntry maxTime = + entryBuilder.startDoubleField(new TranslationTextComponent( + "option.immersive_hud." + value.getName() + + "MaxTime"), + (float) value.getMaxTime() / TICKS_PER_SECOND) + .setDefaultValue(SHOW_TIME) + .setMin(0) + .setMax(10 * 60 * TICKS_PER_SECOND) // 10 Minutes + .setTooltip(new TranslationTextComponent( + "tooltip.immersive_hud." + value.getName() + + "MaxTime")) + .setSaveConsumer(val -> value.setMaxTime((int) (val * TICKS_PER_SECOND))) + .build(); + + DoubleListEntry fadeIn = + entryBuilder.startDoubleField(new TranslationTextComponent( + "option.immersive_hud." + value.getName() + + "FadeIn"), + (float) value.getFadeInTime() / TICKS_PER_SECOND) + .setDefaultValue(FADE_IN).setMin(0).setMax(10 * 60 * TICKS_PER_SECOND) + .setTooltip(new TranslationTextComponent( + "tooltip.immersive_hud." + value.getName() + + "FadeIn")) + .setSaveConsumer(val -> value.setFadeInTime((int) (val * TICKS_PER_SECOND))) + .build(); + + DoubleListEntry fadeOut = + entryBuilder.startDoubleField(new TranslationTextComponent( + "option.immersive_hud." + value.getName() + + "FadeOut"), + (float) value.getFadeOutTime() / TICKS_PER_SECOND) + .setDefaultValue(FADE_OUT) + .setMin(0) + .setMax(10 * 60 * TICKS_PER_SECOND) + .setTooltip(new TranslationTextComponent( + "tooltip.immersive_hud." + value.getName() + + "FadeOut")) + .setSaveConsumer(val -> value.setFadeOutTime((int) (val * TICKS_PER_SECOND))) + .build(); + + cat.addEntry(maxTime); + cat.addEntry(fadeIn); + cat.addEntry(fadeOut); + } + + private void setupScreen() + { + ModLoadingContext.get() + .registerExtensionPoint(ExtensionPoint.CONFIGGUIFACTORY, + () -> (mc, screen) -> { + ConfigCategory general; + ConfigEntryBuilder entryBuilder; + final ConfigBuilder builder = ConfigBuilder.create() + .setParentScreen(screen) + .setTitle(new TranslationTextComponent( + "immersive_hud.configGui.title")) + .setSavingRunnable(() -> { + ConfigManager.getInstance().save(); + }); + general = + builder.getOrCreateCategory(new TranslationTextComponent( + "category.immersive_hud.general")); + entryBuilder = builder.entryBuilder(); + + startTimeField(entryBuilder, + general, + ConfigManager.getInstance() + .getHotbarTime()); + startTimeField(entryBuilder, + general, + ConfigManager.getInstance() + .getExperenceTime()); + startTimeField(entryBuilder, + general, + ConfigManager.getInstance().getJumpTime()); + startTimeField(entryBuilder, + general, + ConfigManager.getInstance() + .getHealthTime()); + startTimeField(entryBuilder, + general, + ConfigManager.getInstance() + .getHungerTime()); + startTimeField(entryBuilder, + general, + ConfigManager.getInstance() + .getPotionTime()); + + general.addEntry(entryBuilder.startDoubleField(new TranslationTextComponent( + "option.immersive_hud" + + ".crosshairTime"), + (float) ConfigManager.getInstance() + .getCrosshairTime() / TICKS_PER_SECOND) + .setDefaultValue(6) + .setTooltip(new TranslationTextComponent( + "tooltip.immersive_hud" + + ".crosshairTime")) + .setSaveConsumer(val -> ConfigManager.getInstance() + .setCrosshairTime((int) (val * TICKS_PER_SECOND))) + .build()); + + general.addEntry(entryBuilder.startDoubleField(new TranslationTextComponent( + "option.immersive_hud.handTime"), + (float) ConfigManager.getInstance() + .getHandTime() / TICKS_PER_SECOND) + .setDefaultValue(30) + .setTooltip(new TranslationTextComponent( + "tooltip.immersive_hud.handTime")) + .setSaveConsumer(val -> ConfigManager.getInstance() + .setHandTime((int) (val * TICKS_PER_SECOND))) + .build()); + + general.addEntry(entryBuilder.startDoubleField(new TranslationTextComponent( + "option.immersive_hud.minHealth"), + ConfigManager.getInstance() + .getMinHealth()) + .setDefaultValue(0.5) + .setTooltip(new TranslationTextComponent( + "tooltip.immersive_hud.minHealth")) + .setSaveConsumer(val -> ConfigManager.getInstance() + .setMinHealth( + val)) + .build()); + + general.addEntry(entryBuilder.startIntField(new TranslationTextComponent( + "option.immersive_hud.minHunger"), + ConfigManager.getInstance() + .getMinHunger()) + .setDefaultValue(17) + .setTooltip(new TranslationTextComponent( + "tooltip.immersive_hud.minHunger")) + .setSaveConsumer(val -> ConfigManager.getInstance() + .setMinHunger( + val)) + .build()); + + general.addEntry(entryBuilder.startBooleanToggle(new TranslationTextComponent( + "option.immersive_hud.showArmor"), + ConfigManager.getInstance() + .shouldShowArmor()) + .setDefaultValue(true) + .setTooltip(new TranslationTextComponent( + "tooltip.immersive_hud.showArmor")) + .setSaveConsumer(val -> ConfigManager.getInstance() + .shouldShowArmor( + val)) + .build()); + + return builder.build(); + }); + } + + private void setup(final FMLClientSetupEvent event) + { + } + /** * A utility method to handle the transparency timing. It will (for the most * part), make * - * @param renderTime - How many ticks until the element entirely + * @param renderTime - How many seconds until the element entirely * disappears. - * @param maxTime - How many ticks the element can appear. + * @param maxTime - How many seconds the element can appear. * * @return The proper transparency to render something. */ - static float getAlpha(int renderTime, int maxTime, int fadeInTime, int fadeOutTime) + static float getAlpha(double renderTime, + double maxTime, + double fadeInTime, + double fadeOutTime) { if (renderTime <= fadeOutTime) { - return renderTime / (float) fadeOutTime; + return (float) (renderTime / fadeOutTime); } else if (renderTime > maxTime - fadeInTime) { - return (maxTime - renderTime) / (float) fadeInTime; + return (float) ((maxTime - renderTime) / fadeInTime); } return 1F; } diff --git a/src/main/java/markil3/immersive_hud/RenderUtils.java b/src/main/java/markil3/immersive_hud/RenderUtils.java index 5e4fde7..66ec060 100644 --- a/src/main/java/markil3/immersive_hud/RenderUtils.java +++ b/src/main/java/markil3/immersive_hud/RenderUtils.java @@ -49,9 +49,6 @@ import net.minecraft.world.World; import java.util.Collection; import java.util.List; -import static markil3.immersive_hud.TimerUtils.FADE_IN_TIME; -import static markil3.immersive_hud.TimerUtils.FADE_OUT_TIME; - /** * Contains methods for rendering various HUD elements. Most of these methods * come from {@link IngameGui} and @@ -64,8 +61,8 @@ import static markil3.immersive_hud.TimerUtils.FADE_OUT_TIME; public class RenderUtils { public static void renderPotionIcons(Minecraft mc, - IngameGui gui, - MatrixStack matrixStack) + IngameGui gui, + MatrixStack matrixStack, float ticks) { int scaledWidth = mc.getMainWindow().getScaledWidth(); int scaledHeight = mc.getMainWindow().getScaledHeight(); @@ -89,7 +86,7 @@ public class RenderUtils .sortedCopy(collection)) { Effect effect = effectinstance.getPotion(); - float effectAlpha = TimerUtils.getPotionAlpha(mc.player, effectinstance); + float effectAlpha = TimerUtils.getPotionAlpha(mc.player, effectinstance, ticks); if (!effectinstance.shouldRenderHUD() || effectAlpha < 0.01F) { continue; @@ -165,6 +162,7 @@ public class RenderUtils * @param mc - A Minecraft instance. * @param gui - The GUI. * @param matrixStack - The rendering transformation matrix stack. + * @param ticks * @param renderTime - How much time before this element becomes fully * transparent. * @@ -173,14 +171,15 @@ public class RenderUtils public static void renderHorseJumpBar(Minecraft mc, IngameGui gui, MatrixStack matrixStack, - int renderTime, int maxRenderTime) + float ticks, double renderTime) { - if (renderTime == 0) + ConfigManager.TimeValues jump = ConfigManager.getInstance().getJumpTime(); + if (renderTime <= 0) { return; } - float alpha = Main.getAlpha(renderTime, maxRenderTime, FADE_IN_TIME, FADE_OUT_TIME); + float alpha = Main.getAlpha(renderTime, jump.getMaxTime(), jump.getFadeInTime(), jump.getFadeOutTime()); int scaledWidth = mc.getMainWindow().getScaledWidth(); int scaledHeight = mc.getMainWindow().getScaledHeight(); int xPosition = scaledWidth / 2 - 91; @@ -210,6 +209,7 @@ public class RenderUtils * @param mc - A Minecraft instance. * @param gui - The GUI. * @param matrixStack - The rendering transformation matrix stack. + * @param ticks * @param renderTime - How much time before this element becomes fully * transparent. * @@ -218,14 +218,16 @@ public class RenderUtils public static void renderExperience(Minecraft mc, IngameGui gui, MatrixStack matrixStack, - int renderTime, int maxRenderTime) + float ticks, double renderTime) { - if (renderTime == 0) + ConfigManager.TimeValues experience = ConfigManager.getInstance().getHealthTime(); + ConfigManager.TimeValues hotbar = ConfigManager.getInstance().getHotbarTime(); + if (renderTime <= 0) { return; } - float alpha = Main.getAlpha(renderTime, maxRenderTime, FADE_IN_TIME, FADE_OUT_TIME); + float alpha = Main.getAlpha(renderTime, experience.getMaxTime(), experience.getFadeInTime(), experience.getFadeOutTime()); RenderSystem.color4f(1.0F, 1.0F, 1.0F, alpha); if (mc.playerController.gameIsSurvivalOrAdventure()) @@ -259,7 +261,7 @@ public class RenderUtils String s = "" + mc.player.experienceLevel; int i1 = (scaledWidth - gui.getFontRenderer() .getStringWidth(s)) / 2; - int j1 = scaledHeight - (int) ((22F * Main.getAlpha(TimerUtils.hotbarTime, maxRenderTime, FADE_IN_TIME, FADE_OUT_TIME) + 9F) * alpha) - (int) (4F * alpha); + int j1 = scaledHeight - (int) ((22F * Main.getAlpha(TimerUtils.hotbarTime, hotbar.getMaxTime(), hotbar.getFadeInTime(), hotbar.getFadeOutTime()) + 9F) * alpha) - (int) (4F * alpha); gui.getFontRenderer() .drawString(matrixStack, s, @@ -310,20 +312,23 @@ public class RenderUtils * * @see IngameGui#renderHotbar(float, MatrixStack) */ - public static void renderHotbar(Minecraft mc, IngameGui gui, + public static void renderHotbar(Minecraft mc, + IngameGui gui, MatrixStack matrixStack, - float partialTicks, int renderTime, int maxRenderTime) + float partialTicks, + double renderTime) { + ConfigManager.TimeValues hotbar = ConfigManager.getInstance().getHotbarTime(); final ResourceLocation WIDGETS_TEX_PATH = new ResourceLocation("textures/gui/widgets.png"); PlayerEntity playerentity = mc.player; - if (renderTime == 0) + if (renderTime <= 0) { return; } - float alpha = Main.getAlpha(renderTime, maxRenderTime, FADE_IN_TIME, FADE_OUT_TIME); + float alpha = Main.getAlpha(renderTime, hotbar.getMaxTime(), hotbar.getFadeInTime(), hotbar.getFadeOutTime()); int scaledWidth = mc.getMainWindow().getScaledWidth(); int scaledHeight = mc.getMainWindow().getScaledHeight(); diff --git a/src/main/java/markil3/immersive_hud/TimerUtils.java b/src/main/java/markil3/immersive_hud/TimerUtils.java index f66c87a..c8305a6 100644 --- a/src/main/java/markil3/immersive_hud/TimerUtils.java +++ b/src/main/java/markil3/immersive_hud/TimerUtils.java @@ -24,6 +24,7 @@ import net.minecraft.potion.Effect; import net.minecraft.potion.EffectInstance; import net.minecraft.potion.Effects; import net.minecraft.util.Hand; +import net.minecraft.util.Util; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.RayTraceResult; @@ -34,35 +35,37 @@ import java.util.Optional; public class TimerUtils { - /** - * The number of ticks that the hand will be onscreen. Every tick is 1/20th - * of a second. - */ - private static final int HAND_TIME = 10 * 20; - /** - * The number of ticks most elements will be onscreen. Every tick is 1/20th - * of a second. - */ - static final int VISUAL_TIME = 6 * 20; - /** - * The number of ticks that the health and hunger bars will be onscreen. - * Every tick is 1/20th of a second. - */ - private static final int HEALTH_TIME = (int) ((float) VISUAL_TIME * 2.5); - public static final int FADE_IN_TIME = 5; - public static final int FADE_OUT_TIME = 20; +// /** +// * The number of ticks that the hand will be onscreen. Every tick is +// 1/20th +// * of a second. +// */ +// private static final int HAND_TIME = 10 * 20; +// /** +// * The number of ticks most elements will be onscreen. Every tick is +// 1/20th +// * of a second. +// */ +// static final int VISUAL_TIME = 6 * 20; +// /** +// * The number of ticks that the health and hunger bars will be onscreen. +// * Every tick is 1/20th of a second. +// */ +// private static final int HEALTH_TIME = (int) ((float) VISUAL_TIME * 2.5); +// public static final int FADE_IN_TIME = 5; +// public static final int FADE_OUT_TIME = 20; /** * How many more ticks the hand will be onscreen. Every tick is 1/20th of a * second. */ - private static int mainHandTime, offHandTime; + private static double mainHandTime, offHandTime; /** * How many more ticks the crosshair will be onscreen. Every tick is 1/20th * of a second. */ - private static int crosshairTime; + private static double crosshairTime; /** * If true, then the hand (and crosshairs) will be locked onto the screen * without disappearing until this flag is updated. @@ -75,13 +78,13 @@ public class TimerUtils */ private static int mapLock; - private static HashMap effectTime = new HashMap<>(); + private static HashMap effectTime = new HashMap<>(); /** * How many more ticks the hotbar will be onscreen. Every tick is 1/20th of * a second. */ - static int hotbarTime; + static double hotbarTime; /** * The last hotbar slot that was selected. This is used to check for a * change in the hotbar slot. @@ -97,7 +100,7 @@ public class TimerUtils * How many more ticks the health bar will be onscreen. Every tick is 1/20th * of a second. */ - private static int healthTime; + private static double healthTime; /** * Records what the health was previously. Used to check for a change in the * health. @@ -115,7 +118,7 @@ public class TimerUtils * How many more ticks the hunger bar will be onscreen. Every tick is 1/20th * of a second. */ - private static int hungerTime; + private static double hungerTime; /** * Records what the hunger level was previously. Used to check for a change * in hunger. @@ -131,7 +134,7 @@ public class TimerUtils * How many more ticks the mount's health bar will be onscreen. Every tick * is 1/20th of a second. */ - private static int mountTime; + private static double mountTime; /** * Records what the health of the mount was previously. Used to check for a * change in the health. @@ -147,13 +150,13 @@ public class TimerUtils * How many more ticks the mount's jump bar will be onscreen. Every tick is * 1/20th of a second. */ - static int jumpTime; + static double jumpTime; /** * How many more ticks the experience bar will be onscreen. Every tick is * 1/20th of a second. */ - static int experienceTime; + static double experienceTime; /** * Records what the experience was previously. Used to check for a change in * the health. @@ -188,7 +191,12 @@ public class TimerUtils */ public static int getHotbarTranslation() { - return (int) (22F * Main.getAlpha(hotbarTime, VISUAL_TIME, FADE_IN_TIME, FADE_OUT_TIME)); + ConfigManager.TimeValues hotbar = + ConfigManager.getInstance().getHotbarTime(); + return (int) (22F * Main.getAlpha(hotbarTime, + hotbar.getMaxTime(), + hotbar.getFadeInTime(), + hotbar.getFadeOutTime())); } @@ -200,8 +208,13 @@ public class TimerUtils */ public static int getExperienceTranslation() { + ConfigManager.TimeValues experience = + ConfigManager.getInstance().getExperenceTime(); return (int) ((getHotbarTranslation() + 10F) * Main.getAlpha( - experienceTime, VISUAL_TIME, FADE_IN_TIME, FADE_OUT_TIME)) - 3; + experienceTime, + experience.getMaxTime(), + experience.getFadeInTime(), + experience.getFadeOutTime())) - 3; } @@ -213,7 +226,12 @@ public class TimerUtils */ public static int getJumpTranslation() { - return (int) ((getHotbarTranslation() + 10F) * Main.getAlpha(jumpTime, VISUAL_TIME, FADE_IN_TIME, FADE_OUT_TIME)) - 3; + ConfigManager.TimeValues jump = + ConfigManager.getInstance().getJumpTime(); + return (int) ((getHotbarTranslation() + 10F) * Main.getAlpha(jumpTime, + jump.getMaxTime(), + jump.getFadeInTime(), + jump.getFadeOutTime())) - 3; } @@ -231,21 +249,32 @@ public class TimerUtils public static void onClick(Hand hand, Item item) { - crosshairTime = VISUAL_TIME; + ConfigManager.TimeValues health = + ConfigManager.getInstance().getHealthTime(); + ConfigManager.TimeValues hunger = + ConfigManager.getInstance().getHungerTime(); + double handTime = ConfigManager.getInstance().getHandTime(); + + crosshairTime = ConfigManager.getInstance().getCrosshairTime(); + if (hand == Hand.MAIN_HAND) { - mainHandTime = HAND_TIME; + mainHandTime = handTime; } else { - offHandTime = HAND_TIME; + offHandTime = handTime; } if (item != null) { if (item.isFood()) { - healthTime = HEALTH_TIME; - hungerTime = HEALTH_TIME; + healthTime = health.getMaxTime() - (healthTime > 0 ? + health.getFadeInTime() : + 0); + hungerTime = hunger.getMaxTime() - (hungerTime > 0 ? + hunger.getFadeInTime() : + 0); } } } @@ -256,14 +285,17 @@ public class TimerUtils * * @param hand - The hand being rendered. * @param matrixStack - The rendering stack. + * @param ticks * * @return If true, then don't render this hand at all. * * @since 0.2-1.16.4-forge */ - public static boolean onRenderHand(Hand hand, MatrixStack matrixStack) + public static boolean onRenderHand(Hand hand, + MatrixStack matrixStack, + float ticks) { - final int HAND_UP_TIME = 20; + float HAND_UP_TIME = 1F; switch (hand) { @@ -284,7 +316,10 @@ public class TimerUtils } else if (!offHandLock && (mapLock & 0b01) == 0) { - offHandTime--; + if (offHandTime > 0) + { + offHandTime -= ticks; + } if (offHandTime < HAND_UP_TIME) { matrixStack @@ -301,7 +336,10 @@ public class TimerUtils } else if (!mainHandLock && (mapLock & 0b10) == 0) { - mainHandTime--; + if (mainHandTime > 0) + { + mainHandTime -= ticks; + } if (mainHandTime < HAND_UP_TIME) { matrixStack @@ -320,7 +358,11 @@ public class TimerUtils */ public static void resetMountHealth() { - mountTime = VISUAL_TIME; + ConfigManager.TimeValues health = + ConfigManager.getInstance().getHealthTime(); + mountTime = health.getMaxTime() - (mountTime > 0 ? + health.getFadeInTime() : + 0); jumpTime = 0; } @@ -328,12 +370,16 @@ public class TimerUtils * Determines whether or not to draw the crosshair, adjusting the alpha as * needed. * + * @param ticks + * * @return If true, then cancel drawing the crosshair. * * @since 0.2-1.16.4-forge */ - public static boolean drawCrosshair() + public static boolean drawCrosshair(float ticks) { + double CROSSHAIR_TIME = ConfigManager.getInstance().getCrosshairTime(); + Minecraft mc = Minecraft.getInstance(); boolean changed = false; boolean canceled = false; @@ -357,7 +403,7 @@ public class TimerUtils { setAlpha(Main.getAlpha(crosshairTime > 0 ? crosshairTime : - VISUAL_TIME, VISUAL_TIME, 0, 0)); + CROSSHAIR_TIME, CROSSHAIR_TIME, 0, 0)); } else { @@ -365,7 +411,7 @@ public class TimerUtils } if (crosshairTime > 0) { - crosshairTime--; + crosshairTime -= ticks; } return canceled; @@ -403,33 +449,40 @@ public class TimerUtils * @return */ public static float getPotionAlpha(ClientPlayerEntity player, - EffectInstance effectinstance) + EffectInstance effectinstance, + float ticks) { + ConfigManager.TimeValues potion = + ConfigManager.getInstance().getPotionTime(); final int BLINK_TIME = 200; float effectAlpha = 0.0F; - Integer time = effectTime.get(effectinstance.getPotion()); + Double time = effectTime.get(effectinstance.getPotion()); if (time == null) { - effectTime.put(effectinstance.getPotion(), (time = VISUAL_TIME)); + effectTime.put(effectinstance.getPotion(), + (time = (double) potion.getMaxTime())); } else { - effectTime.put(effectinstance.getPotion(), (time -= 1)); + effectTime.put(effectinstance.getPotion(), (time -= ticks)); } - if (effectinstance.getDuration() <= BLINK_TIME) + if (effectinstance.getDuration() <= potion.getFadeOutTime()) { effectAlpha = MathHelper.sin(7000F / (effectinstance.getDuration() + 16F * (float) Math.PI)) * 50F / (effectinstance .getDuration() + 100F) + 0.5F; } - else if (effectinstance.getDuration() <= BLINK_TIME + 10) + else if (effectinstance.getDuration() <= potion.getFadeOutTime() + 10) { effectAlpha = -(effectinstance.getDuration() - 200) / 22F + 0.454F; } else { - effectAlpha = Main.getAlpha(time, VISUAL_TIME, FADE_IN_TIME, FADE_OUT_TIME); + effectAlpha = Main.getAlpha(time, + potion.getMaxTime(), + potion.getFadeInTime(), + potion.getFadeOutTime()); } return effectAlpha; } @@ -440,11 +493,17 @@ public class TimerUtils * * @return If true, then there have been changes in the hotbar. * - * @see #drawHotbar() + * @see #drawHotbar(float) * @since 0.2-1.16.4-forge */ private static boolean updateHotbar() { + ConfigManager.TimeValues health = + ConfigManager.getInstance().getHealthTime(); + ConfigManager.TimeValues hunger = + ConfigManager.getInstance().getHungerTime(); + double handTime = ConfigManager.getInstance().getHandTime(); + Minecraft mc = Minecraft.getInstance(); Item item, handItem; boolean changed = false; @@ -586,18 +645,22 @@ public class TimerUtils */ if (item.isFood()) { - healthTime = HEALTH_TIME; - hungerTime = HEALTH_TIME; + healthTime = health.getMaxTime() - (healthTime > 0 ? + health.getFadeInTime() : + 0); + hungerTime = hunger.getMaxTime() - (hungerTime > 0 ? + hunger.getFadeInTime() : + 0); } if (i == 0) { mainHandItem = item; - mainHandTime = HAND_TIME; + mainHandTime = handTime; } else if (i == 1) { offHandItem = item; - offHandTime = HAND_TIME; + offHandTime = handTime; } } } @@ -612,8 +675,11 @@ public class TimerUtils * * @since 0.2-1.16.4-forge */ - public static boolean drawHotbar() + public static boolean drawHotbar(float ticks) { + ConfigManager.TimeValues hotbar = + ConfigManager.getInstance().getHotbarTime(); + double handTime = ConfigManager.getInstance().getHandTime(); Minecraft mc = Minecraft.getInstance(); int hotbarSlot; @@ -625,17 +691,19 @@ public class TimerUtils if (selectedHotbarSlot != hotbarSlot) { selectedHotbarSlot = hotbarSlot; - mainHandTime = HAND_TIME; + mainHandTime = handTime; changed = true; } if (changed) { - hotbarTime = VISUAL_TIME - (hotbarTime > 0 ? FADE_IN_TIME : 0); + hotbarTime = hotbar.getMaxTime() - (hotbarTime > 0 ? + hotbar.getFadeInTime() : + 0); } else if (hotbarTime > 0) { - hotbarTime--; + hotbarTime -= ticks; } return hotbarTime == 0; @@ -649,14 +717,17 @@ public class TimerUtils * * @since 0.2-1.16.4-forge */ - public static boolean drawHealth(MatrixStack stack) + public static boolean drawHealth(MatrixStack stack, float ticks) { /* * When the health percentage falls to this level or below, the * health bar won't disappear, allowing the player to be constantly * reminded of their low health. */ - final float HEALTH_BOUNDARY = 0.5F; + final double HEALTH_BOUNDARY = + ConfigManager.getInstance().getMinHealth(); + ConfigManager.TimeValues healthTimes = + ConfigManager.getInstance().getHealthTime(); Minecraft mc = Minecraft.getInstance(); boolean changed = false; @@ -675,11 +746,13 @@ public class TimerUtils } if (changed) { - healthTime = HEALTH_TIME - (healthTime > 0 ? FADE_IN_TIME : 0); + healthTime = healthTimes.getMaxTime() - (healthTime > 0 ? + healthTimes.getFadeInTime() : + 0); } else if (healthTime > 0) { - healthTime--; + healthTime -= ticks; } /* * Only makes a change if the player is healthy. Otherwise, @@ -693,7 +766,10 @@ public class TimerUtils stack.translate(0F, getHealthTranslation(), 0F); - setAlpha(Main.getAlpha(healthTime, HEALTH_TIME, FADE_IN_TIME, FADE_OUT_TIME)); + setAlpha(Main.getAlpha(healthTime, + healthTimes.getMaxTime(), + healthTimes.getFadeInTime(), + healthTimes.getFadeOutTime())); return false; } return true; @@ -713,14 +789,16 @@ public class TimerUtils * * @since 0.2-1.16.4-forge */ - public static boolean drawHunger(MatrixStack stack) + public static boolean drawHunger(MatrixStack stack, float ticks) { /* * When hunger falls to this level or below, the hunger bar won't * disappear, allowing the player to be constantly reminded of their * low hunger. */ - final int HUNGER_BOUNDARY = 15; + final int HUNGER_BOUNDARY = ConfigManager.getInstance().getMinHunger(); + ConfigManager.TimeValues hungerTimes = + ConfigManager.getInstance().getHungerTime(); Minecraft mc = Minecraft.getInstance(); boolean changed = false; @@ -738,23 +816,28 @@ public class TimerUtils if (changed || hunger <= HUNGER_BOUNDARY) { - hungerTime = HEALTH_TIME - hungerTime == 0 ? FADE_IN_TIME : 0; + hungerTime = hungerTimes.getMaxTime() - (hungerTime > 0 ? + hungerTimes.getFadeInTime() : + 0); } else if (hungerTime > 0) { - hungerTime--; + hungerTime -= ticks; } /* * Only fade a change if the player is satisfied. Otherwise, * the bar is shown. */ - if (hungerTime == 0 && hunger > HUNGER_BOUNDARY) + if (hungerTime <= 0 && hunger > HUNGER_BOUNDARY) { return true; } else { - setAlpha(Main.getAlpha(hungerTime, HEALTH_TIME, FADE_IN_TIME, FADE_OUT_TIME)); + setAlpha(Main.getAlpha(hungerTime, + hungerTimes.getMaxTime(), + hungerTimes.getFadeInTime(), + hungerTimes.getFadeOutTime())); stack.push(); stack.translate(0F, getHealthTranslation(), @@ -768,19 +851,25 @@ public class TimerUtils * needed. * * @param stack + * @param ticks * * @return If true, then cancel drawing the armor bar. * * @since 0.2-1.16.4-forge */ - public static boolean drawArmor(MatrixStack stack) + public static boolean drawArmor(MatrixStack stack, float ticks) { + ConfigManager.TimeValues healthTimes; /* * Renders armor along with health. */ - if (healthTime > 0) + if (ConfigManager.getInstance().shouldShowArmor() && healthTime > 0) { - setAlpha(Main.getAlpha(healthTime, HEALTH_TIME, FADE_IN_TIME, FADE_OUT_TIME)); + healthTimes = ConfigManager.getInstance().getHealthTime(); + setAlpha(Main.getAlpha(healthTime, + healthTimes.getMaxTime(), + healthTimes.getFadeInTime(), + healthTimes.getFadeOutTime())); stack.push(); stack.translate(0F, getHealthTranslation(), @@ -794,12 +883,13 @@ public class TimerUtils * Repositions the oxygen bar. * * @param stack + * @param ticks * * @return If true, then cancel drawing the oxygen bar. * * @since 0.2-1.16.4-forge */ - public static boolean drawAir(MatrixStack stack) + public static boolean drawAir(MatrixStack stack, float ticks) { stack.push(); stack.translate(0F, @@ -813,13 +903,24 @@ public class TimerUtils * as needed. * * @param stack + * @param ticks * * @return If true, then cancel drawing the mount health bar. * * @since 0.2-1.16.4-forge */ - public static boolean drawMountHealth(MatrixStack stack) + public static boolean drawMountHealth(MatrixStack stack, float ticks) { + /* + * When the health percentage falls to this level or below, the + * health bar won't disappear, allowing the player to be constantly + * reminded of their low health. + */ + final double HEALTH_BOUNDARY = + ConfigManager.getInstance().getMinHealth(); + + ConfigManager.TimeValues healthTimes = + ConfigManager.getInstance().getHealthTime(); Minecraft mc = Minecraft.getInstance(); Entity tmp = mc.player.getRidingEntity(); boolean changed = false; @@ -846,43 +947,66 @@ public class TimerUtils if (changed) { - mountTime = VISUAL_TIME - (mountTime > 0 ? FADE_IN_TIME : 0); + mountTime = healthTimes.getMaxTime() - (mountTime > 0 ? + healthTimes.getFadeInTime() : + 0); } else if (mountTime > 0) { - mountTime--; + mountTime -= ticks; } - if (mountTime > 0) + /* + * Only makes a change if the player is healthy. Otherwise, + * the bar is shown. + */ + if (mountHealth / mountMaxHealth > HEALTH_BOUNDARY) { - stack.push(); - stack.translate(0F, - getHealthTranslation(), - 0F); - setAlpha(Main.getAlpha(mountTime, VISUAL_TIME, FADE_IN_TIME, FADE_OUT_TIME)); - return false; + if (mountTime > 0) + { + stack.push(); + stack.translate(0F, + getHealthTranslation(), + 0F); + setAlpha(Main.getAlpha(mountTime, + healthTimes.getMaxTime(), + healthTimes.getFadeInTime(), + healthTimes.getFadeOutTime())); + return false; + } + return true; } - return true; + stack.push(); + stack.translate(0F, + getHealthTranslation(), + 0F); + return false; } /** * Determines whether or not to draw the horse jump bar, adjusting the alpha * as needed. * + * @param ticks + * * @return If true, then cancel drawing the jump bar. * * @since 0.2-1.16.4-forge */ - public static boolean drawJumpbar() + public static boolean drawJumpbar(float ticks) { + ConfigManager.TimeValues jump = + ConfigManager.getInstance().getJumpTime(); Minecraft mc = Minecraft.getInstance(); if (mc.player.getHorseJumpPower() > 0) { - jumpTime = VISUAL_TIME - (jumpTime > 0 ? FADE_IN_TIME : 0); + jumpTime = jump.getMaxTime() - (jumpTime > 0 ? + jump.getFadeInTime() : + 0); } else if (jumpTime > 0) { - jumpTime--; + jumpTime -= ticks; } return jumpTime == 0; } @@ -891,12 +1015,16 @@ public class TimerUtils * Determines whether or not to draw the experience bar, adjusting the alpha * as needed. * + * @param ticks + * * @return If true, then cancel drawing the experience bar. * * @since 0.2-1.16.4-forge */ - public static boolean drawExperience() + public static boolean drawExperience(float ticks) { + ConfigManager.TimeValues experience = + ConfigManager.getInstance().getExperenceTime(); Minecraft mc = Minecraft.getInstance(); boolean changed = false; @@ -907,11 +1035,13 @@ public class TimerUtils } if (changed) { - experienceTime = VISUAL_TIME - (experienceTime > 0 ? FADE_IN_TIME : 0); + experienceTime = experience.getMaxTime() - (experienceTime > 0 ? + experience.getFadeInTime() : + 0); } else if (experienceTime > 0) { - experienceTime--; + experienceTime -= ticks; } return experienceProgress == 0; } diff --git a/src/main/resources/assets/immersive_hud/lang/en_us.json b/src/main/resources/assets/immersive_hud/lang/en_us.json new file mode 100644 index 0000000..86e1475 --- /dev/null +++ b/src/main/resources/assets/immersive_hud/lang/en_us.json @@ -0,0 +1,49 @@ +{ + "immersive_hud.configGui.title": "Immersive HUD Configuration", + "option.immersive_hud.hotbarMaxTime": "Hotbar Display Time", + "option.immersive_hud.hotbarFadeIn": "Hotbar Fade In Time", + "option.immersive_hud.hotbarFadeOut": "Hotbar Fade Out Time", + "option.immersive_hud.experienceMaxTime": "Experience Display Time", + "option.immersive_hud.experienceFadeIn": "Experience Fade In Time", + "option.immersive_hud.experienceFadeOut": "Experience Fade Out Time", + "option.immersive_hud.jumpMaxTime": "Jump Bar Display Time", + "option.immersive_hud.jumpFadeIn": "Jump Bar Fade In Time", + "option.immersive_hud.jumpFadeOut": "Jump Bar Fade Out Time", + "option.immersive_hud.healthMaxTime": "Health Bar Display Time", + "option.immersive_hud.healthFadeIn": "Health Bar Fade In Time", + "option.immersive_hud.healthFadeOut": "Health Bar Fade Out Time", + "option.immersive_hud.hungerMaxTime": "Hunger Bar Display Time", + "option.immersive_hud.hungerFadeIn": "Hunger Bar Fade In Time", + "option.immersive_hud.hungerFadeOut": "Hunger Bar Fade Out Time", + "option.immersive_hud.effectMaxTime": "Potion Display Time", + "option.immersive_hud.effectFadeIn": "Potion Fade In Time", + "option.immersive_hud.effectFadeOut": "Potion Fade Out Time", + "option.immersive_hud.crosshairTime": "Crosshair Display Time", + "option.immersive_hud.handTime": "Hand Display Time", + "option.immersive_hud.minHealth": "Minimum Health Fade", + "option.immersive_hud.minHunger": "Minimum Hunger Fade", + "option.immersive_hud.showArmor": "Show Armor", + "tooltip.immersive_hud.hotbarMaxTime": "How long the hotbar can be displayed on screen in seconds", + "tooltip.immersive_hud.hotbarFadeIn": "How many seconds it takes for the hotbar to fade in", + "tooltip.immersive_hud.hotbarFadeOut": "How many seconds it takes for the hotbar to move out", + "tooltip.immersive_hud.experienceMaxTime": "How long the experience bar can be displayed on screen in seconds", + "tooltip.immersive_hud.experienceFadeIn": "How many seconds it takes for the experience bar to fade in", + "tooltip.immersive_hud.experienceFadeOut": "How many seconds it takes for the experience bar to move out", + "tooltip.immersive_hud.jumpMaxTime": "How long the horse jump bar can be displayed on screen in seconds", + "tooltip.immersive_hud.jumpFadeIn": "How many seconds it takes for the horse jump bar to fade in", + "tooltip.immersive_hud.jumpFadeOut": "How many seconds it takes for the horse jump bar to fade out", + "tooltip.immersive_hud.healthMaxTime": "How long the health bar can be displayed on screen in seconds", + "tooltip.immersive_hud.healthFadeIn": "How many seconds it takes for the health bar to fade in", + "tooltip.immersive_hud.healthFadeOut": "How many seconds it takes for the health bar to fade out", + "tooltip.immersive_hud.hungerMaxTime": "How long the hunger bar can be displayed on screen in seconds", + "tooltip.immersive_hud.hungerFadeIn": "How many seconds it takes for the hunger bar to fade in", + "tooltip.immersive_hud.hungerFadeOut": "How many seconds it takes for the hunger bar to fade out", + "tooltip.immersive_hud.effectMaxTime": "How long potion icons can be displayed on screen in seconds", + "tooltip.immersive_hud.effectFadeIn": "How many seconds it takes for potion icons to fade in", + "tooltip.immersive_hud.effectFadeOut": "How many seconds it takes for potion icons to fade out", + "tooltip.immersive_hud.crosshairTime": "How many seconds the crosshairs can be on screen", + "tooltip.immersive_hud.handTime": "How many seconds the hands can be on screen", + "tooltip.immersive_hud.minHealth": "When the percentage of health goes below this level, the health bar won't fade away", + "tooltip.immersive_hud.minHunger": "When the hunger level goes below this level, the hunger bar won't fade away", + "tooltip.immersive_hud.showArmor": "Whether or not the armor bar should display on the HUD" +} \ No newline at end of file