Skip to content

Commit f5d714b

Browse files
committed
Updated Chest Search
1 parent 48bab95 commit f5d714b

File tree

3 files changed

+134
-10
lines changed

3 files changed

+134
-10
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ All credit for the original client goes to Wurst-Imperium and its contributors.
105105
- Chests are auto-removed if it has been detected as broken/missing
106106
- Adjustable Waypoint and ESP timeout
107107
- Adjustable ESP and Waypoint colors
108+
- Adjustable search radius
108109

109110
![ChestSearch](https://i.imgur.com/o5DYBqR.png)
110111

src/main/java/net/wurstclient/clickgui/screens/ChestSearchScreen.java

Lines changed: 114 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package net.wurstclient.clickgui.screens;
99

1010
import java.util.ArrayList;
11+
import java.util.Locale;
1112

1213
import net.minecraft.client.gui.Click;
1314
import net.minecraft.client.gui.DrawContext;
@@ -16,6 +17,7 @@
1617
import net.minecraft.client.gui.widget.TextFieldWidget;
1718
import net.minecraft.text.Text;
1819
import net.minecraft.util.math.BlockPos;
20+
import net.minecraft.util.math.Vec3d;
1921
import net.wurstclient.WurstClient;
2022
import net.wurstclient.chestsearch.ChestManager;
2123
import net.wurstclient.chestsearch.ChestEntry;
@@ -35,6 +37,9 @@ public final class ChestSearchScreen extends Screen
3537
private int totalChestsLogged = 0;
3638
private long totalItemsLogged = 0;
3739
private int totalMatches = 0;
40+
private boolean radiusFilterActive = false;
41+
private int radiusLimitBlocks = Integer.MAX_VALUE;
42+
private int radiusFilteredOut = 0;
3843
private boolean limitedResults = false;
3944
private double scrollOffset = 0.0;
4045
private ButtonWidget scrollUpButton;
@@ -71,6 +76,18 @@ private static String normalizeDimension(String dimension)
7176
return dimension == null ? "" : dimension;
7277
}
7378

79+
private static String canonicalDimension(String dimension)
80+
{
81+
String dim = normalizeDimension(dimension).trim();
82+
if(dim.isEmpty())
83+
return "";
84+
String lower = dim.toLowerCase(Locale.ROOT);
85+
int colon = lower.indexOf(':');
86+
if(colon >= 0 && colon < lower.length() - 1)
87+
return lower.substring(colon + 1);
88+
return lower;
89+
}
90+
7491
private static String makePosKey(String dimension, BlockPos pos)
7592
{
7693
String dim = normalizeDimension(dimension);
@@ -297,8 +314,8 @@ private void onSearchChanged(String q)
297314
java.util.List<ChestEntry> ordered = new java.util.ArrayList<>();
298315
ordered.addAll(pinned);
299316
ordered.addAll(others);
300-
totalMatches = ordered.size();
301-
results = ordered;
317+
results = applyRadiusFilter(ordered);
318+
totalMatches = results.size();
302319
int maxResults = 50;
303320
try
304321
{
@@ -313,6 +330,78 @@ private void onSearchChanged(String q)
313330
rebuildRowButtons();
314331
}
315332

333+
private java.util.List<ChestEntry> applyRadiusFilter(
334+
java.util.List<ChestEntry> entries)
335+
{
336+
radiusFilterActive = false;
337+
radiusFilteredOut = 0;
338+
radiusLimitBlocks = Integer.MAX_VALUE;
339+
if(entries == null || entries.isEmpty())
340+
return entries;
341+
342+
net.minecraft.client.MinecraftClient mc = WurstClient.MC;
343+
if(mc == null || mc.player == null)
344+
return entries;
345+
346+
net.wurstclient.hacks.ChestSearchHack hack;
347+
try
348+
{
349+
hack = WurstClient.INSTANCE.getHax().chestSearchHack;
350+
}catch(Throwable ignored)
351+
{
352+
hack = null;
353+
}
354+
if(hack == null || hack.isDisplayRadiusUnlimited())
355+
return entries;
356+
357+
int radiusBlocks = hack.getDisplayRadius();
358+
if(radiusBlocks <= 0 || radiusBlocks >= Integer.MAX_VALUE)
359+
return entries;
360+
361+
radiusFilterActive = true;
362+
radiusLimitBlocks = radiusBlocks;
363+
double radiusSq = (double)radiusBlocks * (double)radiusBlocks;
364+
Vec3d playerPos =
365+
new Vec3d(mc.player.getX(), mc.player.getY(), mc.player.getZ());
366+
String playerDim = "";
367+
try
368+
{
369+
if(mc.world != null)
370+
playerDim = mc.world.getRegistryKey().getValue().toString();
371+
}catch(Throwable ignored)
372+
{}
373+
String playerDimKey = canonicalDimension(playerDim);
374+
375+
java.util.ArrayList<ChestEntry> filtered =
376+
new java.util.ArrayList<>(entries.size());
377+
int filteredOut = 0;
378+
for(ChestEntry entry : entries)
379+
{
380+
if(entry == null)
381+
continue;
382+
boolean include = true;
383+
String entryDimKey = canonicalDimension(entry.dimension);
384+
if(!entryDimKey.isEmpty() && !playerDimKey.isEmpty()
385+
&& !entryDimKey.equals(playerDimKey))
386+
include = false;
387+
388+
if(include)
389+
{
390+
BlockPos pos = entry.getClickedPos();
391+
Vec3d chestPos = Vec3d.ofCenter(pos);
392+
if(chestPos.squaredDistanceTo(playerPos) > radiusSq)
393+
include = false;
394+
}
395+
396+
if(include)
397+
filtered.add(entry);
398+
else
399+
filteredOut++;
400+
}
401+
radiusFilteredOut = filteredOut;
402+
return filtered;
403+
}
404+
316405
private void rebuildRowButtons()
317406
{
318407
for(ButtonWidget btn : rowButtons)
@@ -705,8 +794,6 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta)
705794
int sfY = 18;
706795
context.fill(sfX - 2, sfY - 2, sfX + 222, sfY + 22, 0xFF333333);
707796
int summaryY = sfY + 24;
708-
context.fill(sfX - 2, summaryY - 2, sfX + 360, summaryY + 18,
709-
0xFF222222);
710797
// draw result panels BEFORE super.render so buttons draw on top
711798
int x = this.width / 2 - 150;
712799
int visibleTop = getResultsTop();
@@ -904,11 +991,29 @@ else if(scrollOffset > maxScroll)
904991
? " (showing first " + WurstClient.INSTANCE.getHax().chestSearchHack
905992
.getMaxSearchResults() + ")"
906993
: "";
907-
String summary =
908-
"Showing " + shown + "/" + totalMatches + limiter + " - Tracking "
909-
+ totalChestsLogged + " chests, " + totalItemsLogged + " items";
910-
context.drawText(this.textRenderer, Text.literal(summary), sfX,
911-
summaryY + 2, 0xFFCCCCCC, false);
994+
java.util.ArrayList<String> summaryExtras = new java.util.ArrayList<>();
995+
if(radiusFilterActive && radiusLimitBlocks < Integer.MAX_VALUE)
996+
summaryExtras.add("radius <= " + radiusLimitBlocks + " blocks");
997+
if(radiusFilterActive && radiusFilteredOut > 0)
998+
summaryExtras.add(radiusFilteredOut + " outside radius");
999+
String extra = summaryExtras.isEmpty() ? ""
1000+
: " (" + String.join(", ", summaryExtras) + ")";
1001+
String summary = "Showing " + shown + "/" + totalMatches + limiter
1002+
+ extra + " - Tracking " + totalChestsLogged + " chests, "
1003+
+ totalItemsLogged + " items";
1004+
int summaryPadding = 8;
1005+
int summaryWidth =
1006+
this.textRenderer.getWidth(summary) + summaryPadding * 2;
1007+
if(summaryWidth > this.width - 4)
1008+
summaryWidth = this.width - 4;
1009+
int summaryHalf = summaryWidth / 2;
1010+
int summaryCenter = this.width / 2;
1011+
int summaryLeft = Math.max(0, summaryCenter - summaryHalf);
1012+
int summaryRight = Math.min(this.width, summaryCenter + summaryHalf);
1013+
context.fill(summaryLeft, summaryY - 2, summaryRight, summaryY + 18,
1014+
0xFF222222);
1015+
context.drawCenteredTextWithShadow(this.textRenderer,
1016+
Text.literal(summary), this.width / 2, summaryY + 2, 0xFFCCCCCC);
9121017

9131018
if(shown == 0)
9141019
{

src/main/java/net/wurstclient/hacks/ChestSearchHack.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99

1010
import net.wurstclient.Category;
1111
import net.wurstclient.hack.Hack;
12+
import net.wurstclient.settings.ColorSetting;
1213
import net.wurstclient.settings.SliderSetting;
1314
import net.wurstclient.settings.SliderSetting.ValueDisplay;
14-
import net.wurstclient.settings.ColorSetting;
1515

1616
public final class ChestSearchHack extends Hack
1717
{
18+
private static final int DISPLAY_RADIUS_UNLIMITED = 2001;
19+
1820
private final net.wurstclient.settings.CheckboxSetting automaticMode =
1921
new net.wurstclient.settings.CheckboxSetting("Automatic mode",
2022
"Automatically scan chests on open.", true);
@@ -29,6 +31,10 @@ public final class ChestSearchHack extends Hack
2931
"Cleaner scan radius", 64, 8, 512, 8, ValueDisplay.INTEGER);
3032
private final SliderSetting maxResults = new SliderSetting(
3133
"Max search results", 50, 10, 1000, 10, ValueDisplay.INTEGER);
34+
private final SliderSetting displayRadius = new SliderSetting(
35+
"Display radius", DISPLAY_RADIUS_UNLIMITED, 1, DISPLAY_RADIUS_UNLIMITED,
36+
1, ValueDisplay.INTEGER.withSuffix(" blocks")
37+
.withLabel(DISPLAY_RADIUS_UNLIMITED, "Unlimited"));
3238
private final ColorSetting waypointColor =
3339
new ColorSetting("Waypoint color", new java.awt.Color(0xFFFF00));
3440
private final ColorSetting espFillColor =
@@ -49,6 +55,7 @@ public ChestSearchHack()
4955
addSetting(gracePeriodSec);
5056
addSetting(scanRadius);
5157
addSetting(maxResults);
58+
addSetting(displayRadius);
5259
addSetting(waypointColor);
5360
addSetting(espFillColor);
5461
addSetting(espLineColor);
@@ -69,6 +76,17 @@ public int getMaxSearchResults()
6976
return maxResults.getValueI();
7077
}
7178

79+
public boolean isDisplayRadiusUnlimited()
80+
{
81+
return displayRadius.getValueI() >= DISPLAY_RADIUS_UNLIMITED;
82+
}
83+
84+
public int getDisplayRadius()
85+
{
86+
return isDisplayRadiusUnlimited() ? Integer.MAX_VALUE
87+
: displayRadius.getValueI();
88+
}
89+
7290
public int getWaypointTimeMs()
7391
{
7492
return (int)(waypointTimeSec.getValue() * 1000);

0 commit comments

Comments
 (0)