mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-12 13:44:28 +01:00
Support async chunk loading
This commit is contained in:
parent
1ead7c923a
commit
37b5575484
@ -254,4 +254,14 @@ public class AnvilLoader implements IChunkLoader {
|
||||
}
|
||||
chunkColumn.setTileEntities(tileEntities);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsParallelLoading() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsParallelSaving() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package net.minestom.server.instance;
|
||||
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.utils.callback.OptionalCallback;
|
||||
import net.minestom.server.utils.thread.MinestomThread;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -33,7 +32,7 @@ public interface IChunkLoader {
|
||||
*
|
||||
* @param chunk the {@link Chunk} to save
|
||||
* @return a {@link CompletableFuture} executed when the {@link Chunk} is done saving,
|
||||
* * should be called even if the saving failed (you can throw an exception).
|
||||
* should be called even if the saving failed (you can throw an exception).
|
||||
*/
|
||||
@NotNull CompletableFuture<Void> saveChunk(@NotNull Chunk chunk);
|
||||
|
||||
@ -44,7 +43,7 @@ public interface IChunkLoader {
|
||||
*
|
||||
* @param chunks the chunks to save
|
||||
* @return a {@link CompletableFuture} executed when the {@link Chunk} is done saving,
|
||||
* * should be called even if the saving failed (you can throw an exception).
|
||||
* should be called even if the saving failed (you can throw an exception).
|
||||
*/
|
||||
default @NotNull CompletableFuture<Void> saveChunks(@NotNull Collection<Chunk> chunks) {
|
||||
if (supportsParallelSaving()) {
|
||||
|
@ -318,7 +318,7 @@ public class InstanceContainer extends Instance {
|
||||
|
||||
protected CompletableFuture<Chunk> retrieveChunk(int chunkX, int chunkZ) {
|
||||
CompletableFuture<Chunk> completableFuture = new CompletableFuture<>();
|
||||
chunkLoader.loadChunk(this, chunkX, chunkZ)
|
||||
final Runnable loader = () -> chunkLoader.loadChunk(this, chunkX, chunkZ)
|
||||
.whenComplete((chunk, throwable) -> {
|
||||
if (chunk != null) {
|
||||
// Successfully loaded
|
||||
@ -335,7 +335,11 @@ public class InstanceContainer extends Instance {
|
||||
completableFuture.complete(c));
|
||||
}
|
||||
});
|
||||
|
||||
if (chunkLoader.supportsParallelLoading()) {
|
||||
CompletableFuture.runAsync(loader);
|
||||
} else {
|
||||
loader.run();
|
||||
}
|
||||
// Chunk is being loaded
|
||||
return completableFuture;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user