From 2eff4a4bb2ce03655fd7997df908892f8bc919f4 Mon Sep 17 00:00:00 2001 From: Markil3 <75867393+Markil3@users.noreply.github.com> Date: Fri, 26 Mar 2021 11:25:55 -0600 Subject: [PATCH] Adds the ability to always show hands and crosshairs. Apparently, @rflambert doesn't want the hands to fade. It seemed like a good idea, so I added a configurable option to the main repo. --- .../markil3/immersive_hud/ConfigManager.java | 42 +++++++ .../markil3/immersive_hud/TimerUtils.java | 114 ++++++++++-------- .../assets/immersive_hud/lang/en_us.json | 4 + 3 files changed, 107 insertions(+), 53 deletions(-) diff --git a/src/main/java/markil3/immersive_hud/ConfigManager.java b/src/main/java/markil3/immersive_hud/ConfigManager.java index f2b358c..6bfb889 100644 --- a/src/main/java/markil3/immersive_hud/ConfigManager.java +++ b/src/main/java/markil3/immersive_hud/ConfigManager.java @@ -84,7 +84,9 @@ public class ConfigManager private TimeValues hungerTime = new TimeValues(); private TimeValues effectTime = new TimeValues(); private int crosshairTime = 6 * TICKS_PER_SECOND; + private boolean hideCrosshair = true; private int handTime = 30 * TICKS_PER_SECOND; + private boolean hideHands = true; private boolean showArmor = true; private double minHealth = 0.5; private int minHunger = 17; @@ -186,6 +188,16 @@ public class ConfigManager return this.crosshairTime; } + /** + * Checks whether the crosshairs should be hidden after a period of time. + * + * @return - Whether or not crosshairs will be hidden. + */ + public boolean hideCrosshair() + { + return this.hideCrosshair; + } + /** * Obtains the time that the hands are allowed to display. * @@ -196,6 +208,16 @@ public class ConfigManager return this.handTime; } + /** + * Checks whether hands should be hidden after a period of time. + * + * @return - Whether or not hands will be hidden. + */ + public boolean hideHands() + { + return this.hideHands; + } + /** * Checks whether the armor bar should render. * @@ -238,6 +260,16 @@ public class ConfigManager this.crosshairTime = time; } + /** + * Sets whether the crosshairs should be hidden after a period of time. + * + * @param hide - Whether or not crosshairs will be hidden. + */ + public void hideCrosshair(boolean hide) + { + this.hideCrosshair = hide; + } + /** * Sets the time that the hands are allowed to display. * @@ -248,6 +280,16 @@ public class ConfigManager this.handTime = time; } + /** + * Sets whether hands should be hidden after a period of time. + * + * @param hide - Whether or not hands will be hidden. + */ + public void hideHands(boolean hide) + { + this.hideHands = hide; + } + /** * Determines whether the armor bar should render. * diff --git a/src/main/java/markil3/immersive_hud/TimerUtils.java b/src/main/java/markil3/immersive_hud/TimerUtils.java index 83f405a..5b8352b 100644 --- a/src/main/java/markil3/immersive_hud/TimerUtils.java +++ b/src/main/java/markil3/immersive_hud/TimerUtils.java @@ -354,48 +354,52 @@ public class TimerUtils { final float HAND_UP_TIME = 20F; - switch (hand) + boolean hideHands = ConfigManager.getInstance().hideHands(); + if (hideHands) { - case OFF_HAND: - if (offHandTime == 0 && !offHandLock) + switch (hand) { - return true; - } - else if (!offHandLock && (mapLock & 0b01) == 0) - { - if (offHandTime > 0) + case OFF_HAND: + if (offHandTime == 0 && !offHandLock) { - offHandTime -= ticks; + return true; } - if (offHandTime < HAND_UP_TIME) + else if (!offHandLock && (mapLock & 0b01) == 0) { - GlStateManager.translatef(0, - (float) (-1.0F * (HAND_UP_TIME - offHandTime) / - HAND_UP_TIME), - 0); + if (offHandTime > 0) + { + offHandTime -= ticks; + } + if (offHandTime < HAND_UP_TIME) + { + GlStateManager.translatef(0, + (float) (-1.0F * (HAND_UP_TIME - offHandTime) / + HAND_UP_TIME), + 0); + } } - } - break; - case MAIN_HAND: - if (mainHandTime == 0 && !mainHandLock) - { - return true; - } - else if (!mainHandLock && (mapLock & 0b10) == 0) - { - if (mainHandTime > 0) + break; + case MAIN_HAND: + if (mainHandTime == 0 && !mainHandLock) { - mainHandTime -= ticks; + return true; } - if (mainHandTime < HAND_UP_TIME) + else if (!mainHandLock && (mapLock & 0b10) == 0) { - GlStateManager.translatef(0, - (float) (-1.0F * (HAND_UP_TIME - mainHandTime) / - HAND_UP_TIME), - 0); + if (mainHandTime > 0) + { + mainHandTime -= ticks; + } + if (mainHandTime < HAND_UP_TIME) + { + GlStateManager.translatef(0, + (float) (-1.0F * (HAND_UP_TIME - mainHandTime) / + HAND_UP_TIME), + 0); + } } + break; } - break; } return false; } @@ -418,37 +422,41 @@ public class TimerUtils boolean changed = false; boolean canceled = false; - if (mc.hitResult != null && mc.hitResult - .getType() != HitResult.Type.MISS) + boolean hideCrosshair = ConfigManager.getInstance().hideCrosshair(); + if (hideCrosshair) { - if (mc.hitResult.getType() == HitResult.Type - .ENTITY) + if (mc.hitResult != null && mc.hitResult + .getType() != HitResult.Type.MISS) { - if (((EntityHitResult) mc.hitResult).getEntity() != entity - .getVehicle()) + if (mc.hitResult.getType() == HitResult.Type + .ENTITY) + { + if (((EntityHitResult) mc.hitResult).getEntity() != entity + .getVehicle()) + { + changed = true; + } + } + else { changed = true; } } + if (changed || mainHandLock || offHandLock || crosshairTime + > 0) + { + setAlpha(Main.getAlpha(crosshairTime > 0 ? + crosshairTime : + CROSSHAIR_TIME, CROSSHAIR_TIME, 0, 0)); + } else { - changed = true; + canceled = true; + } + if (crosshairTime > 0) + { + crosshairTime -= ticks; } - } - if (changed || mainHandLock || offHandLock || crosshairTime - > 0) - { - setAlpha(Main.getAlpha(crosshairTime > 0 ? - crosshairTime : - CROSSHAIR_TIME, CROSSHAIR_TIME, 0, 0)); - } - else - { - canceled = true; - } - if (crosshairTime > 0) - { - crosshairTime -= ticks; } return canceled; } diff --git a/src/main/resources/assets/immersive_hud/lang/en_us.json b/src/main/resources/assets/immersive_hud/lang/en_us.json index 86e1475..238c055 100644 --- a/src/main/resources/assets/immersive_hud/lang/en_us.json +++ b/src/main/resources/assets/immersive_hud/lang/en_us.json @@ -19,7 +19,9 @@ "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.hideCrosshair": "Hide Crosshair", "option.immersive_hud.handTime": "Hand Display Time", + "option.immersive_hud.hideHands": "Hide Hands", "option.immersive_hud.minHealth": "Minimum Health Fade", "option.immersive_hud.minHunger": "Minimum Hunger Fade", "option.immersive_hud.showArmor": "Show Armor", @@ -42,7 +44,9 @@ "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.hideCrosshair": "Whether or not the crosshairs should be hidden after a period of time", "tooltip.immersive_hud.handTime": "How many seconds the hands can be on screen", + "tooltip.immersive_hud.hideHands": "Whether or not hands should be hidden after a period of time", "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"