Can now specify InstanceContainer chunk loader during initialization

This commit is contained in:
TheMode 2021-08-28 13:06:09 +02:00
parent bf847fac79
commit 4d0924a522
2 changed files with 23 additions and 13 deletions

View File

@ -27,6 +27,7 @@ import net.minestom.server.utils.chunk.ChunkUtils;
import net.minestom.server.utils.validate.Check; import net.minestom.server.utils.validate.Check;
import net.minestom.server.world.DimensionType; import net.minestom.server.world.DimensionType;
import net.minestom.server.world.biomes.Biome; import net.minestom.server.world.biomes.Biome;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; 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 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) private long lastBlockChangeTime; // Time at which the last block change happened (#setBlock)
/** @ApiStatus.Experimental
* Creates an {@link InstanceContainer}. public InstanceContainer(@NotNull UUID uniqueId, @NotNull DimensionType dimensionType, @Nullable IChunkLoader loader) {
*
* @param uniqueId the unique id of the instance
* @param dimensionType the dimension type of the instance
*/
public InstanceContainer(@NotNull UUID uniqueId, @NotNull DimensionType dimensionType) {
super(uniqueId, dimensionType); super(uniqueId, dimensionType);
// Set the default chunk supplier using DynamicChunk
setChunkSupplier(DynamicChunk::new); setChunkSupplier(DynamicChunk::new);
// Set the default chunk loader which use the Anvil format setChunkLoader(Objects.requireNonNullElseGet(loader, () -> new AnvilLoader("world")));
setChunkLoader(new AnvilLoader("world"));
this.chunkLoader.loadInstance(this); this.chunkLoader.loadInstance(this);
} }
public InstanceContainer(@NotNull UUID uniqueId, @NotNull DimensionType dimensionType) {
this(uniqueId, dimensionType, null);
}
@Override @Override
public void setBlock(int x, int y, int z, @NotNull Block block) { public void setBlock(int x, int y, int z, @NotNull Block block) {
final Chunk chunk = getChunkAt(x, z); final Chunk chunk = getChunkAt(x, z);

View File

@ -4,6 +4,7 @@ import net.minestom.server.MinecraftServer;
import net.minestom.server.storage.StorageLocation; import net.minestom.server.storage.StorageLocation;
import net.minestom.server.utils.validate.Check; import net.minestom.server.utils.validate.Check;
import net.minestom.server.world.DimensionType; import net.minestom.server.world.DimensionType;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -39,21 +40,32 @@ public final class InstanceManager {
* with the specified {@link DimensionType} and {@link StorageLocation}. * with the specified {@link DimensionType} and {@link StorageLocation}.
* *
* @param dimensionType the {@link DimensionType} of the instance * @param dimensionType the {@link DimensionType} of the instance
* @param loader the chunk loader
* @return the created {@link InstanceContainer} * @return the created {@link InstanceContainer}
*/ */
public @NotNull InstanceContainer createInstanceContainer(@NotNull DimensionType dimensionType) { @ApiStatus.Experimental
final InstanceContainer instanceContainer = new InstanceContainer(UUID.randomUUID(), dimensionType); public @NotNull InstanceContainer createInstanceContainer(@NotNull DimensionType dimensionType, @Nullable IChunkLoader loader) {
final InstanceContainer instanceContainer = new InstanceContainer(UUID.randomUUID(), dimensionType, loader);
registerInstance(instanceContainer); registerInstance(instanceContainer);
return 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}. * Creates and register an {@link InstanceContainer}.
* *
* @return the created {@link InstanceContainer} * @return the created {@link InstanceContainer}
*/ */
public @NotNull InstanceContainer createInstanceContainer() { public @NotNull InstanceContainer createInstanceContainer() {
return createInstanceContainer(DimensionType.OVERWORLD); return createInstanceContainer(DimensionType.OVERWORLD, null);
} }
/** /**