1515import java .util .HashMap ;
1616import java .util .HashSet ;
1717import java .util .Locale ;
18+ import java .util .Map ;
1819import java .util .Objects ;
1920import java .util .concurrent .ConcurrentHashMap ;
2021import java .util .concurrent .ConcurrentLinkedQueue ;
@@ -509,10 +510,15 @@ private boolean syncToArea(HashSet<ChunkPos> areaChunks)
509510
510511 missingChunks .sort (Comparator
511512 .comparingInt (pos -> getChunkDistance (pos , priorityCenter )));
512- for (ChunkPos pos : missingChunks )
513+ // Prioritize nearby chunks so stale long-range detections are corrected
514+ // quickly when the player moves toward them.
515+ for (int i = missingChunks .size () - 1 ; i >= 0 ; i --)
516+ {
517+ ChunkPos pos = missingChunks .get (i );
513518 if (queuedChunks .add (pos ))
514- scanQueue .addLast (pos );
515-
519+ scanQueue .addFirst (pos );
520+ }
521+
516522 return changed ;
517523 }
518524
@@ -533,7 +539,7 @@ private void enqueueDirtyChunks(HashSet<ChunkPos> areaChunks)
533539 continue ;
534540
535541 if (queuedChunks .add (pos ))
536- scanQueue .addLast (pos );
542+ scanQueue .addFirst (pos );
537543
538544 promoted ++;
539545 }
@@ -1249,8 +1255,14 @@ private void rebuildRenderCache()
12491255 bubbleColumnBoxes .clear ();
12501256 waterColumnBoxes .clear ();
12511257
1252- for (ChunkDetections detections : detectionsByChunk .values ())
1258+ for (Map .Entry <ChunkPos , ChunkDetections > entry : detectionsByChunk
1259+ .entrySet ())
12531260 {
1261+ ChunkPos chunkPos = entry .getKey ();
1262+ if (MC .level == null || !MC .level .hasChunk (chunkPos .x , chunkPos .z ))
1263+ continue ;
1264+
1265+ ChunkDetections detections = entry .getValue ();
12541266 holeBoxes .addAll (detections .holes );
12551267 tunnelBoxes .addAll (detections .tunnels );
12561268 stairBoxes .addAll (detections .stairs );
0 commit comments