diff --git a/build.gradle b/build.gradle index d0c2d61..ee32b0f 100755 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '0.10-SNAPSHOT' + id 'fabric-loom' version '0.11-SNAPSHOT' id 'maven-publish' } diff --git a/gradle.properties b/gradle.properties index f0c7b7d..d12a309 100755 --- a/gradle.properties +++ b/gradle.properties @@ -4,12 +4,12 @@ org.gradle.jvmargs=-Xmx4G # Fabric Properties # check these on https://fabricmc.net/use minecraft_version=1.18.1 - yarn_mappings=1.18.1+build.1 + yarn_mappings=1.18.1+build.22 loader_version=0.12.12 cloth_version=6.1.48 modmenu_version=3.0.1 -fabric_version=0.44.0+1.18 +fabric_version=0.46.2+1.18 # Mod Properties mod_version = 1.3 diff --git a/src/main/java/markil3/immersive_hud/ConfigManager.java b/src/main/java/markil3/immersive_hud/ConfigManager.java index a46422e..ce1a09f 100755 --- a/src/main/java/markil3/immersive_hud/ConfigManager.java +++ b/src/main/java/markil3/immersive_hud/ConfigManager.java @@ -90,6 +90,7 @@ public class ConfigManager private TimeValues jumpTime = new TimeValues(); private TimeValues healthTime = new TimeValues(); private TimeValues hungerTime = new TimeValues(); + private TimeValues airTime = new TimeValues(); private TimeValues effectTime = new TimeValues(); private int crosshairTime = 6 * TICKS_PER_SECOND; private boolean hideCrosshair = true; @@ -98,6 +99,7 @@ public class ConfigManager private boolean showArmor = true; private double minHealth = 0.5; private int minHunger = 17; + private int minAir = 300; private Identifier[] ignoredItems = new Identifier[]{Registry.ITEM.getId(Items.FIREWORK_ROCKET)}; private Identifier[] enchantingBlocks = new Identifier[]{Registry.BLOCK.getId(Blocks.ENCHANTING_TABLE), Registry.BLOCK.getId(Blocks.ANVIL), Registry.BLOCK.getId(Blocks.BOOKSHELF), Registry.BLOCK.getId(Blocks.FURNACE), Registry.BLOCK.getId(Blocks.BLAST_FURNACE), Registry.BLOCK.getId(Blocks.SMOKER), Registry.BLOCK.getId(Blocks.GRINDSTONE)}; @@ -177,6 +179,11 @@ public class ConfigManager { return this.hungerTime; } + + public TimeValues getAirTime() + { + return this.airTime; + } /** * Obtains time values related to potion effects. @@ -258,6 +265,17 @@ public class ConfigManager { return this.minHunger; } + + /** + * Obtains the minimum oxygen for fading. Anything below that and the oxygen + * always displays. + * + * @return The oxygen boundary, from 0 to 20. + */ + public int getMinAir() + { + return this.minAir; + } /** * Obtains a collection of items that won't cause hands and crosshairs to show when used. @@ -370,6 +388,17 @@ public class ConfigManager { this.minHunger = MathHelper.clamp(boundary, 0, 20); } + + /** + * Sets the minimum oxygen value for fading. Anything below that and the + * air bar always displays. + * + * @param boundary - The air boundary, from 0 to 20. + */ + public void setMinAir(int boundary) + { + this.minAir = MathHelper.clamp(boundary, 0, 20); + } /** * Sets which items won't cause the hands and crosshairs to show when used. diff --git a/src/main/java/markil3/immersive_hud/ModMenu.java b/src/main/java/markil3/immersive_hud/ModMenu.java index d62f5dd..d6f8c61 100755 --- a/src/main/java/markil3/immersive_hud/ModMenu.java +++ b/src/main/java/markil3/immersive_hud/ModMenu.java @@ -125,6 +125,9 @@ public class ModMenu implements ModMenuApi startTimeField("hunger", entryBuilder, general, instance.getHungerTime()); + startTimeField("air", entryBuilder, + general, + instance.getAirTime()); startTimeField("effect", entryBuilder, general, instance.getPotionTime()); @@ -184,6 +187,15 @@ public class ModMenu implements ModMenuApi "tooltip.immersive_hud.minHunger")) .setSaveConsumer(val -> instance.setMinHunger(val)) .build()); + + general.addEntry(entryBuilder.startIntField(new TranslatableText( + "option.immersive_hud.minAir"), + instance.getMinAir()) + .setDefaultValue(300) + .setTooltip(new TranslatableText( + "tooltip.immersive_hud.minAir")) + .setSaveConsumer(val -> instance.setMinAir(val)) + .build()); general.addEntry(entryBuilder.startBooleanToggle(new TranslatableText( "option.immersive_hud.showArmor"), diff --git a/src/main/java/markil3/immersive_hud/TimerUtils.java b/src/main/java/markil3/immersive_hud/TimerUtils.java index 48c7734..b386186 100755 --- a/src/main/java/markil3/immersive_hud/TimerUtils.java +++ b/src/main/java/markil3/immersive_hud/TimerUtils.java @@ -131,11 +131,21 @@ public class TimerUtils * in hunger. */ private static int hunger = -1; + /** + * Records what the oxygen level was previously. Used to check for a change + * in oxygen. + */ + private static int air = -1; /** * Records whether or not there was food poisoning. Used to check for a * change in hunger. */ private static boolean isFoodPoisoned = false; + /** + * How many more ticks the oxygen bar will be onscreen. Every tick is 1/20th + * of a second. + */ + private static double airTime; /** * How many more ticks the mount's health bar will be onscreen. Every tick @@ -256,6 +266,8 @@ public class TimerUtils ConfigManager.getInstance().getJumpTime(); ConfigManager.TimeValues healthTimes = ConfigManager.getInstance().getHealthTime(); ConfigManager.TimeValues hungerTimes = ConfigManager.getInstance().getHungerTime(); + ConfigManager.TimeValues airTimes = + ConfigManager.getInstance().getAirTime(); float hotbarAlpha = Main.getAlpha(hotbarTime, hotbar.getMaxTime(), @@ -277,13 +289,24 @@ public class TimerUtils hungerTimes.getMaxTime(), hungerTimes.getFadeInTime(), hungerTimes.getFadeOutTime())); + statusAlpha = Math.max(statusAlpha, Main.getAlpha(airTime, + airTimes.getMaxTime(), + airTimes.getFadeInTime(), + airTimes.getFadeOutTime())); /* * Draw it in its standard location until it is completely transparent, then move it * instantly. */ statusAlpha = (float) Math.ceil(statusAlpha); - return 7 * (1 - Math.max(experienceAlpha, - jumpAlpha)) + 22 * (1 - hotbarAlpha) + 42 * (1 - statusAlpha); + float trans = 7 * (1 - Math.max(experienceAlpha, + jumpAlpha)) + 22 * (1 - hotbarAlpha) + 42 * (1 - statusAlpha) + 9 * (1 - Math.max(Main.getAlpha(hungerTime, + hungerTimes.getMaxTime(), + hungerTimes.getFadeInTime(), + hungerTimes.getFadeOutTime()), Main.getAlpha(healthTime, + healthTimes.getMaxTime(), + healthTimes.getFadeInTime(), + healthTimes.getFadeOutTime()))); + return trans; } /** @@ -848,6 +871,93 @@ public class TimerUtils return hungerTime == 0 && hunger > HUNGER_BOUNDARY && !entity .hasStatusEffect(StatusEffects.HUNGER); } + + /** + * Determines whether or not to draw the oxygen bar, adjusting the alpha as + * needed. + * + * @return If true, then cancel drawing the oxygen bar. + * + * @since 1.3.1-1.18-fabric + */ + public static boolean drawAir(float ticks) + { + /* + * When air falls to this level or below, the oxygen bar won't + * disappear, allowing the player to be constantly reminded of their + * low oxygen. + */ + final int AIR_BOUNDARY = ConfigManager.getInstance().getMinAir(); + ConfigManager.TimeValues airTimes = + ConfigManager.getInstance().getAirTime(); + + MinecraftClient mc = MinecraftClient.getInstance(); + PlayerEntity entity; + boolean canceled; + boolean changed = false; + + if (mc.getCameraEntity() instanceof PlayerEntity) + { + entity = (PlayerEntity) mc.getCameraEntity(); + } + else + { + return true; + } + + if (air != entity.getAir()) + { + float dividor = entity.getMaxAir() / 10; + if (air / dividor != entity.getAir() / dividor) + { + changed = true; + } + air = entity.getAir(); + } + if (air <= AIR_BOUNDARY) + { + changed = true; + } + if (entity.hasStatusEffect(StatusEffects + .CONDUIT_POWER) || entity.hasStatusEffect(StatusEffects + .WATER_BREATHING)) + { + changed = false; + } + if (changed) + { + airTime = airTimes.getMaxTime() - (airTime > 0 ? + airTimes.getFadeInTime() : + 0); + } + else if (airTime > 0) + { + airTime -= ticks; + } + + if (airTime <= 0 && (air >= AIR_BOUNDARY || entity.hasStatusEffect(StatusEffects + .CONDUIT_POWER) || entity.hasStatusEffect(StatusEffects + .WATER_BREATHING))) + { + return true; + } + /* + * Only makes a change if the player is healthy. Otherwise, + * the bar is shown. + */ + if (entity.getAir() >= entity.getMaxAir() || entity.hasStatusEffect(StatusEffects + .CONDUIT_POWER) || entity.hasStatusEffect(StatusEffects + .WATER_BREATHING)) + { + setAlpha(Main.getAlpha(airTime, + airTimes.getMaxTime(), + airTimes.getFadeInTime(), + airTimes.getFadeOutTime())); + } + return airTime == 0 && entity.getAir() >= entity.getMaxAir() && !entity.hasStatusEffect(StatusEffects + .CONDUIT_POWER) && !entity.hasStatusEffect(StatusEffects + .WATER_BREATHING); + } /** * Determines whether or not to draw the horse jump bar, adjusting the alpha diff --git a/src/main/java/markil3/immersive_hud/mixin/HudHook.java b/src/main/java/markil3/immersive_hud/mixin/HudHook.java index 53cd3bb..dfb78de 100755 --- a/src/main/java/markil3/immersive_hud/mixin/HudHook.java +++ b/src/main/java/markil3/immersive_hud/mixin/HudHook.java @@ -253,8 +253,9 @@ public class HudHook { try { + float trans = TimerUtils.getHealthTranslation(); stack.push(); - stack.translate(0F, TimerUtils.getHealthTranslation(), 0F); + stack.translate(0F, trans, 0F); } catch (Exception e) { @@ -381,6 +382,10 @@ public class HudHook * Resets the color so that nothing else is bothered. */ TimerUtils.setAlpha(1F); + if (TimerUtils.drawAir(MinecraftClient.getInstance().getTickDelta())) + { + TimerUtils.setAlpha(0F); + } } catch (Exception e) { @@ -398,6 +403,7 @@ public class HudHook { try { + TimerUtils.setAlpha(1F); stack.pop(); } catch (Exception e) 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 2f4c43c..9a78c98 100755 --- a/src/main/resources/assets/immersive_hud/lang/en_us.json +++ b/src/main/resources/assets/immersive_hud/lang/en_us.json @@ -15,6 +15,9 @@ "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.airMaxTime": "Oxygen Bar Display Time", + "option.immersive_hud.airFadeIn": "Oxygen Bar Fade In Time", + "option.immersive_hud.airFadeOut": "Oxygen 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", @@ -24,6 +27,7 @@ "option.immersive_hud.hideHands": "Hide Hands", "option.immersive_hud.minHealth": "Minimum Health Fade", "option.immersive_hud.minHunger": "Minimum Hunger Fade", + "option.immersive_hud.minAir": "Minimum Oxygen Fade", "option.immersive_hud.showArmor": "Show Armor", "option.immersive_hud.ignoreList": "Ignored Items", "option.immersive_hud.enchantingList": "Experience Blocks", @@ -42,6 +46,9 @@ "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.airMaxTime": "How long the hunger bar can be oxygen on screen in seconds", + "tooltip.immersive_hud.airFadeIn": "How many seconds it takes for the oxygen bar to fade in", + "tooltip.immersive_hud.airFadeOut": "How many seconds it takes for the oxygen 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", @@ -51,6 +58,7 @@ "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.minAir": "When the oxygen level goes below this level, the oxygen bar won't fade away", "tooltip.immersive_hud.showArmor": "Whether or not the armor bar should display on the HUD", "tooltip.immersive_hud.ignoreList": "Which items will not trigger the arm and crosshairs when used", "tooltip.immersive_hud.enchantingList": "Which blocks will show the experience bar when looked at.",