Search in sources :

Example 1 with IArtisanItemStack

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

the class TileEntitySecondaryInputBase method getSecondaryIngredientMatcher.

@Override
public ISecondaryIngredientMatcher getSecondaryIngredientMatcher() {
    int slotCount = this.secondaryIngredientHandler.getSlots();
    List<IArtisanItemStack> inputs = new ArrayList<>(slotCount);
    for (int i = 0; i < slotCount; i++) {
        ItemStack itemStack = this.secondaryIngredientHandler.getStackInSlot(i);
        inputs.add(ArtisanItemStack.from(itemStack));
    }
    return new SecondaryIngredientMatcher(inputs);
}
Also used : ISecondaryIngredientMatcher(com.codetaylor.mc.artisanworktables.api.internal.recipe.ISecondaryIngredientMatcher) SecondaryIngredientMatcher(com.codetaylor.mc.artisanworktables.modules.worktables.recipe.SecondaryIngredientMatcher) ArrayList(java.util.ArrayList) ArtisanItemStack(com.codetaylor.mc.artisanworktables.api.internal.recipe.ArtisanItemStack) ItemStack(net.minecraft.item.ItemStack) IArtisanItemStack(com.codetaylor.mc.artisanworktables.api.internal.recipe.IArtisanItemStack) IArtisanItemStack(com.codetaylor.mc.artisanworktables.api.internal.recipe.IArtisanItemStack)

Example 2 with IArtisanItemStack

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

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

the class RecipeBuilderCopyHelper method replaceRecipeOutput.

public static IRecipeBuilder replaceRecipeOutput(IRecipe recipe, IArtisanItemStack toReplace, IRecipeBuilder builder) throws RecipeBuilderException {
    ItemStack itemStack = toReplace.toItemStack();
    int count = recipe.getRecipeOutput().getCount();
    itemStack.setCount(count);
    builder.addOutput(ArtisanItemStack.from(itemStack), 1);
    return builder;
}
Also used : ArtisanItemStack(com.codetaylor.mc.artisanworktables.api.internal.recipe.ArtisanItemStack) ItemStack(net.minecraft.item.ItemStack) IArtisanItemStack(com.codetaylor.mc.artisanworktables.api.internal.recipe.IArtisanItemStack)

Aggregations

IArtisanItemStack (com.codetaylor.mc.artisanworktables.api.internal.recipe.IArtisanItemStack)3 ArtisanItemStack (com.codetaylor.mc.artisanworktables.api.internal.recipe.ArtisanItemStack)2 ItemStack (net.minecraft.item.ItemStack)2 IArtisanIngredient (com.codetaylor.mc.artisanworktables.api.internal.recipe.IArtisanIngredient)1 ISecondaryIngredientMatcher (com.codetaylor.mc.artisanworktables.api.internal.recipe.ISecondaryIngredientMatcher)1 SecondaryIngredientMatcher (com.codetaylor.mc.artisanworktables.modules.worktables.recipe.SecondaryIngredientMatcher)1 ArrayList (java.util.ArrayList)1