Search in sources :

Example 1 with IIngredient

use of crafttweaker.api.item.IIngredient in project artisan-worktables by codetaylor.

the class CTArtisanRecipe method getRemainingItems.

@Nonnull
@Override
protected List<ItemStack> getRemainingItems(ICraftingContext context, NonNullList<ItemStack> itemStacks) {
    MatchInfo matchInfo;
    if (this.isShaped()) {
        matchInfo = this.getStacksShaped(context);
    } else {
        matchInfo = this.getStacksShapeless(context);
    }
    ICraftingMatrixStackHandler matrixHandler = context.getCraftingMatrixHandler();
    List<IArtisanIngredient> ingredients = this.getIngredientList();
    IItemStack[] stacks = matchInfo.getStacks();
    int[] matrixIndices = matchInfo.getMatrixIndices();
    for (int i = 0; i < ingredients.size(); i++) {
        IArtisanIngredient artisanIngredient = ingredients.get(i);
        if (artisanIngredient.isEmpty()) {
            continue;
        }
        if (artisanIngredient instanceof CTArtisanIngredient) {
            IIngredient ingredient = ((CTArtisanIngredient) artisanIngredient).getIngredient();
            if (ingredient.hasNewTransformers()) {
                IItemStack remainingItem = null;
                try {
                    remainingItem = ingredient.applyNewTransform(stacks[i]);
                } catch (Throwable e) {
                    CraftTweakerAPI.logError("Could not execute NewRecipeTransformer on " + ingredient.toCommandString(), e);
                }
                itemStacks.set(matrixIndices[i], CraftTweakerMC.getItemStack(remainingItem));
            }
        } else {
            itemStacks.set(matrixIndices[i], Util.getContainerItem(matrixHandler.getStackInSlot(matrixIndices[i])));
        }
    }
    return itemStacks;
}
Also used : IIngredient(crafttweaker.api.item.IIngredient) IItemStack(crafttweaker.api.item.IItemStack) Nonnull(javax.annotation.Nonnull)

Example 2 with IIngredient

use of crafttweaker.api.item.IIngredient in project HorsePower by GoryMoon.

the class TweakerPluginImpl method convert.

public static IRecipe convert(CTShapedChoppingRecipe recipe, ResourceLocation name) {
    IIngredient[] ingredients = recipe.getIngredients();
    byte[] posx = recipe.getIngredientsX();
    byte[] posy = recipe.getIngredientsY();
    int counter;
    Object[] converted = new Object[recipe.getHeight() * recipe.getWidth()];
    for (counter = 0; counter < ingredients.length; ++counter) {
        converted[posx[counter] + posy[counter] * recipe.getWidth()] = ingredients[counter].getInternal();
    }
    counter = 0;
    String[] parts = new String[recipe.getHeight()];
    ArrayList rarguments = new ArrayList();
    for (int i = 0; i < recipe.getHeight(); ++i) {
        char[] pattern = new char[recipe.getWidth()];
        for (int j = 0; j < recipe.getWidth(); ++j) {
            int off = i * recipe.getWidth() + j;
            if (converted[off] == null) {
                pattern[j] = 32;
            } else {
                pattern[j] = (char) (65 + counter);
                rarguments.add(Character.valueOf(pattern[j]));
                rarguments.add(converted[off]);
                ++counter;
            }
        }
        parts[i] = new String(pattern);
    }
    rarguments.addAll(0, Arrays.asList(parts));
    return new se.gory_moon.horsepower.recipes.ShapedChoppingRecipe(name, Lists.newArrayList(getItemStacks(recipe.getOre().getItems())), (ItemStack) recipe.getOutput().getInternal(), rarguments.toArray());
}
Also used : IIngredient(crafttweaker.api.item.IIngredient) ArrayList(java.util.ArrayList)

Aggregations

IIngredient (crafttweaker.api.item.IIngredient)2 IItemStack (crafttweaker.api.item.IItemStack)1 ArrayList (java.util.ArrayList)1 Nonnull (javax.annotation.Nonnull)1