Package net.minestom.server.instance
Interface IChunkLoader
- All Known Implementing Classes:
AnvilLoader
public interface IChunkLoader
Interface implemented to change the way chunks are loaded/saved.
See AnvilLoader
for the default implementation used in InstanceContainer
.
-
Method Summary
Modifier and TypeMethodDescription@NotNull CompletableFuture
<@Nullable Chunk> Loads aChunk
, all blocks should be set since theChunkGenerator
is not applied.default void
loadInstance
(@NotNull Instance instance) Loads instance data from the loader.@NotNull CompletableFuture
<Void> Saves aChunk
with an optional callback for when it is done.default @NotNull CompletableFuture
<Void> saveChunks
(@NotNull Collection<Chunk> chunks) Saves multiple chunks with an optional callback for when it is done.default @NotNull CompletableFuture
<Void> saveInstance
(@NotNull Instance instance) default boolean
Does thisIChunkLoader
allow for multi-threaded loading ofChunk
?default boolean
Does thisIChunkLoader
allow for multi-threaded saving ofChunk
?default void
unloadChunk
(Chunk chunk) Called when a chunk is unloaded, so that this chunk loader can unload any resource it is holding.
-
Method Details
-
loadInstance
Loads instance data from the loader.- Parameters:
instance
- the instance to retrieve the data from
-
loadChunk
@NotNull @NotNull CompletableFuture<@Nullable Chunk> loadChunk(@NotNull @NotNull Instance instance, int chunkX, int chunkZ) Loads aChunk
, all blocks should be set since theChunkGenerator
is not applied.- Parameters:
instance
- theInstance
where theChunk
belongchunkX
- the chunk XchunkZ
- the chunk Z- Returns:
- a
CompletableFuture
containing the chunk, or null if not present
-
saveInstance
-
saveChunk
Saves aChunk
with an optional callback for when it is done.- Parameters:
chunk
- theChunk
to save- Returns:
- a
CompletableFuture
executed when theChunk
is done saving, should be called even if the saving failed (you can throw an exception).
-
saveChunks
@NotNull default @NotNull CompletableFuture<Void> saveChunks(@NotNull @NotNull Collection<Chunk> chunks) Saves multiple chunks with an optional callback for when it is done.Implementations need to check
supportsParallelSaving()
to support the feature if possible.- Parameters:
chunks
- the chunks to save- Returns:
- a
CompletableFuture
executed when theChunk
is done saving, should be called even if the saving failed (you can throw an exception).
-
supportsParallelSaving
default boolean supportsParallelSaving()Does thisIChunkLoader
allow for multi-threaded saving ofChunk
?- Returns:
- true if the chunk loader supports parallel saving
-
supportsParallelLoading
default boolean supportsParallelLoading()Does thisIChunkLoader
allow for multi-threaded loading ofChunk
?- Returns:
- true if the chunk loader supports parallel loading
-
unloadChunk
Called when a chunk is unloaded, so that this chunk loader can unload any resource it is holding. Note: Minestom currently has no way to determine whether the chunk comes from this loader, so you may get unload requests for chunks not created by the loader.- Parameters:
chunk
- the chunk to unload
-