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: updated armorAccessor implementation and bumped version

+79 -38
+1 -1
gradle.properties
··· 9 9 loom_version=1.16-SNAPSHOT 10 10 11 11 # Mod Properties 12 - mod_version=1.9.0 12 + mod_version=1.9.1 13 13 maven_group=com.armorhud 14 14 archives_base_name=simple-armor-hud 15 15
+6 -3
src/client/java/com/armorhud/armor/ArmorAccessor.java
··· 1 1 package com.armorhud.armor; 2 2 3 3 import net.minecraft.client.player.LocalPlayer; 4 - import net.minecraft.world.entity.EquipmentSlot; 5 4 import net.minecraft.world.item.ItemStack; 5 + 6 + import java.util.List; 6 7 7 8 public interface ArmorAccessor { 8 9 9 - default void initialize(LocalPlayer player) { 10 + default void initialize(LocalPlayer player) { } 11 + default String getName() { 12 + return this.getClass().getSimpleName(); 10 13 } 11 14 12 - ItemStack getArmorPiece(LocalPlayer player, EquipmentSlot slot); 15 + List<ItemStack> getArmorPieces(LocalPlayer player); 13 16 }
+30
src/client/java/com/armorhud/armor/CombinedArmorAccessor.java
··· 1 + package com.armorhud.armor; 2 + 3 + import net.minecraft.client.player.LocalPlayer; 4 + import net.minecraft.world.item.ItemStack; 5 + 6 + import java.util.ArrayList; 7 + import java.util.List; 8 + 9 + public class CombinedArmorAccessor implements ArmorAccessor { 10 + private final List<ArmorAccessor> accessors = new ArrayList<>(); 11 + 12 + public void addAccessor(ArmorAccessor accessor) { 13 + accessors.add(accessor); 14 + } 15 + 16 + public List<ArmorAccessor> getAccessors() { 17 + return accessors; 18 + } 19 + 20 + @Override 21 + public List<ItemStack> getArmorPieces(LocalPlayer player) { 22 + List<ItemStack> armorList = new ArrayList<>(); 23 + 24 + for ( ArmorAccessor accessor : accessors ) { 25 + armorList.addAll(accessor.getArmorPieces(player)); 26 + } 27 + 28 + return armorList; 29 + } 30 + }
+17 -4
src/client/java/com/armorhud/armor/VanillaArmorAccessor.java
··· 4 4 import net.minecraft.world.entity.EquipmentSlot; 5 5 import net.minecraft.world.item.ItemStack; 6 6 7 + import java.util.ArrayList; 8 + import java.util.List; 9 + 7 10 public class VanillaArmorAccessor implements ArmorAccessor { 8 11 9 - public ItemStack getArmorPiece(LocalPlayer player, EquipmentSlot slot) { 10 - if (!slot.isArmor()) { 11 - throw new IllegalArgumentException("Invalid slot type: " + slot); 12 + @Override 13 + public String getName() { 14 + return "Vanilla"; 15 + } 16 + 17 + @Override 18 + public List<ItemStack> getArmorPieces(LocalPlayer player) { 19 + List<ItemStack> armorList = new ArrayList<>(); 20 + 21 + for ( EquipmentSlot slot : EquipmentSlot.values() ) { 22 + if ( slot.isArmor() ) { 23 + armorList.add(player.getItemBySlot(slot)); 24 + } 12 25 } 13 26 14 - return player.getItemBySlot(slot); 27 + return armorList; 15 28 } 16 29 }
+13 -3
src/client/java/com/armorhud/armorHud.java
··· 1 1 package com.armorhud; 2 2 3 3 import com.armorhud.armor.ArmorAccessor; 4 + import com.armorhud.armor.CombinedArmorAccessor; 4 5 import com.armorhud.armor.VanillaArmorAccessor; 5 6 import com.armorhud.config.config; 6 7 import com.armorhud.util.armorHudRegistries; ··· 9 10 import org.slf4j.Logger; 10 11 import org.slf4j.LoggerFactory; 11 12 13 + import java.util.stream.Collectors; 14 + 12 15 public class armorHud implements ClientModInitializer { 13 16 14 17 public static final Logger LOGGER = LoggerFactory.getLogger("simple-armor-hud"); 15 18 public static final config CONFIG = new config(); 16 - private static ArmorAccessor armorAccessor; 19 + private static CombinedArmorAccessor armorAccessor; 17 20 18 21 @Override 19 22 public void onInitializeClient() { 20 23 LOGGER.info("Simple Armor Hud loaded!"); 21 - armorAccessor = new VanillaArmorAccessor(); 24 + armorAccessor = new CombinedArmorAccessor(); 25 + armorAccessor.addAccessor(new VanillaArmorAccessor()); 26 + 22 27 CONFIG.load(); 23 28 armorHudRegistries.registerArmorHud(); 24 29 handleKeys(); 25 30 26 - 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); 27 37 } 28 38 29 39 public void handleKeys() {
+12 -19
src/client/java/com/armorhud/mixin/client/armorHudMixin.java
··· 8 8 import net.minecraft.client.gui.Gui; 9 9 import net.minecraft.client.AttackIndicatorStatus; 10 10 import net.minecraft.client.DeltaTracker; 11 - import net.minecraft.world.entity.EquipmentSlot; 12 11 import net.minecraft.world.entity.LivingEntity; 13 12 import net.minecraft.world.entity.player.Player; 14 13 import net.minecraft.world.item.ItemStack; ··· 19 18 import org.spongepowered.asm.mixin.injection.At; 20 19 import org.spongepowered.asm.mixin.injection.Inject; 21 20 import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 21 + 22 + import java.util.List; 22 23 23 24 @Mixin(Gui.class) 24 25 public abstract class armorHudMixin { ··· 72 73 73 74 assert minecraft.player != null; 74 75 ArmorAccessor armorAccessor = armorHud.getArmorAccessor(); 75 - EquipmentSlot[] slots = EquipmentSlot.values(); 76 + List<ItemStack> armorPieces = armorAccessor.getArmorPieces(minecraft.player); 76 77 77 78 final int hungerWidth = 14; // Magic number to center 4 armor pieces 78 79 final int armorWidth = 15; 79 80 80 81 int emptyArmorSlots = 0; 81 - if (config.TRIM_EMPTY_SLOTS) { 82 - for (EquipmentSlot slot : slots) { 83 - if (slot.isArmor()) { 84 - ItemStack stack = armorAccessor.getArmorPiece(minecraft.player, slot); 85 - if (stack.isEmpty()) { 86 - emptyArmorSlots++; 87 - } 82 + if ( config.TRIM_EMPTY_SLOTS ) { 83 + for ( ItemStack stack : armorPieces ) { 84 + if ( stack.isEmpty() ) { 85 + emptyArmorSlots++; 88 86 } 89 87 } 90 88 } ··· 95 93 if (config.RTL) { 96 94 if ( config.TRIM_EMPTY_SLOTS ) { x -= (float) (( (float) armorWidth / 2 ) + 0.5); } 97 95 x += armorWidth; 98 - for ( int i = slots.length - 1; i > 0; i-- ) { 99 - EquipmentSlot slot = slots[i]; 100 - if (!slot.isArmor()) continue; 101 - ItemStack armor = armorAccessor.getArmorPiece(minecraft.player, slot); 96 + armorPieces = armorPieces.reversed(); 102 97 98 + for ( ItemStack armor : armorPieces ) { 103 99 if (config.TRIM_EMPTY_SLOTS && armor.isEmpty()) continue; 104 100 x -= armorWidth; 105 101 ··· 107 103 } 108 104 } else { 109 105 if ( config.TRIM_EMPTY_SLOTS ) { x += ( (float) hungerWidth / 2 ); } 110 - for ( EquipmentSlot slot : slots ) { 111 - if ( !slot.isArmor() ) continue; 112 - ItemStack armor = armorAccessor.getArmorPiece(minecraft.player, slot); 113 - 114 - if ( config.TRIM_EMPTY_SLOTS && armor.isEmpty() ) continue; 106 + for ( ItemStack armor : armorPieces ) { 107 + if (config.TRIM_EMPTY_SLOTS && armor.isEmpty()) continue; 115 108 x -= armorWidth; 116 109 117 110 renderArmorPiece(context, x, armorHeight, minecraft.player, armor); 118 - } 111 + } 119 112 } 120 113 } 121 114
-3
src/client/java/com/armorhud/mixin/client/inGameHudMixin.java
··· 4 4 import net.minecraft.client.gui.GuiGraphicsExtractor; 5 5 import net.minecraft.client.gui.Gui; 6 6 import net.minecraft.world.entity.player.Player; 7 - import org.jetbrains.annotations.Nullable; 8 7 import org.spongepowered.asm.mixin.Mixin; 9 - import org.spongepowered.asm.mixin.Shadow; 10 8 import org.spongepowered.asm.mixin.injection.At; 11 9 import org.spongepowered.asm.mixin.injection.Inject; 12 - import org.spongepowered.asm.mixin.injection.ModifyVariable; 13 10 import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 14 11 15 12 @Mixin(Gui.class)
-5
src/client/java/com/armorhud/util/modDetect.java
··· 1 1 package com.armorhud.util; 2 2 3 - // import com.armorhud.armor.TrinketsArmorAccessor; 4 3 import com.armorhud.armorHud; 5 4 import com.armorhud.config.config; 6 5 import net.fabricmc.loader.api.FabricLoader; ··· 16 15 config.DOUBLE_HOTBAR = true; 17 16 armorHud.LOGGER.info("Double hotbar found!"); 18 17 } 19 - // if (FabricLoader.getInstance().isModLoaded("trinkets")) { 20 - // armorHud.setArmorAccessor(new TrinketsArmorAccessor(armorHud.getArmorAccessor())); 21 - // armorHud.LOGGER.info("Trinkets found!"); 22 - // } 23 18 24 19 config.save(); 25 20 }