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: changed armorAccessor to use new armor system

+19 -8
+2 -1
src/client/java/com/armorhud/armor/ArmorAccessor.java
··· 1 1 package com.armorhud.armor; 2 2 3 3 import net.minecraft.client.network.ClientPlayerEntity; 4 + import net.minecraft.entity.EquipmentSlot; 4 5 import net.minecraft.item.ItemStack; 5 6 6 7 public interface ArmorAccessor { ··· 8 9 default void initialize(ClientPlayerEntity player) { 9 10 } 10 11 11 - ItemStack getArmorPiece(ClientPlayerEntity player, int slotIndex); 12 + ItemStack getArmorPiece(ClientPlayerEntity player, EquipmentSlot slot); 12 13 13 14 int getPieces(ClientPlayerEntity player); 14 15 }
+17 -7
src/client/java/com/armorhud/armor/VanillaArmorAccessor.java
··· 1 1 package com.armorhud.armor; 2 2 3 3 import net.minecraft.client.network.ClientPlayerEntity; 4 + import net.minecraft.entity.EquipmentSlot; 4 5 import net.minecraft.item.ItemStack; 5 6 6 7 public class VanillaArmorAccessor implements ArmorAccessor { 7 8 8 - @Override 9 - public ItemStack getArmorPiece(ClientPlayerEntity player, int slotIndex) { 10 - if (slotIndex < 0 || slotIndex >= getPieces(player)) { 11 - throw new IllegalArgumentException("Invalid slot index: " + slotIndex); 9 + public ItemStack getArmorPiece(ClientPlayerEntity player, EquipmentSlot slot) { 10 + if (!slot.isArmorSlot()) { 11 + throw new IllegalArgumentException("Invalid slot type: " + slot); 12 12 } 13 - return player.getInventory().getArmorStack(slotIndex); 13 + 14 + return player.getEquippedStack(slot); 14 15 } 15 16 16 - @Override 17 17 public int getPieces(ClientPlayerEntity player) { 18 - return player.getInventory().armor.size(); 18 + int armorCount = 0; 19 + 20 + for (EquipmentSlot slot : EquipmentSlot.values()) { 21 + if (slot.isArmorSlot()) { 22 + if (!player.getEquippedStack(slot).isEmpty()) { 23 + armorCount++; 24 + } 25 + } 26 + } 27 + 28 + return armorCount; 19 29 } 20 30 }