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());
}
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);
}
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));
}
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();
}
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());
}
Aggregations