mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-30 21:17:53 +01:00
Can now specify InstanceContainer chunk loader during initialization
This commit is contained in:
parent
bf847fac79
commit
4d0924a522
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user