88package net .wurstclient .clickgui .screens ;
99
1010import java .util .ArrayList ;
11+ import java .util .Locale ;
1112
1213import net .minecraft .client .gui .DrawContext ;
1314import net .minecraft .client .gui .screen .Screen ;
1415import net .minecraft .client .gui .widget .ButtonWidget ;
1516import net .minecraft .client .gui .widget .TextFieldWidget ;
1617import net .minecraft .text .Text ;
1718import net .minecraft .util .math .BlockPos ;
19+ import net .minecraft .util .math .Vec3d ;
1820import net .wurstclient .WurstClient ;
1921import net .wurstclient .chestsearch .ChestManager ;
2022import 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 {
0 commit comments