Search in sources :

Example 6 with DelayedRegistration

use of org.spongepowered.api.registry.util.DelayedRegistration in project SpongeCommon by SpongePowered.

the class RegistryModuleLoader method isDefaultProperPhase.

private static boolean isDefaultProperPhase(RegistryModule module) {
    try {
        Method method = module.getClass().getMethod("registerDefaults");
        DelayedRegistration delay = method.getDeclaredAnnotation(DelayedRegistration.class);
        if (delay == null) {
            return SpongeImpl.getRegistry().getPhase() == RegistrationPhase.PRE_REGISTRY;
        }
        return SpongeImpl.getRegistry().getPhase() == delay.value();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    }
    return false;
}
Also used : DelayedRegistration(org.spongepowered.api.registry.util.DelayedRegistration) Method(java.lang.reflect.Method)

Example 7 with DelayedRegistration

use of org.spongepowered.api.registry.util.DelayedRegistration in project LanternServer by LanternPowered.

the class LanternCraftingRecipeRegistryModule method registerDefaults.

@DelayedRegistration(RegistrationPhase.POST_INIT)
@Override
public void registerDefaults() {
    try {
        ReflectionHelper.setField(Ingredient.class.getField("NONE"), null, IIngredient.builder().with(ItemStack::isEmpty).withDisplay(ItemTypes.NONE).build());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    PluginContainer plugin = Lantern.getMinecraftPlugin();
    register(ICraftingRecipe.shapedBuilder().aisle("x", "x").where('x', Ingredient.of(ItemTypes.PLANKS)).result(ItemStack.of(ItemTypes.STICK, 4)).build("stick", plugin));
    // Extra, testing stuff
    plugin = Lantern.getImplementationPlugin();
    ItemStack result = ItemStack.of(ItemTypes.GOLD_NUGGET, 4);
    result.offer(Keys.DISPLAY_NAME, Text.of(TextColors.GOLD, "€1"));
    register(ICraftingRecipe.shapedBuilder().aisle("x", "y").where('x', Ingredient.of(ItemTypes.GOLD_INGOT)).where('y', IIngredient.builder().with(ItemTypes.LAVA_BUCKET).withRemaining(ItemTypes.BUCKET).build()).result(result).build("one_euro", plugin));
    // Two sticks?
    register(ICraftingRecipe.shapelessBuilder().addIngredients(Ingredient.of(ItemTypes.STICK), 2).result(ItemStack.of(ItemTypes.STICK, 2)).build("two_sticks", plugin));
    // Two buckets?
    result = ItemStack.of(ItemTypes.LAVA_BUCKET, 1);
    result.offer(Keys.DISPLAY_NAME, Text.of(TextColors.GOLD, "¿Compressed Lava?"));
    register(ICraftingRecipe.shapelessBuilder().addIngredient(Ingredient.of(ItemTypes.LAVA_BUCKET)).addIngredient(IIngredient.builder().with(ItemTypes.LAVA_BUCKET).withRemaining(ItemTypes.BUCKET).build()).result(result).build("compressed_lava", plugin));
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer) IIngredient(org.lanternpowered.server.item.recipe.IIngredient) Ingredient(org.spongepowered.api.item.recipe.crafting.Ingredient) ItemStack(org.spongepowered.api.item.inventory.ItemStack) DelayedRegistration(org.spongepowered.api.registry.util.DelayedRegistration)

Aggregations

DelayedRegistration (org.spongepowered.api.registry.util.DelayedRegistration)7 PluginContainer (org.spongepowered.api.plugin.PluginContainer)4 Method (java.lang.reflect.Method)2 ItemStack (org.spongepowered.api.item.inventory.ItemStack)2 CustomCatalogRegistration (org.spongepowered.api.registry.util.CustomCatalogRegistration)2 HashMultimap (com.google.common.collect.HashMultimap)1 Multimap (com.google.common.collect.Multimap)1 Gson (com.google.gson.Gson)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1