2121import java .util .Locale ;
2222import java .util .Set ;
2323import java .util .UUID ;
24+ import java .util .LinkedHashSet ;
2425import net .minecraft .client .gui .screens .Screen ;
2526import net .minecraft .client .player .LocalPlayer ;
2627import net .minecraft .core .BlockPos ;
28+ import net .minecraft .core .Holder ;
29+ import net .minecraft .core .component .DataComponents ;
2730import net .minecraft .world .entity .Entity ;
2831import net .minecraft .world .entity .item .ItemEntity ;
2932import net .minecraft .world .entity .ExperienceOrb ;
3639import net .minecraft .world .InteractionHand ;
3740import net .minecraft .world .item .ItemStack ;
3841import net .minecraft .world .item .Items ;
42+ import net .minecraft .world .item .enchantment .Enchantment ;
43+ import net .minecraft .world .item .enchantment .ItemEnchantments ;
3944import net .minecraft .world .level .block .entity .SignBlockEntity ;
4045import net .minecraft .world .level .block .entity .SignText ;
4146import net .minecraft .world .phys .Vec3 ;
5560import com .google .gson .JsonElement ;
5661import com .google .gson .JsonNull ;
5762import com .google .gson .JsonObject ;
63+ import it .unimi .dsi .fastutil .objects .Object2IntMap ;
5864// no screen import needed; we embed ItemESP's editor component directly
5965import net .wurstclient .util .InventoryUtils ;
6066import net .wurstclient .util .chunk .ChunkUtils ;
@@ -118,6 +124,11 @@ public class ItemHandlerHack extends Hack
118124 private final CheckboxSetting showRegistryName =
119125 new CheckboxSetting ("Show registry names" , false );
120126
127+ private final CheckboxSetting showEnchantmentsInNames =
128+ new CheckboxSetting ("Show enchantments in names" ,
129+ "Shows enchantments on the second line in ItemHandler HUD and GUI." ,
130+ false );
131+
121132 // How many items to show in the popup HUD
122133 private final SliderSetting popupMaxItems = new SliderSetting (
123134 "Popup HUD max items" , 8 , 1 , 10 , 1 , ValueDisplay .INTEGER );
@@ -182,6 +193,7 @@ public ItemHandlerHack()
182193 addSetting (new ButtonSetting ("Open ItemHandler GUI" , this ::openScreen ));
183194 addSetting (hudEnabled );
184195 addSetting (showRegistryName );
196+ addSetting (showEnchantmentsInNames );
185197 addSetting (includeMobEquipment );
186198 addSetting (filterDefaultMobEquipment );
187199 addSetting (respectItemEspIgnores );
@@ -561,7 +573,8 @@ private void scanNearbyItems()
561573
562574 private void scanNearbySigns ()
563575 {
564- if (!showSignsInHud .isChecked ())
576+ boolean guiOpen = MC .screen instanceof ItemHandlerScreen ;
577+ if (!showSignsInHud .isChecked () && !guiOpen )
565578 {
566579 trackedSigns .clear ();
567580 return ;
@@ -985,14 +998,26 @@ public List<NearbySign> getTrackedSigns()
985998 return List .copyOf (trackedSigns );
986999 }
9871000
1001+ public static String getSignTraceId (BlockPos pos )
1002+ {
1003+ if (pos == null )
1004+ return null ;
1005+ return "sign:" + pos .asLong ();
1006+ }
1007+
9881008 public boolean isShowSignsInHud ()
9891009 {
9901010 return showSignsInHud .isChecked ();
9911011 }
9921012
9931013 public record NearbySign (BlockPos pos , ItemStack icon , String text ,
9941014 double distance )
995- {}
1015+ {
1016+ public String traceId ()
1017+ {
1018+ return getSignTraceId (pos );
1019+ }
1020+ }
9961021
9971022 public boolean isHudEnabled ()
9981023 {
@@ -1063,6 +1088,11 @@ public boolean isShowRegistryName()
10631088 return showRegistryName .isChecked ();
10641089 }
10651090
1091+ public boolean isShowEnchantmentsInNames ()
1092+ {
1093+ return showEnchantmentsInNames .isChecked ();
1094+ }
1095+
10661096 public record GroundItem (int entityId , UUID uuid , ItemStack stack ,
10671097 double distance , Vec3 position , SourceType sourceType ,
10681098 String sourceName )
@@ -1084,6 +1114,8 @@ public String traceId()
10841114 int xp = net .wurstclient .util .ItemUtils .getXpAmount (stack );
10851115 return baseId + ":xp:" + xp ;
10861116 }
1117+ if (sourceType == SourceType .ITEM_FRAME )
1118+ return baseId + ":item_frame" ;
10871119 return baseId ;
10881120 }
10891121
@@ -1104,6 +1136,7 @@ public String displayName()
11041136 if (name == null || name .isBlank ())
11051137 name = net .minecraft .core .registries .BuiltInRegistries .ITEM
11061138 .getKey (stack .getItem ()).getPath ();
1139+
11071140 String label = sourceLabel ();
11081141 if (label == null || label .isBlank ())
11091142 return name ;
@@ -1163,6 +1196,22 @@ public void onRender(PoseStack matrixStack, float partialTicks)
11631196 if (shouldDrawTracers )
11641197 ends .add (new RenderUtils .ColoredPoint (p , 0 ));
11651198 }
1199+
1200+ for (NearbySign sign : trackedSigns )
1201+ {
1202+ if (sign == null || sign .pos () == null )
1203+ continue ;
1204+ String traceId = sign .traceId ();
1205+ boolean traced = traceId != null && isTraced (traceId );
1206+ if (!traced )
1207+ continue ;
1208+ BlockPos pos = sign .pos ();
1209+ Vec3 p = Vec3 .atCenterOf (pos );
1210+ if (shouldDrawBoxes )
1211+ boxes .add (new AABB (pos ));
1212+ if (shouldDrawTracers )
1213+ ends .add (new RenderUtils .ColoredPoint (p , 0 ));
1214+ }
11661215 boolean hasBoxes = shouldDrawBoxes && boxes != null && !boxes .isEmpty ();
11671216 boolean hasTracers =
11681217 shouldDrawTracers && ends != null && !ends .isEmpty ();
@@ -1263,4 +1312,35 @@ public java.util.Set<net.wurstclient.keybinds.PossibleKeybind> getPossibleKeybin
12631312 return java .util .Collections .emptySet ();
12641313 }
12651314 };
1315+
1316+ public String getEnchantmentSummary (ItemStack stack )
1317+ {
1318+ if (stack == null || stack .isEmpty ())
1319+ return "" ;
1320+
1321+ ArrayList <String > parts = new ArrayList <>();
1322+ LinkedHashSet <String > seen = new LinkedHashSet <>();
1323+ appendEnchantmentParts (parts , seen , stack
1324+ .getOrDefault (DataComponents .ENCHANTMENTS , ItemEnchantments .EMPTY ));
1325+ appendEnchantmentParts (parts , seen , stack .getOrDefault (
1326+ DataComponents .STORED_ENCHANTMENTS , ItemEnchantments .EMPTY ));
1327+ if (parts .isEmpty ())
1328+ return "" ;
1329+ return String .join (", " , parts );
1330+ }
1331+
1332+ private static void appendEnchantmentParts (List <String > out ,
1333+ Set <String > seen , ItemEnchantments enchantments )
1334+ {
1335+ for (Object2IntMap .Entry <Holder <Enchantment >> entry : enchantments
1336+ .entrySet ())
1337+ {
1338+ Holder <Enchantment > holder = entry .getKey ();
1339+ int level = entry .getIntValue ();
1340+ String key = holder .getRegisteredName () + "#" + level ;
1341+ if (!seen .add (key ))
1342+ continue ;
1343+ out .add (Enchantment .getFullname (holder , level ).getString ());
1344+ }
1345+ }
12661346}
0 commit comments