Search in sources :

Example 1 with GameRegistry

use of org.spongepowered.api.GameRegistry 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>) () -> {
        List<String> valid = registry.getAllOf(DimensionType.class).stream().map(DimensionType::getId).collect(Collectors.toList());
        return new RuntimeException("No dimension type: " + dimensionName + "; Valid dimension types: " + Joiner.on(", ").join(valid));
    });
    archeTypeBuilder.dimension(dimension);
    String generatorName = archetypeConfig.getGenerator();
    GeneratorType generator = registry.getType(GeneratorType.class, generatorName).orElseThrow((Supplier<Throwable>) () -> {
        List<String> valid = registry.getAllOf(GeneratorType.class).stream().map(GeneratorType::getId).collect(Collectors.toList());
        return new RuntimeException("No generator type: " + generatorName + "; Valid generator types: " + Joiner.on(", ").join(valid));
    });
    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 GameRegistry

use of org.spongepowered.api.GameRegistry in project SpongeAPI by SpongePowered.

the class TextFormatConfigSerializer method deserialize.

@Override
public TextFormat deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException {
    TextColor color = TextColors.NONE;
    GameRegistry registry = Sponge.getRegistry();
    String colorId = value.getNode(NODE_COLOR).getString();
    if (colorId != null) {
        color = registry.getType(TextColor.class, colorId).orElseThrow(() -> new ObjectMappingException("Color not found: " + colorId));
    }
    TextStyle style = TextStyles.NONE;
    ConfigurationNode styleNode = value.getNode(NODE_STYLE);
    for (TextStyle.Base component : registry.getAllOf(TextStyle.Base.class)) {
        if (styleNode.getNode(component.getId().toLowerCase()).getBoolean()) {
            style = style.and(component);
        }
    }
    return TextFormat.NONE.color(color).style(style);
}
Also used : TextStyle(org.spongepowered.api.text.format.TextStyle) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) GameRegistry(org.spongepowered.api.GameRegistry) TextColor(org.spongepowered.api.text.format.TextColor) ObjectMappingException(ninja.leaping.configurate.objectmapping.ObjectMappingException)

Example 3 with GameRegistry

use of org.spongepowered.api.GameRegistry in project Nucleus by NucleusPowered.

the class ImprovedCatalogTypeArgument method parseValue.

@Nullable
@Override
protected Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
    String arg = args.next().toLowerCase();
    // Try
    GameRegistry registry = Sponge.getRegistry();
    Optional<? extends CatalogType> catalogType = registry.getType(type, arg);
    if (!catalogType.isPresent() && !arg.contains(":")) {
        catalogType = registry.getType(type, "minecraft:" + arg);
        if (!catalogType.isPresent()) {
            catalogType = registry.getType(type, "sponge:" + arg);
        }
    }
    if (catalogType.isPresent()) {
        return catalogType.get();
    }
    throw args.createError(Nucleus.getNucleus().getMessageProvider().getTextMessageWithFormat("args.catalogtype.nomatch", arg));
}
Also used : GameRegistry(org.spongepowered.api.GameRegistry) Nullable(javax.annotation.Nullable)

Example 4 with GameRegistry

use of org.spongepowered.api.GameRegistry 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);
    service.registerWorld(worldName);
    return optTargetWorld.get();
}
Also used : WorldArchetype(org.spongepowered.api.world.WorldArchetype) GameRegistry(org.spongepowered.api.GameRegistry) World(org.spongepowered.api.world.World)

Example 5 with GameRegistry

use of org.spongepowered.api.GameRegistry in project LanternServer by LanternPowered.

the class TestRecipesPlugin method onStart.

@Listener
public void onStart(GameInitializationEvent event) {
    this.logger.info("Test Recipes plugin enabled!");
    final GameRegistry gameRegistry = Sponge.getGame().getRegistry();
    gameRegistry.getCraftingRecipeRegistry().register(CraftingRecipe.shapedBuilder().aisle("xy", "yx").where('x', Ingredient.of(ItemTypes.APPLE)).where('y', Ingredient.of(ItemTypes.GOLD_NUGGET)).result(ItemStack.of(ItemTypes.GOLDEN_APPLE, 2)).build("golden_apples", this));
    gameRegistry.getSmeltingRecipeRegistry().register(SmeltingRecipe.builder().ingredient(ItemTypes.GOLDEN_APPLE).result(ItemStack.of(ItemTypes.GOLD_NUGGET, 1)).build());
}
Also used : GameRegistry(org.spongepowered.api.GameRegistry) Listener(org.spongepowered.api.event.Listener)

Aggregations

GameRegistry (org.spongepowered.api.GameRegistry)6 WorldArchetype (org.spongepowered.api.world.WorldArchetype)2 WorldGeneratorModifier (org.spongepowered.api.world.gen.WorldGeneratorModifier)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Supplier (java.util.function.Supplier)1 Nullable (javax.annotation.Nullable)1 ConfigurationNode (ninja.leaping.configurate.ConfigurationNode)1 ObjectMappingException (ninja.leaping.configurate.objectmapping.ObjectMappingException)1 Listener (org.spongepowered.api.event.Listener)1 TextColor (org.spongepowered.api.text.format.TextColor)1 TextStyle (org.spongepowered.api.text.format.TextStyle)1 DimensionType (org.spongepowered.api.world.DimensionType)1 GeneratorType (org.spongepowered.api.world.GeneratorType)1 World (org.spongepowered.api.world.World)1