A mod that adds your armor to the hud modrinth.com/mod/simple-armor-hud
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

merge: TheDinoKingK/dinos_health_rendering

New option to display SAH above the health-bar / armor-bar

authored by

Legoraft and committed by
GitHub
b0188e72 018eeba7

+173 -141
+3
src/client/java/com/armorhud/config/config.java
··· 15 15 public static boolean ARMOR_HUD = true; 16 16 public static boolean RTL = false; 17 17 public static boolean DISABLE_ARMOR_BAR = false; 18 + public static boolean ABOVE_HEALTH_BAR = false; // a new option to render armor hud above the healthbar instead of the hungerbar -Dino 18 19 19 20 private static final Path CONFIG_PATH = FabricLoader.getInstance().getConfigDir().resolve("armorhud.properties"); 20 21 ··· 24 25 properties.setProperty("armor_hud", Boolean.toString(ARMOR_HUD)); 25 26 properties.setProperty("right_to_left", Boolean.toString(RTL)); 26 27 properties.setProperty("disable_armor_bar", Boolean.toString(DISABLE_ARMOR_BAR)); 28 + properties.setProperty("above_health_bar", Boolean.toString(ABOVE_HEALTH_BAR)); 27 29 } 28 30 29 31 public void read(Properties properties) { ··· 32 34 ARMOR_HUD = Boolean.parseBoolean(properties.getProperty("armor_hud")); 33 35 RTL = Boolean.parseBoolean(properties.getProperty("right_to_left")); 34 36 DISABLE_ARMOR_BAR = Boolean.parseBoolean(properties.getProperty("disable_armor_bar")); 37 + ABOVE_HEALTH_BAR = Boolean.parseBoolean(properties.getProperty("above_health_bar")); 35 38 } 36 39 37 40 public static void save() {
+5 -1
src/client/java/com/armorhud/config/configScreen.java
··· 20 20 public CyclingButtonWidget armorHudToggle; 21 21 public CyclingButtonWidget rightToLeftToggle; 22 22 public CyclingButtonWidget disableArmorBar; 23 + public CyclingButtonWidget aboveHealthBar; // TODO: want the option to visually be "Render: above health bar" & "Render: above hunger bar" instead of "off" & "on" -Dino 23 24 24 25 public ButtonWidget doneButton; 25 26 ··· 40 41 disableArmorBar = CyclingButtonWidget.onOffBuilder(config.DISABLE_ARMOR_BAR) 41 42 .build(Text.translatable("config.disablearmorbar"), ((button, value) -> config.DISABLE_ARMOR_BAR = !config.DISABLE_ARMOR_BAR)); 42 43 44 + aboveHealthBar = CyclingButtonWidget.onOffBuilder(config.ABOVE_HEALTH_BAR) 45 + .build(Text.translatable("config.abovehealthbar"), ((button, value) -> config.ABOVE_HEALTH_BAR = !config.ABOVE_HEALTH_BAR)); 46 + 43 47 OptionListWidget optionListWidget = this.addDrawableChild(new OptionListWidget(this.client, this.width, this)); 44 48 45 49 optionListWidget.addWidgetEntry(doubleHotbarToggle, betterMountHudToggle); 46 50 optionListWidget.addWidgetEntry(armorHudToggle, rightToLeftToggle); 47 - optionListWidget.addWidgetEntry(disableArmorBar, null); 51 + optionListWidget.addWidgetEntry(disableArmorBar, aboveHealthBar); 48 52 49 53 doneButton = ButtonWidget 50 54 .builder(Text.translatable("config.done"), button -> close())
+164 -140
src/client/java/com/armorhud/mixin/client/armorHudMixin.java
··· 1 - package com.armorhud.mixin.client; 2 - 3 - import com.armorhud.armor.ArmorAccessor; 4 - import com.armorhud.armorHud; 5 - import com.armorhud.config.config; 6 - import net.minecraft.client.MinecraftClient; 7 - import net.minecraft.client.gui.DrawContext; 8 - import net.minecraft.client.gui.hud.InGameHud; 9 - import net.minecraft.client.render.RenderTickCounter; 10 - import net.minecraft.entity.LivingEntity; 11 - import net.minecraft.entity.player.PlayerEntity; 12 - import net.minecraft.item.ItemStack; 13 - import org.spongepowered.asm.mixin.Final; 14 - import org.spongepowered.asm.mixin.Mixin; 15 - import org.spongepowered.asm.mixin.Shadow; 16 - import org.spongepowered.asm.mixin.Unique; 17 - import org.spongepowered.asm.mixin.injection.At; 18 - import org.spongepowered.asm.mixin.injection.Inject; 19 - import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 20 - 21 - @Mixin(InGameHud.class) 22 - public abstract class armorHudMixin { 23 - 24 - @Shadow @Final private MinecraftClient client; 25 - 26 - @Shadow protected abstract LivingEntity getRiddenEntity(); 27 - 28 - @Shadow public abstract void tick(boolean paused); 29 - 30 - @Unique int armorHeight; 31 - @Unique boolean initialized; 32 - 33 - @Inject(at = @At("TAIL"), method = "renderHotbar") 34 - private void renderHud(DrawContext context, RenderTickCounter tickCounter, CallbackInfo ci) { 35 - if(!config.ARMOR_HUD) { return; } 36 - 37 - assert client.player != null; 38 - 39 - if (!initialized) { 40 - armorHud.getArmorAccessor().initialize(client.player); 41 - initialized = true; 42 - } 43 - 44 - renderArmor(context, tickCounter); 45 - moveArmor(context); 46 - } 47 - 48 - @Unique 49 - private void renderArmor(DrawContext context, RenderTickCounter tickCounter) { 50 - int scaledWidth = context.getScaledWindowWidth(); 51 - 52 - assert client.player != null; 53 - 54 - ArmorAccessor armorAccessor = armorHud.getArmorAccessor(); 55 - int pieces = armorAccessor.getPieces(client.player); 56 - 57 - final int hungerWidth = 80 + 8; // Bar advances 8 pixels to the left 10 times, 8 is added for the width of the last sprite. 58 - final int armorWidth = 15; 59 - final int barWidth = armorWidth * pieces; 60 - float hungerX = scaledWidth / 2f + 91; 61 - float x = hungerX - hungerWidth / 2f + barWidth / 2f; 62 - x += 2; // This makes it look better because the helmet is thinner. 63 - 64 - for (int j = 0; j < pieces; j++) { 65 - x -= armorWidth; 66 - int armorPiece; 67 - 68 - if (config.RTL) { 69 - armorPiece = (pieces - 1) - j; 70 - } else { 71 - armorPiece = j; 72 - } 73 - 74 - renderArmorPiece(context, x, armorHeight, tickCounter, client.player, armorAccessor.getArmorPiece(client.player, armorPiece)); 75 - } 76 - } 77 - 78 - // Pretty much the same as renderHotbarItem but with x and y as float parameters. 79 - @Unique 80 - private void renderArmorPiece(DrawContext context, float x, float y, RenderTickCounter tickCounter, PlayerEntity player, ItemStack stack) { 81 - if (stack.isEmpty()) return; 82 - 83 - context.getMatrices().push(); 84 - context.getMatrices().translate(x, y, 0); 85 - 86 - context.drawItem(player, stack, 0, 0, 1); 87 - 88 - context.drawStackOverlay(this.client.textRenderer, stack, 0,0); 89 - context.getMatrices().pop(); 90 - } 91 - 92 - @Unique 93 - private void moveArmor(DrawContext context) { 94 - int scaledHeight = context.getScaledWindowHeight(); 95 - 96 - assert client.player != null; 97 - 98 - // Moves armorhud up if player uses double hotbar 99 - armorHeight = scaledHeight - (config.DOUBLE_HOTBAR ? 76 : 55); 100 - 101 - // Moves armorhud up if player is underwater 102 - if (client.player.getAir() < client.player.getMaxAir() || client.player.isSubmergedInWater() && !client.player.isCreative()) { 103 - armorHeight -= 10; 104 - } 105 - 106 - // Moves armorhud down if player is in creative 107 - armorHeight += (client.player.isCreative() ? 16 : 0); 108 - 109 - // Moves armorhud up if player is on mount, like horse 110 - if (client.player.hasVehicle() && getRiddenEntity() != null) { 111 - moveArmorHorse(); 112 - } 113 - } 114 - 115 - @Unique 116 - private void moveArmorHorse() { 117 - assert client.player != null; 118 - 119 - // Check if entity player is riding is alive, like a horse 120 - if (getRiddenEntity().isAlive()) { 121 - // If horse health is 21, it still displays 10 hearts 122 - if (getRiddenEntity().getMaxHealth() > 21) { 123 - if (config.BETTER_MOUNT_HUD && !client.player.isCreative()) { 124 - armorHeight -= 20; 125 - } else { 126 - armorHeight -= (client.player.isCreative() ? 26 : 10); 127 - } 128 - } 129 - // Armor hud only has to be moved up if better mount hud is enabled or player is in creative 130 - else { 131 - if (config.BETTER_MOUNT_HUD && !client.player.isCreative()) { 132 - armorHeight -= 10; 133 - } else if (client.player.isCreative()) { 134 - armorHeight -= 16; 135 - } 136 - } 137 - } 138 - } 139 - 140 - } 1 + package com.armorhud.mixin.client; 2 + 3 + import com.armorhud.armor.ArmorAccessor; 4 + import com.armorhud.armorHud; 5 + import com.armorhud.config.config; 6 + import net.minecraft.client.MinecraftClient; 7 + import net.minecraft.client.gui.DrawContext; 8 + import net.minecraft.client.gui.hud.InGameHud; 9 + import net.minecraft.client.render.RenderTickCounter; 10 + import net.minecraft.entity.LivingEntity; 11 + import net.minecraft.entity.player.PlayerEntity; 12 + import net.minecraft.item.ItemStack; 13 + import org.spongepowered.asm.mixin.Final; 14 + import org.spongepowered.asm.mixin.Mixin; 15 + import org.spongepowered.asm.mixin.Shadow; 16 + import org.spongepowered.asm.mixin.Unique; 17 + import org.spongepowered.asm.mixin.injection.At; 18 + import org.spongepowered.asm.mixin.injection.Inject; 19 + import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 20 + 21 + @Mixin(InGameHud.class) 22 + public abstract class armorHudMixin { 23 + 24 + @Shadow @Final private MinecraftClient client; 25 + 26 + @Shadow protected abstract LivingEntity getRiddenEntity(); 27 + 28 + @Shadow public abstract void tick(boolean paused); 29 + 30 + @Unique int armorHeight; 31 + @Unique boolean initialized; 32 + 33 + @Inject(at = @At("TAIL"), method = "renderHotbar") 34 + private void renderHud(DrawContext context, RenderTickCounter tickCounter, CallbackInfo ci) { 35 + if(!config.ARMOR_HUD) { return; } 36 + 37 + assert client.player != null; 38 + 39 + if (!initialized) { 40 + armorHud.getArmorAccessor().initialize(client.player); 41 + initialized = true; 42 + } 43 + 44 + renderArmor(context, tickCounter); 45 + moveArmor(context); 46 + } 47 + 48 + @Unique 49 + private void renderArmor(DrawContext context, RenderTickCounter tickCounter) { 50 + int scaledWidth = context.getScaledWindowWidth(); 51 + 52 + assert client.player != null; 53 + 54 + ArmorAccessor armorAccessor = armorHud.getArmorAccessor(); 55 + int pieces = armorAccessor.getPieces(client.player); 56 + 57 + final int hungerWidth = 80 + 8; // Bar advances 8 pixels to the left 10 times, 8 is added for the width of the last sprite. 58 + final int armorWidth = 15; 59 + final int barWidth = armorWidth * pieces; 60 + // Added check for Above_Health_Bar -Dino 61 + float hungerX = scaledWidth / 2f + (config.ABOVE_HEALTH_BAR 62 + && client.player.getMaxHealth() + client.player.getMaxAbsorption() < 180 ? -10 : 91); 63 + float x = hungerX - hungerWidth / 2f + barWidth / 2f; 64 + x += 2; // This makes it look better because the helmet is thinner. 65 + 66 + for (int j = 0; j < pieces; j++) { 67 + x -= armorWidth; 68 + int armorPiece; 69 + 70 + if (config.RTL) { 71 + armorPiece = (pieces - 1) - j; 72 + } else { 73 + armorPiece = j; 74 + } 75 + 76 + renderArmorPiece(context, x, armorHeight, tickCounter, client.player, armorAccessor.getArmorPiece(client.player, armorPiece)); 77 + } 78 + } 79 + 80 + // Pretty much the same as renderHotbarItem but with x and y as float parameters. 81 + @Unique 82 + private void renderArmorPiece(DrawContext context, float x, float y, RenderTickCounter tickCounter, PlayerEntity player, ItemStack stack) { 83 + if (stack.isEmpty()) return; 84 + 85 + context.getMatrices().push(); 86 + context.getMatrices().translate(x, y, 0); 87 + 88 + context.drawItem(player, stack, 0, 0, 1); 89 + 90 + context.drawStackOverlay(this.client.textRenderer, stack, 0,0); 91 + context.getMatrices().pop(); 92 + } 93 + 94 + @Unique 95 + private void moveArmor(DrawContext context) { 96 + int scaledHeight = context.getScaledWindowHeight(); 97 + 98 + assert client.player != null; 99 + 100 + // Moves armorhud up if player uses double hotbar 101 + armorHeight = scaledHeight - (config.DOUBLE_HOTBAR ? 76 : 55); 102 + 103 + /* TODO: fix visual bug where remaining hearts available (>20hp) get removed later than armor hud -Dino 104 + Skips unnecessary checks when Above_Health_Bar is on, not a fan of the extra if statement, but it works -Dino 105 + Note: setting gets turned off above 9 rows of hearts, since the hud will fly off the screen at some point -Dino */ 106 + if (config.ABOVE_HEALTH_BAR && client.player.getMaxHealth() + client.player.getMaxAbsorption() < 180) { 107 + /* Displacement calculation extracted for clarity. -Dino 108 + Calc breaks above 90 hearts since hearts don't get condensed further, so it overshoots down -Dino */ 109 + int playerHealthRows = (int) Math.ceil((client.player.getMaxHealth() + client.player.getMaxAbsorption()) / 20); 110 + int healthDisplacement = (10 * playerHealthRows) - ((playerHealthRows>2) ? (playerHealthRows -2) * (playerHealthRows -1) : 0); 111 + 112 + // Moves armorhud up depending on how much health you have, along with negative displacement from higher heart counts -Dino 113 + armorHeight -= healthDisplacement; 114 + 115 + /* Moves armorhud down if player is in creative or Disable_Armor_Bar is on, 116 + formatted as an if-statement for readability -Dino 117 + */ 118 + if(client.player.isCreative()) { 119 + armorHeight += 16 + healthDisplacement; 120 + } else if (config.DISABLE_ARMOR_BAR) { 121 + armorHeight += 10; 122 + } 123 + } else { 124 + // Moves armorhud up if player is underwater 125 + if ((client.player.getAir() < client.player.getMaxAir() || client.player.isSubmergedInWater() && !client.player.isCreative())) { 126 + armorHeight -= 10; 127 + } 128 + 129 + // Moves armorhud down if player is in creative 130 + armorHeight += (client.player.isCreative() ? 16 : 0); 131 + 132 + // Moves armorhud up if player is on mount, like horse 133 + if (client.player.hasVehicle() && getRiddenEntity() != null) { 134 + moveArmorHorse(); 135 + } 136 + } 137 + } 138 + 139 + @Unique 140 + private void moveArmorHorse() { 141 + assert client.player != null; 142 + 143 + // Check if entity player is riding is alive, like a horse 144 + if (getRiddenEntity().isAlive()) { 145 + // If horse health is 21, it still displays 10 hearts 146 + if (getRiddenEntity().getMaxHealth() > 21) { 147 + if (config.BETTER_MOUNT_HUD && !client.player.isCreative()) { 148 + armorHeight -= 20; 149 + } else { 150 + armorHeight -= (client.player.isCreative() ? 26 : 10); 151 + } 152 + } 153 + // Armor hud only has to be moved up if better mount hud is enabled or player is in creative 154 + else { 155 + if (config.BETTER_MOUNT_HUD && !client.player.isCreative()) { 156 + armorHeight -= 10; 157 + } else if (client.player.isCreative()) { 158 + armorHeight -= 16; 159 + } 160 + } 161 + } 162 + } 163 + 164 + }
+1
src/main/resources/assets/simple-armor-hud/lang/en_us.json
··· 7 7 "config.armorvisible": "Armor visible", 8 8 "config.righttoleft": "Right to left display", 9 9 "config.disablearmorbar": "Disable armor bar", 10 + "config.abovehealthbar": "Move above health bar", 10 11 11 12 "config.title": "Armor hud config screen", 12 13 "config.done": "Done"