feat: implemented CustomChunkLoaderWorldFactory
This commit is contained in:
parent
ae93f00397
commit
2e5ca0ef0b
@ -1,8 +1,12 @@
|
|||||||
package ru.dragonestia.msb3.api.world;
|
package ru.dragonestia.msb3.api.world;
|
||||||
|
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import net.minestom.server.instance.IChunkLoader;
|
||||||
import net.minestom.server.instance.InstanceContainer;
|
import net.minestom.server.instance.InstanceContainer;
|
||||||
|
import net.minestom.server.registry.DynamicRegistry;
|
||||||
|
import net.minestom.server.world.DimensionType;
|
||||||
import ru.dragonestia.msb3.api.world.factory.AnvilWorldFactory;
|
import ru.dragonestia.msb3.api.world.factory.AnvilWorldFactory;
|
||||||
|
import ru.dragonestia.msb3.api.world.factory.CustomChunkLoaderWorldFactory;
|
||||||
import ru.dragonestia.msb3.api.world.factory.PreloadedAnvilWorldFactory;
|
import ru.dragonestia.msb3.api.world.factory.PreloadedAnvilWorldFactory;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -19,6 +23,12 @@ public abstract class WorldFactory {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final World createWorldSync() {
|
||||||
|
var world = loadWorld();
|
||||||
|
log.info("Created new world {} ({})", world.getInstance().getUniqueId(), world.getInstance().getChunkLoader().getClass().getSimpleName());
|
||||||
|
return world;
|
||||||
|
}
|
||||||
|
|
||||||
protected final World createWorld(InstanceContainer instance) {
|
protected final World createWorld(InstanceContainer instance) {
|
||||||
return new World(instance);
|
return new World(instance);
|
||||||
}
|
}
|
||||||
@ -32,4 +42,12 @@ public abstract class WorldFactory {
|
|||||||
public static PreloadedAnvilWorldFactory preloadedAnvil(File worldDir) {
|
public static PreloadedAnvilWorldFactory preloadedAnvil(File worldDir) {
|
||||||
return new PreloadedAnvilWorldFactory(worldDir);
|
return new PreloadedAnvilWorldFactory(worldDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static WorldFactory custom(IChunkLoader chunkLoader) {
|
||||||
|
return new CustomChunkLoaderWorldFactory(chunkLoader);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WorldFactory custom(DynamicRegistry.Key<DimensionType> dimensionType, IChunkLoader chunkLoader) {
|
||||||
|
return new CustomChunkLoaderWorldFactory(dimensionType, chunkLoader);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,29 @@
|
|||||||
|
package ru.dragonestia.msb3.api.world.factory;
|
||||||
|
|
||||||
|
import net.minestom.server.MinecraftServer;
|
||||||
|
import net.minestom.server.instance.IChunkLoader;
|
||||||
|
import net.minestom.server.registry.DynamicRegistry;
|
||||||
|
import net.minestom.server.world.DimensionType;
|
||||||
|
import ru.dragonestia.msb3.api.world.World;
|
||||||
|
import ru.dragonestia.msb3.api.world.WorldFactory;
|
||||||
|
|
||||||
|
public class CustomChunkLoaderWorldFactory extends WorldFactory {
|
||||||
|
|
||||||
|
private final DynamicRegistry.Key<DimensionType> dimensionType;
|
||||||
|
private final IChunkLoader chunkLoader;
|
||||||
|
|
||||||
|
public CustomChunkLoaderWorldFactory(IChunkLoader chunkLoader) {
|
||||||
|
this(DimensionType.OVERWORLD, chunkLoader);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CustomChunkLoaderWorldFactory(DynamicRegistry.Key<DimensionType> dimensionType, IChunkLoader chunkLoader) {
|
||||||
|
this.dimensionType = dimensionType;
|
||||||
|
this.chunkLoader = chunkLoader;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected World loadWorld() {
|
||||||
|
var instance = MinecraftServer.getInstanceManager().createInstanceContainer(dimensionType, chunkLoader);
|
||||||
|
return createWorld(instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user