Invalidate chunk-cache after a world-save, not directly with the block-change event

To prevent the chunk being loaded again before the changes are being saved to disk.
This commit is contained in:
Blue (Lukas Rieger) 2020-09-12 17:43:40 +02:00
parent 41a782528d
commit e8fc7028d0

View File

@ -60,6 +60,12 @@ public void onWorldSaveToDisk(final UUID world) {
while (iterator.hasNext()) { while (iterator.hasNext()) {
MapType map = iterator.next(); MapType map = iterator.next();
if (map.getWorld().getUUID().equals(world)) { if (map.getWorld().getUUID().equals(world)) {
//invalidate caches of updated chunks
for (Vector2i chunk : updateBuffer.get(map)) {
map.getWorld().invalidateChunkCache(chunk);
}
renderManager.createTickets(map, updateBuffer.get(map)); renderManager.createTickets(map, updateBuffer.get(map));
iterator.remove(); iterator.remove();
} }
@ -111,8 +117,6 @@ private void updateBlock(UUID world, Vector3i pos){
synchronized (updateBuffer) { synchronized (updateBuffer) {
for (MapType mapType : plugin.getMapTypes()) { for (MapType mapType : plugin.getMapTypes()) {
if (mapType.getWorld().getUUID().equals(world)) { if (mapType.getWorld().getUUID().equals(world)) {
mapType.getWorld().invalidateChunkCache(mapType.getWorld().blockPosToChunkPos(pos));
Vector2i tile = mapType.getTileRenderer().getHiresModelManager().posToTile(pos); Vector2i tile = mapType.getTileRenderer().getHiresModelManager().posToTile(pos);
updateBuffer.put(mapType, tile); updateBuffer.put(mapType, tile);
} }
@ -129,6 +133,12 @@ public void flushTileBuffer() {
synchronized (updateBuffer) { synchronized (updateBuffer) {
for (MapType map : updateBuffer.keySet()) { for (MapType map : updateBuffer.keySet()) {
//invalidate caches of updated chunks
for (Vector2i chunk : updateBuffer.get(map)) {
map.getWorld().invalidateChunkCache(chunk);
}
renderManager.createTickets(map, updateBuffer.get(map)); renderManager.createTickets(map, updateBuffer.get(map));
} }
updateBuffer.clear(); updateBuffer.clear();