mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-02 14:38:26 +01:00
Do not run chunk load callback in the instance thread
This commit is contained in:
parent
91983e16eb
commit
253c059614
@ -271,15 +271,16 @@ public class InstanceContainer extends Instance {
|
|||||||
final Runnable retriever = () -> loader.loadChunk(this, chunkX, chunkZ)
|
final Runnable retriever = () -> loader.loadChunk(this, chunkX, chunkZ)
|
||||||
// create the chunk from scratch (with the generator) if the loader couldn't
|
// create the chunk from scratch (with the generator) if the loader couldn't
|
||||||
.thenCompose(chunk -> chunk != null ? CompletableFuture.completedFuture(chunk) : createChunk(chunkX, chunkZ))
|
.thenCompose(chunk -> chunk != null ? CompletableFuture.completedFuture(chunk) : createChunk(chunkX, chunkZ))
|
||||||
// cache the retrieved chunk (in the next instance tick for thread-safety)
|
// cache the retrieved chunk
|
||||||
.whenComplete((chunk, throwable) -> scheduleNextTick(instance -> {
|
.whenComplete((chunk, throwable) -> {
|
||||||
|
// TODO run in the instance thread?
|
||||||
cacheChunk(chunk);
|
cacheChunk(chunk);
|
||||||
EventDispatcher.call(new InstanceChunkLoadEvent(this, chunkX, chunkZ), GlobalHandles.INSTANCE_CHUNK_LOAD);
|
EventDispatcher.call(new InstanceChunkLoadEvent(this, chunkX, chunkZ), GlobalHandles.INSTANCE_CHUNK_LOAD);
|
||||||
synchronized (loadingChunks) {
|
synchronized (loadingChunks) {
|
||||||
this.loadingChunks.remove(ChunkUtils.getChunkIndex(chunk));
|
this.loadingChunks.remove(ChunkUtils.getChunkIndex(chunk));
|
||||||
}
|
}
|
||||||
completableFuture.complete(chunk);
|
completableFuture.complete(chunk);
|
||||||
}));
|
});
|
||||||
if (loader.supportsParallelLoading()) {
|
if (loader.supportsParallelLoading()) {
|
||||||
CompletableFuture.runAsync(retriever);
|
CompletableFuture.runAsync(retriever);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user