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 Type
    Method
    Description
    @Nullable Chunk
    loadChunk(@NotNull Instance instance, int chunkX, int chunkZ)
    Loads a Chunk, all blocks should be set since the Generator is not applied.
    default void
    loadInstance(@NotNull Instance instance)
    Loads instance data from the loader.
    static @NotNull IChunkLoader
     
    void
    saveChunk(@NotNull Chunk chunk)
    Saves a Chunk with an optional callback for when it is done.
    default void
    saveChunks(@NotNull Collection<Chunk> chunks)
    Saves multiple chunks with an optional callback for when it is done.
    default void
    saveInstance(@NotNull Instance instance)
     
    default boolean
    Supports for instance/chunk loading in virtual threads.
    default boolean
    Supports for instance/chunk saving in virtual threads.
    default void
    Called when a chunk is unloaded, so that this chunk loader can unload any resource it is holding.
  • Method Details

    • noop

      @NotNull static @NotNull IChunkLoader noop()
    • loadInstance

      default void loadInstance(@NotNull @NotNull Instance instance)
      Loads instance data from the loader.
      Parameters:
      instance - the instance to retrieve the data from
    • loadChunk

      @Nullable @Nullable Chunk loadChunk(@NotNull @NotNull Instance instance, int chunkX, int chunkZ)
      Loads a Chunk, all blocks should be set since the Generator is not applied.
      Parameters:
      instance - the Instance where the Chunk belong
      chunkX - the chunk X
      chunkZ - the chunk Z
      Returns:
      the chunk, or null if not present
    • saveInstance

      default void saveInstance(@NotNull @NotNull Instance instance)
    • saveChunk

      void saveChunk(@NotNull @NotNull Chunk chunk)
      Saves a Chunk with an optional callback for when it is done.
      Parameters:
      chunk - the Chunk to save
    • saveChunks

      default 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
    • supportsParallelSaving

      default boolean supportsParallelSaving()
      Supports for instance/chunk saving in virtual threads.
      Returns:
      true if the chunk loader supports parallel saving
    • supportsParallelLoading

      default boolean supportsParallelLoading()
      Supports for instance/chunk loading in virtual threads.
      Returns:
      true if the chunk loader supports parallel loading
    • unloadChunk

      default void unloadChunk(Chunk chunk)
      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