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: added condensed armor bar feature

[Visual feature] Condensed armor bar (Trim Empty Slots)

authored by

Legoraft and committed by
GitHub
1d995eb8 ffa2d56d

+27 -4
+3
src/client/java/com/armorhud/config/config.java
··· 16 16 public static boolean RTL = false; 17 17 public static boolean DISABLE_ARMOR_BAR = false; 18 18 public static boolean ABOVE_HEALTH_BAR = false; // a new option to render armor hud above the healthbar instead of the hungerbar -Dino 19 + public static boolean TRIM_EMPTY_SLOTS = false; // toggles trimming space between empty armor slots 19 20 20 21 private static final Path CONFIG_PATH = FabricLoader.getInstance().getConfigDir().resolve("armorhud.properties"); 21 22 ··· 26 27 properties.setProperty("right_to_left", Boolean.toString(RTL)); 27 28 properties.setProperty("disable_armor_bar", Boolean.toString(DISABLE_ARMOR_BAR)); 28 29 properties.setProperty("above_health_bar", Boolean.toString(ABOVE_HEALTH_BAR)); 30 + properties.setProperty("trim_empty_slots", Boolean.toString(TRIM_EMPTY_SLOTS)); 29 31 } 30 32 31 33 public void read(Properties properties) { ··· 35 37 RTL = Boolean.parseBoolean(properties.getProperty("right_to_left")); 36 38 DISABLE_ARMOR_BAR = Boolean.parseBoolean(properties.getProperty("disable_armor_bar")); 37 39 ABOVE_HEALTH_BAR = Boolean.parseBoolean(properties.getProperty("above_health_bar")); 40 + TRIM_EMPTY_SLOTS = Boolean.parseBoolean(properties.getProperty("trim_empty_slots")); 38 41 } 39 42 40 43 public static void save() {
+5
src/client/java/com/armorhud/config/configScreen.java
··· 21 21 public CyclingButtonWidget<?> rightToLeftToggle; 22 22 public CyclingButtonWidget<?> disableArmorBar; 23 23 public CyclingButtonWidget<?> armorPosition; 24 + public CyclingButtonWidget<?> trimEmptySlots; 24 25 25 26 public ButtonWidget doneButton; 26 27 ··· 45 46 Text.translatable("simple_armor_hud.render.above_armor_bar"), config.ABOVE_HEALTH_BAR) 46 47 .build(Text.translatable("config.hudposition"), ((button, value) -> config.ABOVE_HEALTH_BAR = !config.ABOVE_HEALTH_BAR)); 47 48 49 + trimEmptySlots = CyclingButtonWidget.onOffBuilder(config.TRIM_EMPTY_SLOTS) 50 + .build(Text.translatable("config.trimemptyslots"), ((button, value) -> config.TRIM_EMPTY_SLOTS = !config.TRIM_EMPTY_SLOTS)); 51 + 48 52 OptionListWidget optionListWidget = this.addDrawableChild(new OptionListWidget(this.client, this.width, this)); 49 53 50 54 optionListWidget.addWidgetEntry(doubleHotbarToggle, betterMountHudToggle); 51 55 optionListWidget.addWidgetEntry(armorHudToggle, rightToLeftToggle); 52 56 optionListWidget.addWidgetEntry(disableArmorBar, armorPosition); 57 + optionListWidget.addWidgetEntry(trimEmptySlots, null); 53 58 54 59 doneButton = ButtonWidget 55 60 .builder(Text.translatable("config.done"), button -> close())
+18 -4
src/client/java/com/armorhud/mixin/client/armorHudMixin.java
··· 11 11 import net.minecraft.entity.LivingEntity; 12 12 import net.minecraft.entity.player.PlayerEntity; 13 13 import net.minecraft.item.ItemStack; 14 + import org.slf4j.Logger; 15 + import org.slf4j.LoggerFactory; 14 16 import org.spongepowered.asm.mixin.Final; 15 17 import org.spongepowered.asm.mixin.Mixin; 16 18 import org.spongepowered.asm.mixin.Shadow; ··· 49 51 int scaledWidth = context.getScaledWindowWidth(); 50 52 51 53 assert client.player != null; 52 - 54 + boolean rtl = config.RTL; 53 55 ArmorAccessor armorAccessor = armorHud.getArmorAccessor(); 54 56 55 57 final int hungerWidth = 14; // Magic number to center 4 armor pieces ··· 58 60 // Added check for Above_Health_Bar -Dino 59 61 float hungerX = scaledWidth / 2f + (config.ABOVE_HEALTH_BAR 60 62 && client.player.getMaxHealth() + client.player.getMaxAbsorption() < 180 ? -10 : 91); 61 - float x = hungerX + hungerWidth + 2; 62 - 63 63 EquipmentSlot[] slots = EquipmentSlot.values(); 64 - boolean rtl = config.RTL; 64 + // 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 + int emptyArmorSlots = 0; 66 + if (config.TRIM_EMPTY_SLOTS) { 67 + for (int i = 2; i<6; i++) { // checks players armor slots only. probably makes stuff like trinkets incompatible -dino 68 + if(client.player.getEquippedStack(slots[i]).isEmpty()) { 69 + emptyArmorSlots++; 70 + } 71 + } 72 + } 73 + float x = hungerX + hungerWidth - (7*emptyArmorSlots) + 2; 74 + 75 + 65 76 for (int i = rtl ? slots.length-1 : 0; rtl ? i >= 0 : i < slots.length; i += rtl ? -1 : 1) { 66 77 EquipmentSlot slot = slots[i]; 78 + if(config.TRIM_EMPTY_SLOTS && slot.getType() == EquipmentSlot.Type.HUMANOID_ARMOR && client.player.getEquippedStack(slot).isEmpty()) { 79 + continue; 80 + }; 67 81 x -= armorWidth; 68 82 69 83 if (slot.isArmorSlot()) {
+1
src/main/resources/assets/simple-armor-hud/lang/en_us.json
··· 10 10 "config.hudposition": "Render", 11 11 "simple_armor_hud.render.above_food_bar": "Above Food Bar", 12 12 "simple_armor_hud.render.above_armor_bar": "Above Armor Bar", 13 + "config.trimemptyslots": "Trim Empty Slots", 13 14 14 15 "config.title": "Armor hud config screen", 15 16 "config.done": "Done"