Search in sources :

Example 26 with Ingredient

use of net.minecraft.item.crafting.Ingredient in project Bewitchment by Um-Mitternacht.

the class SpinningThreadRecipe method matches.

public boolean matches(NonNullList<ItemStack> list) {
    int nonEmpty = 0;
    for (ItemStack is : list) {
        if (is.getCount() > 0)
            nonEmpty++;
    }
    if (nonEmpty != inputs.length) {
        return false;
    }
    boolean[] found = new boolean[inputs.length];
    ArrayList<ItemStack> comp = new ArrayList<ItemStack>(list);
    for (int i = 0; i < inputs.length; i++) {
        Ingredient current = inputs[i];
        for (int j = 0; j < comp.size(); j++) {
            ItemStack is = comp.get(j);
            if (current.apply(is)) {
                found[i] = true;
                comp.set(j, ItemStack.EMPTY);
                break;
            }
        }
    }
    for (boolean b : found) {
        if (!b) {
            return false;
        }
    }
    return true;
}
Also used : Ingredient(net.minecraft.item.crafting.Ingredient) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Example 27 with Ingredient

use of net.minecraft.item.crafting.Ingredient in project Bewitchment by Um-Mitternacht.

the class ModSpinningThreadRecipes method init.

public static void init() {
    Ingredient string = Ingredient.fromItem(Items.STRING);
    web = new SpinningThreadRecipe(LibMod.MOD_ID, "spider_web", new ItemStack(Blocks.WEB), string, string, string);
    // soulstring = new SpinningThreadRecipe(LibMod.MOD_ID, "soulstring", new ItemStack(ModItems.soulstring), string, string, Ingredient.fromStacks(new ItemStack(ModItems.misc, 1, 5)), Ingredient.fromStacks(new ItemStack(ModItems.flowers, 1, 1)));
    registerAll();
}
Also used : Ingredient(net.minecraft.item.crafting.Ingredient) ItemStack(net.minecraft.item.ItemStack)

Example 28 with Ingredient

use of net.minecraft.item.crafting.Ingredient in project Bewitchment by Um-Mitternacht.

the class AdapterIRitual method isValidInput.

public boolean isValidInput(List<ItemStack> ground, boolean circles) {
    ArrayList<ItemStack> checklist = new ArrayList<ItemStack>(ground.size());
    for (ItemStack item : ground) for (int j = 0; j < item.getCount(); j++) {
        ItemStack copy = item.copy();
        copy.setCount(1);
        checklist.add(copy);
    }
    if (checklist.size() != ritual.getInput().size()) {
        return false;
    }
    ArrayList<Ingredient> removalList = new ArrayList<Ingredient>(ritual.getInput());
    for (ItemStack stack_on_ground : checklist) {
        Ingredient found = null;
        for (Ingredient ingredient : removalList) {
            if (ingredient.apply(stack_on_ground)) {
                found = ingredient;
                break;
            }
        }
        if (found == null) {
            return false;
        }
        removalList.remove(found);
    }
    if (!removalList.isEmpty()) {
        return false;
    }
    return circles;
}
Also used : Ingredient(net.minecraft.item.crafting.Ingredient) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Example 29 with Ingredient

use of net.minecraft.item.crafting.Ingredient in project Bewitchment by Um-Mitternacht.

the class SpinnerWrapper method getIngredients.

@Override
public void getIngredients(IIngredients ingredients) {
    ArrayList<List<ItemStack>> list = new ArrayList<List<ItemStack>>();
    for (Ingredient i : input) list.add(Arrays.asList(i.getMatchingStacks()));
    ingredients.setInputLists(ItemStack.class, list);
    ingredients.setOutput(ItemStack.class, output);
}
Also used : Ingredient(net.minecraft.item.crafting.Ingredient) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Example 30 with Ingredient

use of net.minecraft.item.crafting.Ingredient in project BuildCraft by BuildCraft.

the class GuideCraftingFactory method getFactory.

public static GuidePartFactory getFactory(IRecipe recipe) {
    ItemStack output = recipe.getRecipeOutput();
    NonNullList<Ingredient> input = recipe.getIngredients();
    if (input == null || input.isEmpty() || output.isEmpty()) {
        return null;
    }
    Ingredient[][] matrix = new Ingredient[3][3];
    int maxX = recipe instanceof IShapedRecipe ? ((IShapedRecipe) recipe).getRecipeWidth() : 3;
    int maxY = recipe instanceof IShapedRecipe ? ((IShapedRecipe) recipe).getRecipeHeight() : 3;
    int offsetX = maxX == 1 ? 1 : 0;
    int offsetY = maxY == 1 ? 1 : 0;
    for (int y = 0; y < 3; y++) {
        for (int x = 0; x < 3; x++) {
            if (x < offsetX || y < offsetY) {
                matrix[x][y] = Ingredient.EMPTY;
                continue;
            }
            int i = x - offsetX + (y - offsetY) * maxX;
            if (i >= input.size() || x - offsetX >= maxX) {
                matrix[x][y] = Ingredient.EMPTY;
            } else {
                matrix[x][y] = input.get(i);
            }
        }
    }
    return new GuideCraftingFactory(matrix, output);
}
Also used : Ingredient(net.minecraft.item.crafting.Ingredient) IShapedRecipe(net.minecraftforge.common.crafting.IShapedRecipe) ItemStack(net.minecraft.item.ItemStack)

Aggregations

Ingredient (net.minecraft.item.crafting.Ingredient)57 ItemStack (net.minecraft.item.ItemStack)49 ResourceLocation (net.minecraft.util.ResourceLocation)12 ArrayList (java.util.ArrayList)10 JsonElement (com.google.gson.JsonElement)8 JsonObject (com.google.gson.JsonObject)7 List (java.util.List)7 IRecipe (net.minecraft.item.crafting.IRecipe)7 JsonArray (com.google.gson.JsonArray)6 Block (net.minecraft.block.Block)6 Item (net.minecraft.item.Item)6 HashMap (java.util.HashMap)5 IBlockState (net.minecraft.block.state.IBlockState)5 ShapelessRecipes (net.minecraft.item.crafting.ShapelessRecipes)5 FluidStack (net.minecraftforge.fluids.FluidStack)5 JsonParser (com.google.gson.JsonParser)4 File (java.io.File)4 FileNotFoundException (java.io.FileNotFoundException)4 FileReader (java.io.FileReader)4 EntityItem (net.minecraft.entity.item.EntityItem)4