diff --git a/src/main/java/markil3/immersive_hud/TimerUtils.java b/src/main/java/markil3/immersive_hud/TimerUtils.java index 302975f..3ab8f6c 100644 --- a/src/main/java/markil3/immersive_hud/TimerUtils.java +++ b/src/main/java/markil3/immersive_hud/TimerUtils.java @@ -205,6 +205,50 @@ public class TimerUtils setAlpha(1.0F); } + /** + * Obtains the offset from the bottom of the screen that the hotbar + * receives. + * + * @return The offset the hotbar uses. + */ + public static int getHotbarTranslation() + { + return (int) (22F * (1 - Main.getAlpha(hotbarTime))); + } + + /** + * Obtains the offset from the bottom of the screen that the experience bar + * receives. + * + * @return The offset the experience bar uses. + */ + public static int getExperienceTranslation() + { + return (int) ((12F + (22 - getHotbarTranslation())) * (1 - Main.getAlpha(experienceTime))) + getHotbarTranslation(); + } + + /** + * Obtains the offset from the bottom of the screen that the jump bar + * receives. + * + * @return The offset the jump bar uses. + */ + public static int getJumpTranslation() + { + return (int) ((12F + (22 - getHotbarTranslation())) * (1 - Main.getAlpha(jumpTime))) + getHotbarTranslation(); + } + + /** + * Obtains the offset that the status bars (health, hunger, etc.) gets from + * their usual position. + * + * @return The offset. + */ + public static float getHealthTranslation() + { + return 7 * (1 - Math.max(Main.getAlpha(experienceTime), Main.getAlpha(jumpTime))) + 22 * (1 - Main.getAlpha(hotbarTime));//Math.min(, getHotbarTranslation()); + } + /** * Run whenever the player clicks a mouse button. This brings the hands into * view, and briefly brings the health and hunger into view if the held item @@ -386,7 +430,7 @@ public class TimerUtils * * @since 0.1-1.16.4-fabric */ - public static boolean drawMountHealth() + public static boolean drawMountHealth(MatrixStack stack) { /* * When the health percentage falls to this level or below, the @@ -431,6 +475,10 @@ public class TimerUtils if (mountTime > 0) { + stack.push(); + stack.translate(0F, + getHealthTranslation(), + 0F); setAlpha(Main.getAlpha(mountTime)); return false; } @@ -663,8 +711,9 @@ public class TimerUtils * @return If true, then cancel drawing the jump bar. * * @since 0.1-1.16.4-fabric + * @param stack */ - public static boolean drawJumpbar() + public static boolean drawJumpbar(MatrixStack stack) { MinecraftClient mc = MinecraftClient.getInstance(); ClientPlayerEntity entity; @@ -687,6 +736,8 @@ public class TimerUtils } if (jumpTime > 0) { + stack.push(); + stack.translate(0F, TimerUtils.getJumpTranslation(), 0F); setAlpha(Main.getAlpha(jumpTime)); return false; } @@ -701,7 +752,7 @@ public class TimerUtils * * @since 0.1-1.16.4-fabric */ - public static boolean drawExperience() + public static boolean drawExperience(MatrixStack stack) { MinecraftClient mc = MinecraftClient.getInstance(); ClientPlayerEntity entity; @@ -731,6 +782,8 @@ public class TimerUtils } if (experienceTime > 0) { + stack.push(); + stack.translate(0F, TimerUtils.getExperienceTranslation(), 0F); setAlpha(Main.getAlpha(experienceTime)); return false; } @@ -953,8 +1006,11 @@ public class TimerUtils * * @since 0.1-1.16.4-fabric */ - public static void recolorHotbar() + public static void recolorHotbar(MatrixStack stack) { + RenderSystem.pushMatrix(); + stack.push(); + RenderSystem.translatef(0F, TimerUtils.getHotbarTranslation(), 0F); setAlpha(Main.getAlpha(hotbarTime)); } } diff --git a/src/main/java/markil3/immersive_hud/mixin/HudHook.java b/src/main/java/markil3/immersive_hud/mixin/HudHook.java index 1839305..f836e9a 100644 --- a/src/main/java/markil3/immersive_hud/mixin/HudHook.java +++ b/src/main/java/markil3/immersive_hud/mixin/HudHook.java @@ -16,6 +16,8 @@ */ package markil3.immersive_hud.mixin; +import com.mojang.blaze3d.systems.RenderSystem; + import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.hud.InGameHud; import net.minecraft.client.network.ClientPlayerEntity; @@ -95,7 +97,7 @@ public class HudHook int x, CallbackInfo callbackInfo) { - if (TimerUtils.drawJumpbar()) + if (TimerUtils.drawJumpbar(stack)) { callbackInfo.cancel(); } @@ -115,6 +117,7 @@ public class HudHook int x, CallbackInfo callbackInfo) { + stack.pop(); /* * Resets the color so that nothing else is bothered. */ @@ -136,7 +139,7 @@ public class HudHook int x, CallbackInfo callbackInfo) { - if (TimerUtils.drawExperience()) + if (TimerUtils.drawExperience(stack)) { callbackInfo.cancel(); } @@ -156,12 +159,38 @@ public class HudHook int x, CallbackInfo callbackInfo) { + stack.pop(); /* * Resets the color so that nothing else is bothered. */ TimerUtils.resetAlpha(); } + /** + * Changes the position of the status bars as the ones below them move up + * and down. + * + * @param stack - The matrix stack used. + * + * @return The same matrix stack, with a new matrix pushed onto it. + */ + @ModifyVariable(method = "renderStatusBars(Lnet/minecraft/client/util" + + "/math/MatrixStack;)V", at = @At("HEAD")) + public MatrixStack startStatus(MatrixStack stack) + { + stack.push(); + stack.translate(0F, TimerUtils.getHealthTranslation(), 0F); + return stack; + } + + @ModifyVariable(method = "renderStatusBars(Lnet/minecraft/client/util" + + "/math/MatrixStack;)V", at = @At("TAIL")) + public MatrixStack finishStatus(MatrixStack stack) + { + stack.pop(); + return stack; + } + /** * Determines whether or not to draw the mount's health. * @@ -175,7 +204,7 @@ public class HudHook cancellable = true) public void startMountHealth(MatrixStack stack, CallbackInfo callbackInfo) { - if (TimerUtils.drawMountHealth()) + if (TimerUtils.drawMountHealth(stack)) { callbackInfo.cancel(); } @@ -196,6 +225,7 @@ public class HudHook /* * Resets the color so that nothing else is bothered. */ + stack.pop(); TimerUtils.resetAlpha(); } @@ -236,15 +266,15 @@ public class HudHook /** * Makes the actual adjustment to the hotbar as needed. * - * @param matrices - The matrix drawing stack. - * @param callbackInfo + * @param f - The original transparency + * @param stack - The matrix stack * * @version 0.2-1.16.4-fabric * @since 0.1-1.16.4-fabric */ @ModifyVariable(method = "renderStatusEffectOverlay" + "(Lnet/minecraft/client/util/math/MatrixStack;)V", at = - @At(value = "STORE"), ordinal = 1) + @At(value = "STORE")) public float updatePotion(float f, MatrixStack stack) { @@ -309,14 +339,14 @@ public class HudHook MatrixStack matrices, CallbackInfo callbackInfo) { - TimerUtils.recolorHotbar(); + TimerUtils.recolorHotbar(matrices); } /** * Resets any changes from drawing the hotbar. * * @param tickDelta - * @param matrices - The matrix drawing stack. + * @param stack - The matrix drawing stack. * @param callbackInfo * * @version 0.2-1.16.4-fabric @@ -324,9 +354,11 @@ public class HudHook */ @Inject(method = "renderHotbar", at = @At(value = "TAIL")) public void finishHotbar(float tickDelta, - MatrixStack matrices, + MatrixStack stack, CallbackInfo callbackInfo) { + RenderSystem.popMatrix(); + stack.pop(); /* * Resets the color so that nothing else is bothered. */