Search in sources :

Example 1 with IArtisanIngredient

use of com.codetaylor.mc.artisanworktables.api.internal.recipe.IArtisanIngredient 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 2 with IArtisanIngredient

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

the class SecondaryIngredientMatcher method matches.

@Override
public boolean matches(Collection<IArtisanIngredient> requiredIngredients) {
    for (int i = 0; i < this.inputs.size(); i++) {
        IArtisanItemStack iItemStack = this.inputs.get(i);
        this.availableAmounts[i] = (iItemStack != null) ? iItemStack.getAmount() : 0;
    }
    for (IArtisanIngredient recipeInput : requiredIngredients) {
        int amountRequired = recipeInput.getAmount();
        for (int i = 0; i < this.inputs.size(); i++) {
            IArtisanItemStack input = this.inputs.get(i);
            if (input == null) {
                continue;
            }
            if (recipeInput.matchesIgnoreAmount(input)) {
                if (this.availableAmounts[i] >= amountRequired) {
                    // more ingredients are available in this stack than are required
                    // adjust and break
                    this.availableAmounts[i] -= amountRequired;
                    amountRequired = 0;
                    break;
                } else {
                    // there aren't enough ingredients available to satisfy the entire requirement
                    // adjust and keep looking
                    amountRequired -= this.availableAmounts[i];
                    this.availableAmounts[i] = 0;
                }
            }
        }
        if (amountRequired > 0) {
            // the requirements were not met
            return false;
        }
    }
    return true;
}
Also used : IArtisanIngredient(com.codetaylor.mc.artisanworktables.api.internal.recipe.IArtisanIngredient) IArtisanItemStack(com.codetaylor.mc.artisanworktables.api.internal.recipe.IArtisanItemStack)

Example 3 with IArtisanIngredient

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

the class JEIRecipeWrapper method getInputs.

public List<List<ItemStack>> getInputs() {
    List<List<ItemStack>> result = new ArrayList<>();
    for (IArtisanIngredient input : this.artisanRecipe.getIngredientList()) {
        ItemStack[] matchingStacks = input.toIngredient().getMatchingStacks();
        List<ItemStack> list = new ArrayList<>(matchingStacks.length);
        for (ItemStack matchingStack : matchingStacks) {
            list.add(matchingStack.copy());
        }
        result.add(list);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IArtisanIngredient(com.codetaylor.mc.artisanworktables.api.internal.recipe.IArtisanIngredient) ItemStack(net.minecraft.item.ItemStack)

Example 4 with IArtisanIngredient

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

the class JEIRecipeWrapper method getSecondaryInputs.

public List<List<ItemStack>> getSecondaryInputs() {
    List<List<ItemStack>> result = new ArrayList<>();
    for (IArtisanIngredient ingredient : this.artisanRecipe.getSecondaryIngredients()) {
        ItemStack[] matchingStacks = ingredient.toIngredient().getMatchingStacks();
        List<ItemStack> list = new ArrayList<>(matchingStacks.length);
        for (ItemStack matchingStack : matchingStacks) {
            list.add(matchingStack.copy());
        }
        result.add(list);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IArtisanIngredient(com.codetaylor.mc.artisanworktables.api.internal.recipe.IArtisanIngredient) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IArtisanIngredient (com.codetaylor.mc.artisanworktables.api.internal.recipe.IArtisanIngredient)4 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ItemStack (net.minecraft.item.ItemStack)2 IArtisanItemStack (com.codetaylor.mc.artisanworktables.api.internal.recipe.IArtisanItemStack)1 RecipeBuilderException (com.codetaylor.mc.artisanworktables.api.internal.recipe.RecipeBuilderException)1 HashSet (java.util.HashSet)1 IRecipe (net.minecraft.item.crafting.IRecipe)1