Skip to content

Commit cf7ff54

Browse files
committed
Updated Chest Search
1 parent eab9540 commit cf7ff54

3 files changed

Lines changed: 134 additions & 10 deletions

File tree

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,13 +8,15 @@
88
package net.wurstclient.clickgui.screens;
99

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

1213
import net.minecraft.client.gui.DrawContext;
1314
import net.minecraft.client.gui.screen.Screen;
1415
import net.minecraft.client.gui.widget.ButtonWidget;
1516
import net.minecraft.client.gui.widget.TextFieldWidget;
1617
import net.minecraft.text.Text;
1718
import net.minecraft.util.math.BlockPos;
19+
import net.minecraft.util.math.Vec3d;
1820
import net.wurstclient.WurstClient;
1921
import net.wurstclient.chestsearch.ChestManager;
2022
import net.wurstclient.chestsearch.ChestEntry;
@@ -34,6 +36,9 @@ public final class ChestSearchScreen extends Screen
3436
private int totalChestsLogged = 0;
3537
private long totalItemsLogged = 0;
3638
private int totalMatches = 0;
39+
private boolean radiusFilterActive = false;
40+
private int radiusLimitBlocks = Integer.MAX_VALUE;
41+
private int radiusFilteredOut = 0;
3742
private boolean limitedResults = false;
3843
private double scrollOffset = 0.0;
3944
private ButtonWidget scrollUpButton;
@@ -70,6 +75,18 @@ private static String normalizeDimension(String dimension)
7075
return dimension == null ? "" : dimension;
7176
}
7277

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

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

9081013
if(shown == 0)
9091014
{

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)