Improvements on world handling the entity chunk-grid

This commit is contained in:
Lukas Rieger (Blue) 2025-01-20 15:41:22 +01:00
parent 19d3c321dc
commit 2367f4feca
No known key found for this signature in database
GPG Key ID: AA33883B1BBA03E6

View File

@ -25,6 +25,7 @@
package de.bluecolored.bluemap.core.world.mca;
import com.flowpowered.math.vector.Vector2i;
import com.flowpowered.math.vector.Vector3d;
import com.flowpowered.math.vector.Vector3i;
import de.bluecolored.bluemap.core.logger.Logger;
import de.bluecolored.bluemap.core.resources.pack.datapack.DataPack;
@ -143,16 +144,19 @@ public WatchService<Vector2i> createRegionWatchService() throws IOException {
@Override
public void preloadRegionChunks(int x, int z, Predicate<Vector2i> chunkFilter) {
blockChunkGrid.preloadRegionChunks(x, z, chunkFilter);
entityChunkGrid.preloadRegionChunks(x, z, chunkFilter);
}
@Override
public void invalidateChunkCache() {
blockChunkGrid.invalidateChunkCache();
entityChunkGrid.invalidateChunkCache();
}
@Override
public void invalidateChunkCache(int x, int z) {
blockChunkGrid.invalidateChunkCache(x, z);
entityChunkGrid.invalidateChunkCache(x, z);
}
@Override
@ -165,7 +169,17 @@ public void iterateEntities(int minX, int minZ, int maxX, int maxZ, Consumer<Ent
Entity[] entities = entityChunkGrid.getChunk(x, z).getEntities();
//noinspection ForLoopReplaceableByForEach
for (int i = 0; i < entities.length; i++) {
entityConsumer.accept(entities[i]);
Entity entity = entities[i];
Vector3d pos = entity.getPos();
int pX = pos.getFloorX();
int pZ = pos.getFloorZ();
if (
pX >= minX && pX <= maxX &&
pZ >= minZ && pZ <= maxZ
) {
entityConsumer.accept(entities[i]);
}
}
}
}