Search in sources :

Example 1 with RecipeBuilderException

use of com.codetaylor.mc.artisanworktables.api.internal.recipe.RecipeBuilderException in project artisan-worktables by codetaylor.

the class IZenRecipeBuilderCopyStrategy method byRecipe.

@ZenMethod
static IZenRecipeBuilderCopyStrategy byRecipe(ICraftingRecipe recipe) {
    try {
        String registryName = recipe.getFullResourceName();
        IRecipe iRecipe = ForgeRegistries.RECIPES.getValue(new ResourceLocation(registryName));
        return new ZenRecipeBuilderCopyStrategy(RecipeBuilderInternal.Copy.byRecipe(iRecipe));
    } catch (RecipeBuilderException e) {
        CTLogHelper.logErrorFromZenMethod(e.getMessage());
        return ZenRecipeBuilderCopyStrategyNoOp.INSTANCE;
    }
}
Also used : IRecipe(net.minecraft.item.crafting.IRecipe) RecipeBuilderException(com.codetaylor.mc.artisanworktables.api.internal.recipe.RecipeBuilderException) ResourceLocation(net.minecraft.util.ResourceLocation) ZenMethod(stanhebben.zenscript.annotations.ZenMethod)

Example 2 with RecipeBuilderException

use of com.codetaylor.mc.artisanworktables.api.internal.recipe.RecipeBuilderException in project artisan-worktables by codetaylor.

the class RecipeBuilderCopyStrategyByOutput method apply.

@Override
public void apply(RecipeBuilderInternal recipeBuilder, List<RecipeBuilderInternal> resultList) throws RecipeBuilderException {
    Collection<IRecipe> recipes = ForgeRegistries.RECIPES.getValuesCollection();
    Set<IRecipe> toCopy = new HashSet<>();
    for (IRecipe recipe : recipes) {
        for (IArtisanIngredient copyRecipe : this.toCopy) {
            if (!recipe.getRecipeOutput().isEmpty() && copyRecipe.matches(recipe.getRecipeOutput())) {
                toCopy.add(recipe);
            }
        }
    }
    for (IRecipe recipe : toCopy) {
        try {
            this.doCopy(recipe, recipeBuilder.copy(), resultList);
        } catch (Exception e) {
            throw new RecipeBuilderException("Unable to copy recipe by output: " + recipe.getRegistryName(), e);
        }
    }
}
Also used : IRecipe(net.minecraft.item.crafting.IRecipe) RecipeBuilderException(com.codetaylor.mc.artisanworktables.api.internal.recipe.RecipeBuilderException) IArtisanIngredient(com.codetaylor.mc.artisanworktables.api.internal.recipe.IArtisanIngredient) RecipeBuilderException(com.codetaylor.mc.artisanworktables.api.internal.recipe.RecipeBuilderException) HashSet(java.util.HashSet)

Example 3 with RecipeBuilderException

use of com.codetaylor.mc.artisanworktables.api.internal.recipe.RecipeBuilderException in project artisan-worktables by codetaylor.

the class RecipeAdditionQueue method onRegisterRecipesEvent.

@SubscribeEvent(priority = EventPriority.LOWEST)
public void onRegisterRecipesEvent(RegistryEvent.Register<IRecipe> event) {
    for (RecipeBuilderInternal builder : this.recipeBuilderWithCopyList) {
        IRecipeBuilderCopyStrategyInternal recipeCopyStrategy = builder.getRecipeCopyStrategy();
        if (recipeCopyStrategy != null) {
            try {
                recipeCopyStrategy.apply(builder, this.recipeBuilderList);
            } catch (Exception e) {
                ModuleWorktables.LOG.error("", e);
            }
        }
    }
    for (RecipeBuilderInternal builder : this.recipeBuilderList) {
        try {
            builder.apply(LOGGER);
        } catch (RecipeBuilderException e) {
            ModuleWorktables.LOG.error("", e);
        }
    }
    this.recipeBuilderList.clear();
    this.recipeBuilderWithCopyList.clear();
}
Also used : IRecipeBuilderCopyStrategyInternal(com.codetaylor.mc.artisanworktables.modules.worktables.recipe.copy.IRecipeBuilderCopyStrategyInternal) RecipeBuilderException(com.codetaylor.mc.artisanworktables.api.internal.recipe.RecipeBuilderException) RecipeBuilderException(com.codetaylor.mc.artisanworktables.api.internal.recipe.RecipeBuilderException) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

RecipeBuilderException (com.codetaylor.mc.artisanworktables.api.internal.recipe.RecipeBuilderException)3 IRecipe (net.minecraft.item.crafting.IRecipe)2 IArtisanIngredient (com.codetaylor.mc.artisanworktables.api.internal.recipe.IArtisanIngredient)1 IRecipeBuilderCopyStrategyInternal (com.codetaylor.mc.artisanworktables.modules.worktables.recipe.copy.IRecipeBuilderCopyStrategyInternal)1 HashSet (java.util.HashSet)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 ZenMethod (stanhebben.zenscript.annotations.ZenMethod)1