diff --git a/src/main/java/markil3/immersive_hud/Main.java b/src/main/java/markil3/immersive_hud/Main.java index e2ba331..57ed111 100644 --- a/src/main/java/markil3/immersive_hud/Main.java +++ b/src/main/java/markil3/immersive_hud/Main.java @@ -34,10 +34,7 @@ import org.apache.logging.log4j.Logger; */ @Mod("immersive_hud") public class Main -{ - public static final int FADE_IN_TIME = 5; - public static final int FADE_OUT_TIME = 20; - /** +{ /** * Class logger. */ private static final Logger LOGGER = LogManager.getLogger(); @@ -62,15 +59,15 @@ public class Main * * @return The proper transparency to render something. */ - static float getAlpha(int renderTime, int maxTime) + static float getAlpha(int renderTime, int maxTime, int fadeInTime, int fadeOutTime) { - if (renderTime <= FADE_OUT_TIME) + if (renderTime <= fadeOutTime) { - return renderTime / (float) FADE_OUT_TIME; + return renderTime / (float) fadeOutTime; } - else if (renderTime > maxTime - FADE_IN_TIME) + else if (renderTime > maxTime - fadeInTime) { - return (maxTime - renderTime) / (float) FADE_IN_TIME; + return (maxTime - renderTime) / (float) fadeInTime; } return 1F; } diff --git a/src/main/java/markil3/immersive_hud/RenderUtils.java b/src/main/java/markil3/immersive_hud/RenderUtils.java index d14632f..5e4fde7 100644 --- a/src/main/java/markil3/immersive_hud/RenderUtils.java +++ b/src/main/java/markil3/immersive_hud/RenderUtils.java @@ -49,6 +49,9 @@ 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 @@ -177,7 +180,7 @@ public class RenderUtils return; } - float alpha = Main.getAlpha(renderTime, maxRenderTime); + float alpha = Main.getAlpha(renderTime, maxRenderTime, FADE_IN_TIME, FADE_OUT_TIME); int scaledWidth = mc.getMainWindow().getScaledWidth(); int scaledHeight = mc.getMainWindow().getScaledHeight(); int xPosition = scaledWidth / 2 - 91; @@ -222,7 +225,7 @@ public class RenderUtils return; } - float alpha = Main.getAlpha(renderTime, maxRenderTime); + float alpha = Main.getAlpha(renderTime, maxRenderTime, FADE_IN_TIME, FADE_OUT_TIME); RenderSystem.color4f(1.0F, 1.0F, 1.0F, alpha); if (mc.playerController.gameIsSurvivalOrAdventure()) @@ -256,7 +259,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) + 9F) * alpha) - (int) (4F * alpha); + int j1 = scaledHeight - (int) ((22F * Main.getAlpha(TimerUtils.hotbarTime, maxRenderTime, FADE_IN_TIME, FADE_OUT_TIME) + 9F) * alpha) - (int) (4F * alpha); gui.getFontRenderer() .drawString(matrixStack, s, @@ -320,7 +323,7 @@ public class RenderUtils return; } - float alpha = Main.getAlpha(renderTime, maxRenderTime); + float alpha = Main.getAlpha(renderTime, maxRenderTime, FADE_IN_TIME, FADE_OUT_TIME); 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 2341292..f66c87a 100644 --- a/src/main/java/markil3/immersive_hud/TimerUtils.java +++ b/src/main/java/markil3/immersive_hud/TimerUtils.java @@ -32,15 +32,13 @@ import java.util.Collections; import java.util.HashMap; import java.util.Optional; -import static markil3.immersive_hud.Main.FADE_IN_TIME; - public class TimerUtils { /** * The number of ticks that the hand will be onscreen. Every tick is 1/20th * of a second. */ - static final int HAND_TIME = 10 * 20; + 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. @@ -50,7 +48,9 @@ public class TimerUtils * The number of ticks that the health and hunger bars will be onscreen. * Every tick is 1/20th of a second. */ - static final int HEALTH_TIME = (int) ((float) VISUAL_TIME * 2.5); + 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 @@ -188,7 +188,7 @@ public class TimerUtils */ public static int getHotbarTranslation() { - return (int) (22F * Main.getAlpha(hotbarTime, VISUAL_TIME)); + return (int) (22F * Main.getAlpha(hotbarTime, VISUAL_TIME, FADE_IN_TIME, FADE_OUT_TIME)); } @@ -201,7 +201,7 @@ public class TimerUtils public static int getExperienceTranslation() { return (int) ((getHotbarTranslation() + 10F) * Main.getAlpha( - experienceTime, VISUAL_TIME)) - 3; + experienceTime, VISUAL_TIME, FADE_IN_TIME, FADE_OUT_TIME)) - 3; } @@ -213,7 +213,7 @@ public class TimerUtils */ public static int getJumpTranslation() { - return (int) ((getHotbarTranslation() + 10F) * Main.getAlpha(jumpTime, VISUAL_TIME)) - 3; + return (int) ((getHotbarTranslation() + 10F) * Main.getAlpha(jumpTime, VISUAL_TIME, FADE_IN_TIME, FADE_OUT_TIME)) - 3; } @@ -357,7 +357,7 @@ public class TimerUtils { setAlpha(Main.getAlpha(crosshairTime > 0 ? crosshairTime : - VISUAL_TIME - FADE_IN_TIME, VISUAL_TIME)); + VISUAL_TIME, VISUAL_TIME, 0, 0)); } else { @@ -429,7 +429,7 @@ public class TimerUtils } else { - effectAlpha = Main.getAlpha(time, VISUAL_TIME); + effectAlpha = Main.getAlpha(time, VISUAL_TIME, FADE_IN_TIME, FADE_OUT_TIME); } return effectAlpha; } @@ -693,7 +693,7 @@ public class TimerUtils stack.translate(0F, getHealthTranslation(), 0F); - setAlpha(Main.getAlpha(healthTime, HEALTH_TIME)); + setAlpha(Main.getAlpha(healthTime, HEALTH_TIME, FADE_IN_TIME, FADE_OUT_TIME)); return false; } return true; @@ -754,7 +754,7 @@ public class TimerUtils } else { - setAlpha(Main.getAlpha(hungerTime, HEALTH_TIME)); + setAlpha(Main.getAlpha(hungerTime, HEALTH_TIME, FADE_IN_TIME, FADE_OUT_TIME)); stack.push(); stack.translate(0F, getHealthTranslation(), @@ -780,7 +780,7 @@ public class TimerUtils */ if (healthTime > 0) { - setAlpha(Main.getAlpha(healthTime, HEALTH_TIME)); + setAlpha(Main.getAlpha(healthTime, HEALTH_TIME, FADE_IN_TIME, FADE_OUT_TIME)); stack.push(); stack.translate(0F, getHealthTranslation(), @@ -859,7 +859,7 @@ public class TimerUtils stack.translate(0F, getHealthTranslation(), 0F); - setAlpha(Main.getAlpha(mountTime, VISUAL_TIME)); + setAlpha(Main.getAlpha(mountTime, VISUAL_TIME, FADE_IN_TIME, FADE_OUT_TIME)); return false; } return true;