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 armorAccessors correctly and fixed logging

legoraft f1eb4165 cbd154c9

+60 -5
+3
src/client/java/com/armorhud/armor/ArmorAccessor.java
··· 9 9 public interface ArmorAccessor { 10 10 11 11 default void initialize(LocalPlayer player) { } 12 + default String getName() { 13 + return this.getClass().getSimpleName(); 14 + } 12 15 13 16 List<ItemStack> getArmorPieces(LocalPlayer player); 14 17 ItemStack getArmorPiece(LocalPlayer player, EquipmentSlot slot);
+4
src/client/java/com/armorhud/armor/CombinedArmorAccessor.java
··· 14 14 accessors.add(accessor); 15 15 } 16 16 17 + public List<ArmorAccessor> getAccessors() { 18 + return accessors; 19 + } 20 + 17 21 @Override 18 22 public List<ItemStack> getArmorPieces(LocalPlayer player) { 19 23 List<ItemStack> armorList = new ArrayList<>();
+5
src/client/java/com/armorhud/armor/VanillaArmorAccessor.java
··· 10 10 public class VanillaArmorAccessor implements ArmorAccessor { 11 11 12 12 @Override 13 + public String getName() { 14 + return "Vanilla"; 15 + } 16 + 17 + @Override 13 18 public List<ItemStack> getArmorPieces(LocalPlayer player) { 14 19 List<ItemStack> armorList = new ArrayList<>(); 15 20
+11 -2
src/client/java/com/armorhud/armorHud.java
··· 10 10 import org.slf4j.Logger; 11 11 import org.slf4j.LoggerFactory; 12 12 13 + import java.util.stream.Collectors; 14 + 13 15 public class armorHud implements ClientModInitializer { 14 16 15 17 public static final Logger LOGGER = LoggerFactory.getLogger("simple-armor-hud"); 16 18 public static final config CONFIG = new config(); 17 - private static ArmorAccessor armorAccessor; 19 + private static CombinedArmorAccessor armorAccessor; 18 20 19 21 @Override 20 22 public void onInitializeClient() { 21 23 LOGGER.info("Simple Armor Hud loaded!"); 22 24 armorAccessor = new CombinedArmorAccessor(); 25 + armorAccessor.addAccessor(new VanillaArmorAccessor()); 26 + 23 27 CONFIG.load(); 24 28 armorHudRegistries.registerArmorHud(); 25 29 handleKeys(); 26 30 27 - LOGGER.info("Armor accessor implementation: {}", armorAccessor.getClass().getSimpleName()); 31 + String accessorNames = armorAccessor.getAccessors().stream() 32 + .map(ArmorAccessor::getName) 33 + .collect(Collectors.joining(", ")); 34 + 35 + LOGGER.info("Loaded armorAccessors: [ {} ]", 36 + accessorNames.isEmpty() ? "none" : accessorNames); 28 37 } 29 38 30 39 public void handleKeys() {
+37 -3
src/client/java/com/armorhud/mixin/client/armorHudMixin.java
··· 20 20 import org.spongepowered.asm.mixin.injection.Inject; 21 21 import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 22 22 23 + import java.util.List; 24 + 23 25 @Mixin(Gui.class) 24 26 public abstract class armorHudMixin { 25 27 ··· 72 74 73 75 assert minecraft.player != null; 74 76 ArmorAccessor armorAccessor = armorHud.getArmorAccessor(); 75 - EquipmentSlot[] slots = EquipmentSlot.values(); 77 + List<ItemStack> armorPieces = armorAccessor.getArmorPieces(minecraft.player); 78 + 79 + // EquipmentSlot[] slots = EquipmentSlot.values(); 76 80 77 81 final int hungerWidth = 14; // Magic number to center 4 armor pieces 78 82 final int armorWidth = 15; 79 83 80 84 int emptyArmorSlots = 0; 85 + if ( config.TRIM_EMPTY_SLOTS ) { 86 + for ( ItemStack stack : armorPieces ) { 87 + if ( stack.isEmpty() ) { 88 + emptyArmorSlots++; 89 + } 90 + } 91 + } 92 + /* 81 93 if (config.TRIM_EMPTY_SLOTS) { 82 94 for (EquipmentSlot slot : slots) { 83 95 if (slot.isArmor()) { ··· 88 100 } 89 101 } 90 102 } 103 + 104 + */ 91 105 92 106 float hungerX = scaledWidth / 2f + startXPosition; 93 107 float x = hungerX + hungerWidth - (7 * emptyArmorSlots) + 2 - (armorWidth * 2); ··· 95 109 if (config.RTL) { 96 110 if ( config.TRIM_EMPTY_SLOTS ) { x -= (float) (( (float) armorWidth / 2 ) + 0.5); } 97 111 x += armorWidth; 98 - for ( int i = slots.length - 1; i > 0; i-- ) { 112 + armorPieces = armorPieces.reversed(); 113 + 114 + for ( ItemStack armor : armorPieces ) { 115 + if (config.TRIM_EMPTY_SLOTS && armor.isEmpty()) continue; 116 + x -= armorWidth; 117 + 118 + renderArmorPiece(context, x, armorHeight, minecraft.player, armor); 119 + } 120 + 121 + /*for ( int i = slots.length - 1; i > 0; i-- ) { 99 122 EquipmentSlot slot = slots[i]; 100 123 if (!slot.isArmor()) continue; 101 124 ItemStack armor = armorAccessor.getArmorPiece(minecraft.player, slot); ··· 105 128 106 129 renderArmorPiece(context, x, armorHeight, minecraft.player, armor); 107 130 } 131 + 132 + */ 108 133 } else { 109 134 if ( config.TRIM_EMPTY_SLOTS ) { x += ( (float) hungerWidth / 2 ); } 110 - for ( EquipmentSlot slot : slots ) { 135 + for ( ItemStack armor : armorPieces ) { 136 + if (config.TRIM_EMPTY_SLOTS && armor.isEmpty()) continue; 137 + x -= armorWidth; 138 + 139 + renderArmorPiece(context, x, armorHeight, minecraft.player, armor); 140 + } 141 + 142 + /*for ( EquipmentSlot slot : slots ) { 111 143 if ( !slot.isArmor() ) continue; 112 144 ItemStack armor = armorAccessor.getArmorPiece(minecraft.player, slot); 113 145 ··· 116 148 117 149 renderArmorPiece(context, x, armorHeight, minecraft.player, armor); 118 150 } 151 + 152 + */ 119 153 } 120 154 } 121 155