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.

feat: added cycling button for position

legoraft dc0f4475 794a5f30

+33 -34
+7 -1
src/client/java/com/armorhud/config/config.java
··· 1 1 package com.armorhud.config; 2 2 3 3 import net.fabricmc.loader.api.FabricLoader; 4 + import net.minecraft.text.Text; 4 5 import org.apache.logging.log4j.LogManager; 5 6 6 7 import java.io.IOException; ··· 22 23 23 24 public enum Position { 24 25 FOODBAR, 25 - HEALTHBAR 26 + HEALTHBAR, 27 + HOTBAR_LEFT; 28 + 29 + public Text displayName() { 30 + return Text.translatable("config.armorposition." + name().toLowerCase()); 31 + } 26 32 } 27 33 28 34 public static void write(Properties properties) {
+15 -25
src/client/java/com/armorhud/config/configScreen.java
··· 2 2 3 3 import net.minecraft.client.gui.DrawContext; 4 4 import net.minecraft.client.gui.screen.Screen; 5 - import net.minecraft.client.gui.screen.option.GameOptionsScreen; 6 5 import net.minecraft.client.gui.widget.*; 7 6 import net.minecraft.text.Text; 8 7 9 - public class configScreen extends GameOptionsScreen { 10 - public Screen parent; 8 + import java.awt.*; 11 9 12 - public configScreen(Screen parent) { 13 - super(parent, null, Text.translatable("config.title")); 10 + public class configScreen extends Screen { 11 + private final Screen parent; 14 12 13 + public configScreen(Screen parent) { 14 + super(Text.translatable("config.title")); 15 15 this.parent = parent; 16 16 } 17 17 18 18 public CyclingButtonWidget<?> doubleHotbarToggle; 19 19 public CyclingButtonWidget<?> betterMountHudToggle; 20 20 public CyclingButtonWidget<?> armorHudToggle; 21 - public CyclingButtonWidget<?> rightToLeftToggle; 22 21 public CyclingButtonWidget<?> disableArmorBar; 23 22 public CyclingButtonWidget<?> armorPosition; 23 + public CyclingButtonWidget<?> rightToLeftToggle; 24 24 public CyclingButtonWidget<?> trimEmptySlots; 25 25 26 26 public ButtonWidget doneButton; ··· 36 36 armorHudToggle = CyclingButtonWidget.onOffBuilder(config.ARMOR_HUD) 37 37 .build(Text.translatable("config.armorvisible"), (button, value) -> config.ARMOR_HUD = !config.ARMOR_HUD); 38 38 39 - rightToLeftToggle = CyclingButtonWidget.onOffBuilder(config.RTL) 40 - .build(Text.translatable("config.righttoleft"), (button, value) -> config.RTL = !config.RTL); 41 - 42 39 disableArmorBar = CyclingButtonWidget.onOffBuilder(config.DISABLE_ARMOR_BAR) 43 40 .build(Text.translatable("config.disablearmorbar"), ((button, value) -> config.DISABLE_ARMOR_BAR = !config.DISABLE_ARMOR_BAR)); 44 41 45 - armorPosition = CyclingButtonWidget.onOffBuilder(Text.translatable("simple_armor_hud.render.above_food_bar"), 46 - Text.translatable("simple_armor_hud.render.above_armor_bar"), config.ABOVE_HEALTH_BAR) 47 - .build(Text.translatable("config.hudposition"), ((button, value) -> config.ABOVE_HEALTH_BAR = !config.ABOVE_HEALTH_BAR)); 42 + armorPosition = CyclingButtonWidget.builder(config.Position::displayName, config.Position.valueOf(String.valueOf(config.position))).values(config.Position.values()) 43 + .build(Text.translatable("config.armorposition"), ((button, value) -> { 44 + config.position = value; 45 + })); 46 + 47 + rightToLeftToggle = CyclingButtonWidget.onOffBuilder(config.RTL) 48 + .build(Text.translatable("config.righttoleft"), (button, value) -> config.RTL = !config.RTL); 48 49 49 50 trimEmptySlots = CyclingButtonWidget.onOffBuilder(config.TRIM_EMPTY_SLOTS) 50 51 .build(Text.translatable("config.trimemptyslots"), ((button, value) -> config.TRIM_EMPTY_SLOTS = !config.TRIM_EMPTY_SLOTS)); 51 52 52 - OptionListWidget optionListWidget = this.addDrawableChild(new OptionListWidget(this.client, this.width, this)); 53 - 54 - optionListWidget.addWidgetEntry(doubleHotbarToggle, betterMountHudToggle); 55 - optionListWidget.addWidgetEntry(armorHudToggle, rightToLeftToggle); 56 - optionListWidget.addWidgetEntry(disableArmorBar, armorPosition); 57 - optionListWidget.addWidgetEntry(trimEmptySlots, null); 58 - 59 53 doneButton = ButtonWidget 60 54 .builder(Text.translatable("config.done"), button -> close()) 61 55 .dimensions(width / 2 - 100, height - 25, 200, 20) 62 56 .build(); 63 57 58 + addDrawableChild(armorPosition); 59 + 64 60 addDrawableChild(doneButton); 65 61 } 66 62 67 - @Override 68 63 public void render(DrawContext context, int mouseX, int mouseY, float delta) { 69 64 super.render(context, mouseX, mouseY, delta); 70 65 context.drawCenteredTextWithShadow(textRenderer, super.title, width / 2, 12, 0xffffff); 71 - } 72 - 73 - @Override 74 - protected void addOptions() { 75 66 super.init(); 76 67 } 77 68 ··· 82 73 config.save(); 83 74 this.client.setScreen(this.parent); 84 75 } 85 - 86 76 }
+2 -3
src/client/java/com/armorhud/mixin/client/armorHudMixin.java
··· 58 58 final int armorWidth = 15; 59 59 60 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); 61 + float hungerX = scaledWidth / 2f + (client.player.getMaxHealth() + client.player.getMaxAbsorption() < 180 ? -10 : 91); 63 62 EquipmentSlot[] slots = EquipmentSlot.values(); 64 63 // counts empty slots to center condensed armor bar, don't like having to loop through the equip slots twice but idk how else to center this dynamically -dino 65 64 int emptyArmorSlots = 0; ··· 112 111 /* TODO: fix visual bug where remaining hearts available (>20hp) get removed later than armor hud -Dino 113 112 Skips unnecessary checks when Above_Health_Bar is on, not a fan of the extra if statement, but it works -Dino 114 113 Note: setting gets turned off above 9 rows of hearts, since the hud will fly off the screen at some point -Dino */ 115 - if (config.ABOVE_HEALTH_BAR && client.player.getMaxHealth() + client.player.getMaxAbsorption() < 180) { 114 + if (client.player.getMaxHealth() + client.player.getMaxAbsorption() < 180) { 116 115 /* Displacement calculation extracted for clarity. -Dino 117 116 Calc breaks above 90 hearts since hearts don't get condensed further, so it overshoots down -Dino */ 118 117 int playerHealthRows = (int) Math.ceil((client.player.getMaxHealth() + client.player.getMaxAbsorption()) / 20);
+9 -5
src/main/resources/assets/simple-armor-hud/lang/en_us.json
··· 4 4 5 5 "config.doublehotbar": "Double Hotbar", 6 6 "config.bettermounthud": "Better Mount Hud", 7 + 7 8 "config.armorvisible": "Armor visible", 8 - "config.righttoleft": "Right to left display", 9 9 "config.disablearmorbar": "Disable armor bar", 10 - "config.hudposition": "Render", 11 - "simple_armor_hud.render.above_food_bar": "Above Food Bar", 12 - "simple_armor_hud.render.above_armor_bar": "Above Armor Bar", 10 + 11 + "config.righttoleft": "Right to left display", 13 12 "config.trimemptyslots": "Trim Empty Slots", 14 13 15 - "config.title": "Armor hud config screen", 14 + "config.armorposition": "Render", 15 + "config.armorposition.foodbar": "Above Foodbar", 16 + "config.armorposition.healthbar": "Above Healthbar", 17 + "config.armorposition.hotbar_left": "Left Hotbar", 18 + 19 + "config.title": "Simple armor hud config screen", 16 20 "config.done": "Done" 17 21 }