use of org.spongepowered.api.world.WorldArchetype in project Skree by Skelril.
the class WorldSystem method buildArchetype.
private void buildArchetype(ArchetypeConfig archetypeConfig) throws Throwable {
GameRegistry registry = Sponge.getRegistry();
Optional<WorldArchetype> optTargetArchetype = registry.getType(WorldArchetype.class, archetypeConfig.getId());
if (optTargetArchetype.isPresent()) {
return;
}
WorldArchetype.Builder archeTypeBuilder = obtainAutoloadingWorld();
String dimensionName = archetypeConfig.getDimension();
DimensionType dimension = registry.getType(DimensionType.class, dimensionName).orElseThrow((Supplier<Throwable>) () -> {
return new RuntimeException("No dimension type: " + dimensionName);
});
archeTypeBuilder.dimension(dimension);
String generatorName = archetypeConfig.getGenerator();
GeneratorType generator = registry.getType(GeneratorType.class, generatorName).orElseThrow((Supplier<Throwable>) () -> {
return new RuntimeException("No generator type: " + generatorName);
});
archeTypeBuilder.generator(generator);
boolean usesMapFeatures = archetypeConfig.usesMapFeatures();
archeTypeBuilder.usesMapFeatures(usesMapFeatures);
List<WorldGeneratorModifier> modifiers = new ArrayList<>();
for (String modifierId : archetypeConfig.getModifiers()) {
modifiers.add(registry.getType(WorldGeneratorModifier.class, modifierId).orElseThrow((Supplier<Throwable>) () -> {
return new RuntimeException("No world generator modifier: " + modifierId);
}));
}
archeTypeBuilder.generatorModifiers(modifiers.toArray(new WorldGeneratorModifier[modifiers.size()]));
archeTypeBuilder.build(archetypeConfig.getId(), archetypeConfig.getName());
}
use of org.spongepowered.api.world.WorldArchetype in project Skree by Skelril.
the class WorldSystem method getOrCreateWorld.
private World getOrCreateWorld(WorldConfig worldConfig) throws Throwable {
String worldName = worldConfig.getName();
Optional<World> optTargetWorld = Sponge.getServer().getWorld(worldName);
if (optTargetWorld.isPresent()) {
return optTargetWorld.get();
}
GameRegistry registry = Sponge.getRegistry();
String archetypeName = worldConfig.getArchetype();
WorldArchetype archetype = registry.getType(WorldArchetype.class, archetypeName).orElseThrow((Supplier<Throwable>) () -> {
return new RuntimeException("No world archetype: " + archetypeName);
});
optTargetWorld = service.loadWorld(worldName, archetype);
return optTargetWorld.get();
}
Aggregations