Skip to content

Commit 1a4a415

Browse files
committed
ChestSearch Update
1 parent 7b0609f commit 1a4a415

File tree

8 files changed

+440
-27
lines changed

8 files changed

+440
-27
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,16 @@ I have no other experience in the field of Minecraft and have never used any oth
108108
- Able to detect chest changes that you make, so adding or removing items instantly updates the JSON
109109
- Unable to detect chest changes that other players make
110110
- Able to delete entries
111+
- Able to determine and search for weapon/armor, potion and book enchantments
111112
- Visually search all scanned chests for content based on keywords
112113
- Create an ESP highlight of the chest that has your desired item or create a waypoint to track the chest down
113114
- Chests are auto-removed if it has been detected as broken/missing
114115
- Adjustable Waypoint and ESP timeout
115116
- Adjustable ESP and Waypoint colors
116117
- Adjustable search radius
118+
- Adjustable font size
117119

118-
![ChestSearch](https://i.imgur.com/o5DYBqR.png)
120+
![ChestSearch](https://i.imgur.com/fBF3YQ0.png) ![Search](https://i.imgur.com/uRvJi9c.png)
119121

120122
### Breadcrumbs
121123
- Leaves a line trail behind you (toggle-able/pause-able).

gradle.properties

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
# Done to increase the memory available to gradle.
2-
org.gradle.jvmargs=-Xmx2G
2+
org.gradle.daemon=true
33
org.gradle.parallel=true
4+
org.gradle.caching=true
45
org.gradle.configuration-cache=true
6+
org.gradle.jvmargs=-Xmx8G -Dfile.encoding=UTF-8
7+
org.gradle.user.home=D:\\GradleCacheLocal
8+
9+
510

611
# Fabric Properties
712
# check these at https://fabricmc.net/develop/ and

src/main/java/net/wurstclient/chestsearch/ChestDatabase.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,34 @@ public synchronized List<ChestEntry> search(String query)
199199
if(!matched && item.nbt != null
200200
&& item.nbt.toString().toLowerCase().contains(q))
201201
matched = true;
202+
// Also match extracted enchantment and potion ids collected
203+
// by the recorder so searches like "sharpness" or "speed"
204+
// will find chests containing those effects.
205+
if(!matched && item.enchantments != null)
206+
{
207+
for(String en : item.enchantments)
208+
{
209+
if(en != null && en.toLowerCase().contains(q))
210+
{
211+
matched = true;
212+
break;
213+
}
214+
}
215+
}
216+
if(!matched && item.potionEffects != null)
217+
{
218+
for(String pe : item.potionEffects)
219+
{
220+
if(pe != null && pe.toLowerCase().contains(q))
221+
{
222+
matched = true;
223+
break;
224+
}
225+
}
226+
}
227+
if(!matched && item.primaryPotion != null
228+
&& item.primaryPotion.toLowerCase().contains(q))
229+
matched = true;
202230
}
203231
if(matched)
204232
res.add(e);

src/main/java/net/wurstclient/chestsearch/ChestEntry.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,24 @@ public static class ItemEntry
3636
public String displayName;
3737
/** Full ItemStack NBT if configured; stored as a JsonObject */
3838
public JsonElement nbt;
39+
/**
40+
* Optional list of enchantment ids/paths (e.g. "sharpness") extracted
41+
* when recording.
42+
*/
43+
public java.util.List<String> enchantments;
44+
/**
45+
* Optional parallel list of enchantment levels matching the
46+
* enchantments
47+
* list. Same length as enchantments when present.
48+
*/
49+
public java.util.List<Integer> enchantmentLevels;
50+
/**
51+
* Optional list of potion/effect ids/paths (e.g. "speed") extracted
52+
* when recording.
53+
*/
54+
public java.util.List<String> potionEffects;
55+
/** Optional primary potion/effect name for quick categorization. */
56+
public String primaryPotion;
3957
}
4058

4159
public ChestEntry()

src/main/java/net/wurstclient/chestsearch/ChestRecorder.java

Lines changed: 101 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@
1414
import net.minecraft.screen.ScreenHandlerListener;
1515
import net.minecraft.util.math.BlockPos;
1616
import net.wurstclient.clickgui.screens.ChestSearchScreen;
17+
import net.minecraft.enchantment.Enchantment;
18+
import net.minecraft.enchantment.EnchantmentHelper;
19+
import it.unimi.dsi.fastutil.objects.Object2IntMap;
20+
import net.minecraft.registry.entry.RegistryEntry;
21+
import java.util.Set;
22+
import net.minecraft.component.type.PotionContentsComponent;
23+
import net.minecraft.component.DataComponentTypes;
24+
import net.minecraft.entity.effect.StatusEffectInstance;
25+
import net.minecraft.entity.effect.StatusEffect;
26+
import net.minecraft.util.Identifier;
1727

1828
import java.io.File;
1929
import java.util.ArrayList;
@@ -23,9 +33,6 @@
2333
import java.util.Timer;
2434
import java.util.TimerTask;
2535

26-
/**
27-
* Captures chest contents whenever a container screen opens.
28-
*/
2936
public class ChestRecorder
3037
{
3138
private final ChestManager manager;
@@ -347,6 +354,88 @@ private void recordFromStacksInternal(String serverIp, String dimension,
347354
{
348355
it.nbt = null;
349356
}
357+
// Extract enchantment ids and potion/effect ids from the actual
358+
// ItemStack where possible. This allows searching by enchantment
359+
// or potion even if the textual NBT is not easily searchable.
360+
try
361+
{
362+
// Enchantments (including enchanted books)
363+
try
364+
{
365+
Set<Object2IntMap.Entry<RegistryEntry<Enchantment>>> enchSet =
366+
EnchantmentHelper.getEnchantments(copy)
367+
.getEnchantmentEntries();
368+
if(enchSet != null && !enchSet.isEmpty())
369+
{
370+
it.enchantments = new java.util.ArrayList<>();
371+
it.enchantmentLevels = new java.util.ArrayList<>();
372+
for(Object2IntMap.Entry<RegistryEntry<Enchantment>> e : enchSet)
373+
{
374+
RegistryEntry<Enchantment> ren = e.getKey();
375+
if(ren == null)
376+
continue;
377+
Identifier id = ren.getKey().map(k -> k.getValue())
378+
.orElse(null);
379+
String idStr = id != null ? id.toString()
380+
: ren.getIdAsString();
381+
int lvl = e.getIntValue();
382+
if(idStr != null && !idStr.isBlank())
383+
{
384+
it.enchantments.add(idStr);
385+
it.enchantmentLevels.add(Integer.valueOf(lvl));
386+
}
387+
}
388+
}
389+
}catch(Throwable ignored)
390+
{}
391+
392+
// Potions / effects
393+
try
394+
{
395+
PotionContentsComponent potionContents =
396+
copy.getComponents().getOrDefault(
397+
DataComponentTypes.POTION_CONTENTS,
398+
PotionContentsComponent.DEFAULT);
399+
if(potionContents != null)
400+
{
401+
java.util.List<String> pe = new java.util.ArrayList<>();
402+
for(StatusEffectInstance sei : potionContents
403+
.getEffects())
404+
{
405+
RegistryEntry<StatusEffect> effEntry =
406+
sei.getEffectType();
407+
Identifier id = effEntry.getKey()
408+
.map(k -> k.getValue()).orElse(null);
409+
String idStr = id != null ? id.toString()
410+
: effEntry.getIdAsString();
411+
if(idStr != null && !idStr.isBlank())
412+
pe.add(idStr);
413+
}
414+
if(!pe.isEmpty())
415+
{
416+
it.potionEffects = pe;
417+
it.primaryPotion = pe.get(0);
418+
}else
419+
{
420+
// fallback to base potion id
421+
java.util.Optional<net.minecraft.registry.entry.RegistryEntry<net.minecraft.potion.Potion>> basePotion =
422+
potionContents.potion();
423+
if(basePotion.isPresent())
424+
{
425+
Identifier id = basePotion.get().getKey()
426+
.map(k -> k.getValue()).orElse(null);
427+
String idStr = id != null ? id.toString()
428+
: basePotion.get().getIdAsString();
429+
it.primaryPotion = idStr;
430+
}
431+
}
432+
}
433+
}catch(Throwable ignored)
434+
{}
435+
}catch(Throwable ignored)
436+
{
437+
// ignore extraction errors
438+
}
350439
items.add(it);
351440
}
352441

@@ -414,4 +503,13 @@ private void recordFromStacksInternal(String serverIp, String dimension,
414503
}
415504
}
416505

506+
private static String sanitizePath(String raw)
507+
{
508+
if(raw == null || raw.isEmpty())
509+
return "";
510+
int colon = raw.indexOf(':');
511+
return colon >= 0 && colon + 1 < raw.length() ? raw.substring(colon + 1)
512+
: raw;
513+
}
514+
417515
}

0 commit comments

Comments
 (0)