Search in sources :

Example 1 with WorldArchetype

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());
}
Also used : DimensionType(org.spongepowered.api.world.DimensionType) GameRegistry(org.spongepowered.api.GameRegistry) GeneratorType(org.spongepowered.api.world.GeneratorType) WorldGeneratorModifier(org.spongepowered.api.world.gen.WorldGeneratorModifier) WorldArchetype(org.spongepowered.api.world.WorldArchetype) Supplier(java.util.function.Supplier)

Example 2 with WorldArchetype

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();
}
Also used : WorldArchetype(org.spongepowered.api.world.WorldArchetype) GameRegistry(org.spongepowered.api.GameRegistry) World(org.spongepowered.api.world.World)

Aggregations

GameRegistry (org.spongepowered.api.GameRegistry)2 WorldArchetype (org.spongepowered.api.world.WorldArchetype)2 Supplier (java.util.function.Supplier)1 DimensionType (org.spongepowered.api.world.DimensionType)1 GeneratorType (org.spongepowered.api.world.GeneratorType)1 World (org.spongepowered.api.world.World)1 WorldGeneratorModifier (org.spongepowered.api.world.gen.WorldGeneratorModifier)1