Skip to content

Commit d1a36e5

Browse files
committed
ChunkGrid improvements
1 parent 05e12c5 commit d1a36e5

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

core/src/main/java/de/bluecolored/bluemap/core/world/mca/ChunkGrid.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.github.benmanes.caffeine.cache.LoadingCache;
66
import de.bluecolored.bluemap.core.BlueMap;
77
import de.bluecolored.bluemap.core.logger.Logger;
8+
import de.bluecolored.bluemap.core.util.Grid;
89
import de.bluecolored.bluemap.core.util.Vector2iCache;
910
import de.bluecolored.bluemap.core.util.WatchService;
1011
import de.bluecolored.bluemap.core.world.ChunkConsumer;
@@ -25,6 +26,9 @@
2526

2627
@RequiredArgsConstructor
2728
public 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

core/src/main/java/de/bluecolored/bluemap/core/world/mca/MCAWorld.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@
6363
@ToString
6464
public class MCAWorld implements World {
6565

66-
private static final Grid CHUNK_GRID = new Grid(16);
67-
private static final Grid REGION_GRID = new Grid(32).multiply(CHUNK_GRID);
68-
6966
private final String id;
7067
private final Path worldFolder;
7168
private final Key dimension;
@@ -116,12 +113,12 @@ public String getName() {
116113

117114
@Override
118115
public Grid getChunkGrid() {
119-
return CHUNK_GRID;
116+
return blockChunkGrid.getChunkGrid();
120117
}
121118

122119
@Override
123120
public Grid getRegionGrid() {
124-
return REGION_GRID;
121+
return blockChunkGrid.getRegionGrid();
125122
}
126123

127124
@Override

0 commit comments

Comments
 (0)