11package io .github .axolotlclient .modules .hud .gui .hud .item ;
22
3+ import io .github .axolotlclient .AxolotlclientConfig .options .BooleanOption ;
34import io .github .axolotlclient .AxolotlclientConfig .options .Option ;
45import io .github .axolotlclient .modules .hud .gui .entry .TextHudEntry ;
56import io .github .axolotlclient .modules .hud .util .DrawPosition ;
67import io .github .axolotlclient .modules .hud .util .ItemUtil ;
78import net .minecraft .client .util .math .MatrixStack ;
9+ import net .minecraft .enchantment .Enchantment ;
810import net .minecraft .item .ItemStack ;
911import net .minecraft .item .Items ;
12+ import net .minecraft .nbt .NbtList ;
1013import net .minecraft .util .Identifier ;
1114
1215import java .util .List ;
@@ -21,6 +24,8 @@ public class ArmorHud extends TextHudEntry {
2124
2225 public static final Identifier ID = new Identifier ("kronhud" , "armorhud" );
2326
27+ protected BooleanOption showProtLvl = new BooleanOption ("showProtectionLevel" , false );
28+
2429 public ArmorHud () {
2530 super (20 , 100 , true );
2631 }
@@ -32,8 +37,20 @@ public void renderComponent(MatrixStack matrices, float delta) {
3237 renderMainItem (matrices , client .player .getInventory ().getMainHandStack (), pos .x () + 2 , pos .y () + lastY );
3338 lastY = lastY - 20 ;
3439 for (int i = 0 ; i <= 3 ; i ++) {
35- ItemStack item = client .player .getInventory ().armor .get (i );
36- renderItem (matrices , item , pos .x () + 2 , lastY + pos .y ());
40+ ItemStack stack = client .player .getInventory ().getArmorStack (i ).copy ();
41+ if (showProtLvl .get () && stack .hasEnchantments ()) {
42+ NbtList nbtList = stack .getEnchantments ();
43+ if (nbtList != null ) {
44+ for (int k = 0 ; k < nbtList .size (); ++k ) {
45+ int enchantId = nbtList .getCompound (k ).getShort ("id" );
46+ int level = nbtList .getCompound (k ).getShort ("lvl" );
47+ if (enchantId == 0 && Enchantment .byRawId (enchantId ) != null ) {
48+ stack .setCount (level );
49+ }
50+ }
51+ }
52+ }
53+ renderItem (matrices , stack , pos .x () + 2 , lastY + pos .y ());
3754 lastY = lastY - 20 ;
3855 }
3956 }
@@ -85,7 +102,9 @@ public Identifier getId() {
85102
86103 @ Override
87104 public List <Option <?>> getConfigurationOptions () {
88- return super .getConfigurationOptions ();
105+ List <Option <?>> options = super .getConfigurationOptions ();
106+ options .add (showProtLvl );
107+ return options ;
89108 }
90109
91110}
0 commit comments