From 4d0924a5229537b8c490813109fdc2c0f176b437 Mon Sep 17 00:00:00 2001 From: TheMode Date: Sat, 28 Aug 2021 13:06:09 +0200 Subject: [PATCH] Can now specify InstanceContainer chunk loader during initialization --- .../server/instance/InstanceContainer.java | 18 ++++++++---------- .../server/instance/InstanceManager.java | 18 +++++++++++++++--- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/minestom/server/instance/InstanceContainer.java b/src/main/java/net/minestom/server/instance/InstanceContainer.java index 52f3fd3ae..b94cf0012 100644 --- a/src/main/java/net/minestom/server/instance/InstanceContainer.java +++ b/src/main/java/net/minestom/server/instance/InstanceContainer.java @@ -27,6 +27,7 @@ import net.minestom.server.utils.chunk.ChunkUtils; import net.minestom.server.utils.validate.Check; import net.minestom.server.world.DimensionType; import net.minestom.server.world.biomes.Biome; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -68,21 +69,18 @@ public class InstanceContainer extends Instance { protected InstanceContainer srcInstance; // only present if this instance has been created using a copy private long lastBlockChangeTime; // Time at which the last block change happened (#setBlock) - /** - * Creates an {@link InstanceContainer}. - * - * @param uniqueId the unique id of the instance - * @param dimensionType the dimension type of the instance - */ - public InstanceContainer(@NotNull UUID uniqueId, @NotNull DimensionType dimensionType) { + @ApiStatus.Experimental + public InstanceContainer(@NotNull UUID uniqueId, @NotNull DimensionType dimensionType, @Nullable IChunkLoader loader) { super(uniqueId, dimensionType); - // Set the default chunk supplier using DynamicChunk setChunkSupplier(DynamicChunk::new); - // Set the default chunk loader which use the Anvil format - setChunkLoader(new AnvilLoader("world")); + setChunkLoader(Objects.requireNonNullElseGet(loader, () -> new AnvilLoader("world"))); this.chunkLoader.loadInstance(this); } + public InstanceContainer(@NotNull UUID uniqueId, @NotNull DimensionType dimensionType) { + this(uniqueId, dimensionType, null); + } + @Override public void setBlock(int x, int y, int z, @NotNull Block block) { final Chunk chunk = getChunkAt(x, z); diff --git a/src/main/java/net/minestom/server/instance/InstanceManager.java b/src/main/java/net/minestom/server/instance/InstanceManager.java index 0dfcd9016..4dbece1a2 100644 --- a/src/main/java/net/minestom/server/instance/InstanceManager.java +++ b/src/main/java/net/minestom/server/instance/InstanceManager.java @@ -4,6 +4,7 @@ import net.minestom.server.MinecraftServer; import net.minestom.server.storage.StorageLocation; import net.minestom.server.utils.validate.Check; import net.minestom.server.world.DimensionType; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -39,21 +40,32 @@ public final class InstanceManager { * with the specified {@link DimensionType} and {@link StorageLocation}. * * @param dimensionType the {@link DimensionType} of the instance + * @param loader the chunk loader * @return the created {@link InstanceContainer} */ - public @NotNull InstanceContainer createInstanceContainer(@NotNull DimensionType dimensionType) { - final InstanceContainer instanceContainer = new InstanceContainer(UUID.randomUUID(), dimensionType); + @ApiStatus.Experimental + public @NotNull InstanceContainer createInstanceContainer(@NotNull DimensionType dimensionType, @Nullable IChunkLoader loader) { + final InstanceContainer instanceContainer = new InstanceContainer(UUID.randomUUID(), dimensionType, loader); registerInstance(instanceContainer); return instanceContainer; } + public @NotNull InstanceContainer createInstanceContainer(@NotNull DimensionType dimensionType) { + return createInstanceContainer(dimensionType, null); + } + + @ApiStatus.Experimental + public @NotNull InstanceContainer createInstanceContainer(@Nullable IChunkLoader loader) { + return createInstanceContainer(DimensionType.OVERWORLD, loader); + } + /** * Creates and register an {@link InstanceContainer}. * * @return the created {@link InstanceContainer} */ public @NotNull InstanceContainer createInstanceContainer() { - return createInstanceContainer(DimensionType.OVERWORLD); + return createInstanceContainer(DimensionType.OVERWORLD, null); } /**