Skip to content

Commit a8ab177

Browse files
committed
Updated ItemHandler (Default Items Filter)
1 parent 2a07fec commit a8ab177

2 files changed

Lines changed: 68 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ Reports number of waypoints changed.
382382
- Respects ItemESP ignored list (optional) and provides link to edit the list.
383383
- Detects XP Orbs and shows the exact XP each orb will give
384384
- Optionally detects items held or worn by mobs (Item count will be for all mobs in the area)
385+
- Can also filter out default mob items to prevent spam
385386

386387
![Popup](https://i.imgur.com/VQw20x0.png)
387388
![GUI](https://i.imgur.com/oZFLufE.png)

src/main/java/net/wurstclient/hacks/itemhandler/ItemHandlerHack.java

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.Deque;
2020
import java.util.List;
2121
import java.util.Locale;
22+
import java.util.Set;
2223
import java.util.UUID;
2324
import net.minecraft.client.gui.screens.Screen;
2425
import net.minecraft.client.player.LocalPlayer;
@@ -62,6 +63,30 @@ public class ItemHandlerHack extends Hack
6263
// and avoids pathological behavior.
6364
private static final double INFINITE_SCAN_RADIUS = 1024.0;
6465
private static final int WHITELIST_TICKS = 3;
66+
private static final Set<String> DEFAULT_MOB_EQUIPMENT_IDS =
67+
Set.of("minecraft:bow", "minecraft:crossbow", "minecraft:trident",
68+
"minecraft:wooden_sword", "minecraft:stone_sword",
69+
"minecraft:iron_sword", "minecraft:golden_sword",
70+
"minecraft:wooden_axe", "minecraft:stone_axe", "minecraft:iron_axe",
71+
"minecraft:golden_axe", "minecraft:wooden_pickaxe",
72+
"minecraft:stone_pickaxe", "minecraft:iron_pickaxe",
73+
"minecraft:golden_pickaxe", "minecraft:wooden_shovel",
74+
"minecraft:stone_shovel", "minecraft:iron_shovel",
75+
"minecraft:golden_shovel", "minecraft:wooden_hoe",
76+
"minecraft:stone_hoe", "minecraft:iron_hoe", "minecraft:golden_hoe",
77+
"minecraft:leather_helmet", "minecraft:leather_chestplate",
78+
"minecraft:leather_leggings", "minecraft:leather_boots",
79+
"minecraft:chainmail_helmet", "minecraft:chainmail_chestplate",
80+
"minecraft:chainmail_leggings", "minecraft:chainmail_boots",
81+
"minecraft:iron_helmet", "minecraft:iron_chestplate",
82+
"minecraft:iron_leggings", "minecraft:iron_boots",
83+
"minecraft:golden_helmet", "minecraft:golden_chestplate",
84+
"minecraft:golden_leggings", "minecraft:golden_boots");
85+
private static final String[] DEFAULT_MOB_EQUIPMENT_MATERIALS =
86+
{"copper", "steel", "gold", "golden"};
87+
private static final String[] DEFAULT_MOB_EQUIPMENT_SUFFIXES =
88+
{"_helmet", "_chestplate", "_leggings", "_boots", "_sword", "_axe",
89+
"_pickaxe", "_shovel", "_hoe", "_spear"};
6590

6691
private final List<GroundItem> trackedItems = new ArrayList<>();
6792
private final Int2IntOpenHashMap pickupWhitelist = new Int2IntOpenHashMap();
@@ -105,9 +130,13 @@ public class ItemHandlerHack extends Hack
105130

106131
// Include items held or worn by mobs
107132
private final CheckboxSetting includeMobEquipment =
108-
new CheckboxSetting("Detect mob equipment",
133+
new CheckboxSetting("Detect held/worn mob items",
109134
"Also detect items held or worn by mobs.", false);
110135

136+
private final CheckboxSetting filterDefaultMobEquipment =
137+
new CheckboxSetting("Filter default mob items",
138+
"Hide common mob gear (gold/iron/stone/chain/etc).", false);
139+
111140
// Reduce extremes so offsets cannot go off-screen entirely.
112141
private final SliderSetting hudOffsetX = new SliderSetting(
113142
"Popup HUD offset X", -105, -300, 300, 1, ValueDisplay.INTEGER);
@@ -125,6 +154,7 @@ public ItemHandlerHack()
125154
addSetting(hudEnabled);
126155
addSetting(showRegistryName);
127156
addSetting(includeMobEquipment);
157+
addSetting(filterDefaultMobEquipment);
128158
addSetting(respectItemEspIgnores);
129159
addSetting(itemEspIgnoredListSetting);
130160
addSetting(rejectRadius);
@@ -502,6 +532,39 @@ private boolean shouldTrack(ItemEntity entity)
502532
&& !entity.getItem().isEmpty();
503533
}
504534

535+
private boolean shouldTrackMobEquipment(ItemStack stack)
536+
{
537+
if(stack == null || stack.isEmpty())
538+
return false;
539+
if(isIgnoredByItemEsp(stack))
540+
return false;
541+
return !filterDefaultMobEquipment.isChecked()
542+
|| !isDefaultMobEquipment(stack);
543+
}
544+
545+
private boolean isDefaultMobEquipment(ItemStack stack)
546+
{
547+
if(stack == null || stack.isEmpty())
548+
return false;
549+
String id = net.minecraft.core.registries.BuiltInRegistries.ITEM
550+
.getKey(stack.getItem()).toString();
551+
if(DEFAULT_MOB_EQUIPMENT_IDS.contains(id))
552+
return true;
553+
String path = net.minecraft.core.registries.BuiltInRegistries.ITEM
554+
.getKey(stack.getItem()).getPath();
555+
for(String material : DEFAULT_MOB_EQUIPMENT_MATERIALS)
556+
{
557+
if(!path.contains(material))
558+
continue;
559+
for(String suffix : DEFAULT_MOB_EQUIPMENT_SUFFIXES)
560+
{
561+
if(path.endsWith(suffix))
562+
return true;
563+
}
564+
}
565+
return false;
566+
}
567+
505568
private void addMobEquipmentItems(LocalPlayer player, double scanRadius)
506569
{
507570
if(player == null || MC.level == null)
@@ -522,14 +585,14 @@ private void addMobEquipmentItems(LocalPlayer player, double scanRadius)
522585
String mobName = le.getName().getString();
523586

524587
ItemStack main = le.getMainHandItem();
525-
if(main != null && !main.isEmpty() && !isIgnoredByItemEsp(main))
588+
if(shouldTrackMobEquipment(main))
526589
{
527590
Vec3 pos = getHeldItemPos(le, InteractionHand.MAIN_HAND);
528591
addMobTrackedItem(le, main, pos, SourceType.MOB_HELD, mobName);
529592
}
530593

531594
ItemStack off = le.getOffhandItem();
532-
if(off != null && !off.isEmpty() && !isIgnoredByItemEsp(off))
595+
if(shouldTrackMobEquipment(off))
533596
{
534597
Vec3 pos = getHeldItemPos(le, InteractionHand.OFF_HAND);
535598
addMobTrackedItem(le, off, pos, SourceType.MOB_HELD, mobName);
@@ -539,8 +602,7 @@ private void addMobEquipmentItems(LocalPlayer player, double scanRadius)
539602
EquipmentSlot.CHEST, EquipmentSlot.LEGS, EquipmentSlot.FEET})
540603
{
541604
ItemStack armor = le.getItemBySlot(slot);
542-
if(armor == null || armor.isEmpty()
543-
|| isIgnoredByItemEsp(armor))
605+
if(!shouldTrackMobEquipment(armor))
544606
continue;
545607
Vec3 pos = getArmorPos(le, slot);
546608
addMobTrackedItem(le, armor, pos, SourceType.MOB_WORN, mobName);

0 commit comments

Comments
 (0)