@@ -129,6 +129,7 @@ private enum SearchMode
129129 // Precomputed tracer endpoints
130130 private java .util .List <net .minecraft .util .math .Vec3d > tracerEnds ;
131131 private ChunkPos lastPlayerChunk ;
132+ private int lastMatchesVersion ;
132133
133134 private SearchMode lastMode ;
134135 private int lastListHash ;
@@ -200,6 +201,7 @@ protected void onEnable()
200201 lastMode = mode .getSelected ();
201202 lastListHash = blockList .getBlockNames ().hashCode ();
202203 applySearchCriteria (block .getBlock (), "" );
204+ lastMatchesVersion = coordinator .getMatchesVersion ();
203205 EVENTS .add (UpdateListener .class , this );
204206 EVENTS .add (PacketInputListener .class , coordinator );
205207 EVENTS .add (RenderListener .class , this );
@@ -213,7 +215,7 @@ protected void onDisable()
213215 EVENTS .remove (PacketInputListener .class , coordinator );
214216 EVENTS .remove (RenderListener .class , this );
215217 EVENTS .remove (CameraTransformViewBobbingListener .class , this );
216- stopBuildingBuffer ();
218+ stopBuildingBuffer (true );
217219 coordinator .reset ();
218220 forkJoinPool .shutdownNow ();
219221 if (vertexBuffer != null )
@@ -229,14 +231,13 @@ protected void onDisable()
229231 @ Override
230232 public void onUpdate ()
231233 {
232- boolean searchersChanged = false ;
233- // Mode/list changes
234234 SearchMode currentMode = mode .getSelected ();
235+
236+ // Mode/list changes
235237 if (currentMode != lastMode )
236238 {
237239 lastMode = currentMode ;
238240 applySearchCriteria (block .getBlock (), "" );
239- searchersChanged = true ;
240241 }
241242 if (currentMode == SearchMode .LIST )
242243 {
@@ -245,59 +246,61 @@ public void onUpdate()
245246 {
246247 lastListHash = listHash ;
247248 applySearchCriteria (block .getBlock (), "" );
248- searchersChanged = true ;
249249 }
250250 }
251+
251252 // Recenter per chunk when sticky is off
252253 ChunkPos currentChunk = new ChunkPos (MC .player .getBlockPos ());
253254 if (!stickyArea .isChecked () && !currentChunk .equals (lastPlayerChunk ))
254255 {
255256 lastPlayerChunk = currentChunk ;
256257 coordinator .reset ();
257- stopBuildingBuffer ();
258- searchersChanged = true ;
258+ stopBuildingBuffer (false );
259259 }
260+
260261 // Area changes
261262 ChunkAreaSetting .ChunkArea currentArea = area .getSelected ();
262263 if (currentArea != lastAreaSelection )
263264 {
264265 lastAreaSelection = currentArea ;
265266 coordinator .reset ();
266- searchersChanged = true ;
267+ stopBuildingBuffer (true );
268+ notify = true ;
267269 }
270+
268271 // Criteria changes only for modes that use them
269272 if (currentMode == SearchMode .BLOCK_ID )
270273 {
271274 Block currentBlock = block .getBlock ();
272275 if (currentBlock != lastBlock )
273- {
274276 applySearchCriteria (currentBlock , "" );
275- searchersChanged = true ;
276- }
277277 }else if (currentMode == SearchMode .QUERY )
278278 {
279279 String currentQuery = normalizeQuery (query .getValue ());
280280 if (!currentQuery .equals (lastQuery ))
281- {
282281 applySearchCriteria (block .getBlock (), currentQuery );
283- searchersChanged = true ;
284- }
285282 }
286- // Coordinator update
287- if (coordinator .update ())
288- searchersChanged = true ;
289- if (searchersChanged )
290- stopBuildingBuffer ();
291- if (!coordinator .isDone ())
292- return ;
283+
284+ // Update coordinator (adds/removes searchers, applies packet updates)
285+ coordinator .update ();
286+
287+ int matchesVersion = coordinator .getMatchesVersion ();
288+ if (matchesVersion != lastMatchesVersion )
289+ {
290+ lastMatchesVersion = matchesVersion ;
291+ stopBuildingBuffer (false );
292+ }
293293
294294 if (limit .getValueI () != prevLimit )
295295 {
296- stopBuildingBuffer ();
296+ stopBuildingBuffer (false );
297297 prevLimit = limit .getValueI ();
298298 notify = true ;
299299 }
300300
301+ if (!coordinator .hasReadyMatches ())
302+ return ;
303+
301304 if (getMatchingBlocksTask == null )
302305 startGetMatchingBlocksTask ();
303306
@@ -326,34 +329,31 @@ public void onCameraTransformViewBobbing(
326329 @ Override
327330 public void onRender (MatrixStack matrixStack , float partialTicks )
328331 {
329- if (vertexBuffer == null || bufferRegion == null )
330- {
331- if (style .hasLines () && tracerEnds != null && !tracerEnds .isEmpty ())
332- {
333- int color = useFixedColor .isChecked ()
334- ? net .wurstclient .util .RenderUtils
335- .toIntColor (fixedColor .getColorF (), 0.5F )
336- : net .wurstclient .util .RenderUtils .toIntColor (
337- net .wurstclient .util .RenderUtils .getRainbowColor (),
338- 0.5F );
339- net .wurstclient .util .RenderUtils .drawTracers (matrixStack ,
340- partialTicks , tracerEnds , color , false );
341- }
332+ boolean drawBoxes =
333+ style .hasBoxes () && vertexBuffer != null && bufferRegion != null ;
334+ boolean drawTracers =
335+ style .hasLines () && tracerEnds != null && !tracerEnds .isEmpty ();
336+
337+ if (!drawBoxes && !drawTracers )
342338 return ;
343- }
344- matrixStack .push ();
345- RenderUtils .applyRegionalRenderOffset (matrixStack , bufferRegion );
339+
346340 float [] rgb = useFixedColor .isChecked () ? fixedColor .getColorF ()
347341 : RenderUtils .getRainbowColor ();
348- vertexBuffer .draw (matrixStack , WurstRenderLayers .ESP_QUADS , rgb , 0.5F );
349- matrixStack .pop ();
350- if (style .hasLines () && tracerEnds != null && !tracerEnds .isEmpty ())
342+
343+ if (drawBoxes )
351344 {
352- int color = useFixedColor .isChecked ()
353- ? RenderUtils .toIntColor (fixedColor .getColorF (), 0.5F )
354- : RenderUtils .toIntColor (RenderUtils .getRainbowColor (), 0.5F );
345+ matrixStack .push ();
346+ RenderUtils .applyRegionalRenderOffset (matrixStack , bufferRegion );
347+ vertexBuffer .draw (matrixStack , WurstRenderLayers .ESP_QUADS , rgb ,
348+ 0.5F );
349+ matrixStack .pop ();
350+ }
351+
352+ if (drawTracers )
353+ {
354+ int tracerColor = RenderUtils .toIntColor (rgb , 0.5F );
355355 RenderUtils .drawTracers (matrixStack , partialTicks , tracerEnds ,
356- color , false );
356+ tracerColor , false );
357357 }
358358 }
359359
@@ -375,6 +375,8 @@ private String abbreviate(String text)
375375
376376 private void applySearchCriteria (Block currentBlock , String normalizedQuery )
377377 {
378+ stopBuildingBuffer (true );
379+
378380 switch (mode .getSelected ())
379381 {
380382 case LIST :
@@ -445,6 +447,7 @@ private void applySearchCriteria(Block currentBlock, String normalizedQuery)
445447 lastQuery = "" ;
446448 }
447449 notify = true ;
450+ lastMatchesVersion = coordinator .getMatchesVersion ();
448451 }
449452
450453 private boolean blockMatchesQuery (Block block , String normalizedQuery )
@@ -487,7 +490,7 @@ private void startGetMatchingBlocksTask()
487490 (a , b ) -> Integer .compare (b .getManhattanDistance (eyesPos ),
488491 a .getManhattanDistance (eyesPos )));
489492 java .util .Iterator <ChunkSearcher .Result > it =
490- coordinator .getMatches ().iterator ();
493+ coordinator .getReadyMatches ().iterator ();
491494 while (it .hasNext ())
492495 {
493496 ChunkSearcher .Result r = it .next ();
@@ -556,7 +559,7 @@ private void setBufferFromTask()
556559 }
557560 }
558561
559- private void stopBuildingBuffer ()
562+ private void stopBuildingBuffer (boolean discardCurrent )
560563 {
561564 if (getMatchingBlocksTask != null )
562565 getMatchingBlocksTask .cancel (true );
@@ -565,6 +568,17 @@ private void stopBuildingBuffer()
565568 compileVerticesTask .cancel (true );
566569 compileVerticesTask = null ;
567570 bufferUpToDate = false ;
568- tracerEnds = null ;
571+ if (discardCurrent )
572+ {
573+ tracerEnds = null ;
574+ lastMatchingBlocks = null ;
575+ foundCount = 0 ;
576+ if (vertexBuffer != null )
577+ {
578+ vertexBuffer .close ();
579+ vertexBuffer = null ;
580+ }
581+ bufferRegion = null ;
582+ }
569583 }
570584}
0 commit comments