55import com .github .benmanes .caffeine .cache .LoadingCache ;
66import de .bluecolored .bluemap .core .BlueMap ;
77import de .bluecolored .bluemap .core .logger .Logger ;
8+ import de .bluecolored .bluemap .core .util .Grid ;
89import de .bluecolored .bluemap .core .util .Vector2iCache ;
910import de .bluecolored .bluemap .core .util .WatchService ;
1011import de .bluecolored .bluemap .core .world .ChunkConsumer ;
2526
2627@ RequiredArgsConstructor
2728public class ChunkGrid <T > {
29+ private static final Grid CHUNK_GRID = new Grid (16 );
30+ private static final Grid REGION_GRID = new Grid (32 ).multiply (CHUNK_GRID );
31+
2832 private static final Vector2iCache VECTOR_2_I_CACHE = new Vector2iCache ();
2933
3034 private final ChunkLoader <T > chunkLoader ;
@@ -45,6 +49,14 @@ public class ChunkGrid<T> {
4549 .expireAfterAccess (1 , TimeUnit .MINUTES )
4650 .build (this ::loadChunk );
4751
52+ public Grid getChunkGrid () {
53+ return CHUNK_GRID ;
54+ }
55+
56+ public Grid getRegionGrid () {
57+ return REGION_GRID ;
58+ }
59+
4860 public T getChunk (int x , int z ) {
4961 return getChunk (VECTOR_2_I_CACHE .get (x , z ));
5062 }
@@ -61,10 +73,6 @@ private Region<T> getRegion(Vector2i pos) {
6173 return regionCache .get (pos );
6274 }
6375
64- public void iterateChunks (int minX , int minZ , int maxX , int maxZ , ChunkConsumer <T > chunkConsumer ) {
65-
66- }
67-
6876 public void preloadRegionChunks (int x , int z , Predicate <Vector2i > chunkFilter ) {
6977 try {
7078 getRegion (x , z ).iterateAllChunks (new ChunkConsumer <>() {
@@ -81,7 +89,7 @@ public void accept(int chunkX, int chunkZ, T chunk) {
8189 }
8290 });
8391 } catch (IOException ex ) {
84- Logger .global .logDebug ("Unexpected exception trying to load preload region (x:" + x + " , z:" + z + " ): " + ex );
92+ Logger .global .logDebug ("Unexpected exception trying to load preload region ('%s' -> x:%d , z:%d ): %s" . formatted ( regionFolder , x , z , ex ) );
8593 }
8694 }
8795
@@ -101,7 +109,7 @@ public Collection<Vector2i> listRegions() {
101109 .filter (Objects ::nonNull )
102110 .toList ();
103111 } catch (IOException ex ) {
104- Logger .global .logError ("Failed to list regions for folder : '" + regionFolder + "'" , ex );
112+ Logger .global .logError ("Failed to list regions from : '%s'" . formatted ( regionFolder ) , ex );
105113 return List .of ();
106114 }
107115 }
@@ -158,7 +166,7 @@ private T loadChunk(int x, int z) {
158166 }
159167 }
160168
161- Logger .global .logDebug ("Unexpected exception trying to load chunk (x:" + x + " , z:" + z + " ): " + loadException );
169+ Logger .global .logDebug ("Unexpected exception trying to load chunk ('%s' -> x:%d , z:%d ): %s" . formatted ( regionFolder , x , z , loadException ) );
162170 return chunkLoader .erroredChunk ();
163171 }
164172
0 commit comments