Search in sources :

Example 31 with Ingredient

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

the class GuideCraftingFactory method equals.

@Override
public boolean equals(Object obj) {
    if (obj == this)
        return true;
    if (obj == null)
        return false;
    if (obj.getClass() != getClass())
        return false;
    GuideCraftingFactory other = (GuideCraftingFactory) obj;
    // Shortcut out of this full itemstack comparison as its really expensive
    if (hash != other.hash)
        return false;
    if (input.getWidth() != other.input.getWidth() || input.getHeight() != other.input.getHeight())
        return false;
    NBTTagList nbtThis = new NBTTagList();
    for (Ingredient ingredient : this.input) {
        NBTTagList list = new NBTTagList();
        for (ItemStack stack : ingredient.getMatchingStacks()) {
            list.appendTag(stack.serializeNBT());
        }
        nbtThis.appendTag(list);
    }
    NBTTagList nbtThat = new NBTTagList();
    for (Ingredient ingredient : other.input) {
        NBTTagList list = new NBTTagList();
        for (ItemStack stack : ingredient.getMatchingStacks()) {
            list.appendTag(stack.serializeNBT());
        }
        nbtThat.appendTag(list);
    }
    return nbtThis.equals(nbtThat);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) Ingredient(net.minecraft.item.crafting.Ingredient) ItemStack(net.minecraft.item.ItemStack)

Example 32 with Ingredient

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

the class BCTransportRecipes method addPipeUpgradeRecipe.

private static void addPipeUpgradeRecipe(ItemPipeHolder from, ItemPipeHolder to, Object additional) {
    if (from == null || to == null) {
        return;
    }
    if (additional == null) {
        throw new NullPointerException("additional");
    }
    IRecipe returnRecipe = new ShapelessOreRecipe(from.getRegistryName(), new ItemStack(from), new ItemStack(to)).setRegistryName(new ResourceLocation(from.getRegistryName() + "_undo"));
    ForgeRegistries.RECIPES.register(returnRecipe);
    NonNullList<Ingredient> list = NonNullList.create();
    list.add(Ingredient.fromItem(from));
    list.add(CraftingHelper.getIngredient(additional));
    IRecipe upgradeRecipe = new ShapelessRecipes(to.getRegistryName().getResourcePath(), new ItemStack(to), list).setRegistryName(new ResourceLocation(to.getRegistryName() + "_colorless"));
    ForgeRegistries.RECIPES.register(upgradeRecipe);
    for (EnumDyeColor colour : ColourUtil.COLOURS) {
        ItemStack f = new ItemStack(from, 1, colour.getMetadata() + 1);
        ItemStack t = new ItemStack(to, 1, colour.getMetadata() + 1);
        IRecipe returnRecipeColored = new ShapelessOreRecipe(from.getRegistryName(), f, t).setRegistryName(new ResourceLocation(from.getRegistryName() + colour.getName() + "_undo"));
        ForgeRegistries.RECIPES.register(returnRecipeColored);
        NonNullList<Ingredient> colorList = NonNullList.create();
        colorList.add(Ingredient.fromStacks(f));
        colorList.add(CraftingHelper.getIngredient(additional));
        IRecipe upgradeRecipeColored = new ShapelessOreRecipe(to.getRegistryName(), colorList, t).setRegistryName(new ResourceLocation(to.getRegistryName() + "_" + colour.getName()));
        ForgeRegistries.RECIPES.register(upgradeRecipeColored);
    }
}
Also used : IRecipe(net.minecraft.item.crafting.IRecipe) Ingredient(net.minecraft.item.crafting.Ingredient) ResourceLocation(net.minecraft.util.ResourceLocation) ShapelessOreRecipe(net.minecraftforge.oredict.ShapelessOreRecipe) ItemStack(net.minecraft.item.ItemStack) ShapelessRecipes(net.minecraft.item.crafting.ShapelessRecipes) EnumDyeColor(net.minecraft.item.EnumDyeColor)

Example 33 with Ingredient

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

the class GuiAdvancedCraftingTable method sendRecipe.

private void sendRecipe(IRecipe recipe) {
    List<ItemStack> stacks = new ArrayList<>(9);
    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;
    List<Ingredient> ingredients = recipe.getIngredients();
    if (ingredients.isEmpty()) {
        return;
    }
    for (int y = 0; y < 3; y++) {
        for (int x = 0; x < 3; x++) {
            if (x < offsetX || y < offsetY) {
                stacks.add(ItemStack.EMPTY);
                continue;
            }
            int i = x - offsetX + (y - offsetY) * maxX;
            if (i >= ingredients.size() || x - offsetX >= maxX) {
                stacks.add(ItemStack.EMPTY);
            } else {
                Ingredient ing = ingredients.get(i);
                ItemStack[] matching = ing.getMatchingStacks();
                if (matching.length >= 1) {
                    stacks.add(matching[0]);
                } else {
                    stacks.add(ItemStack.EMPTY);
                }
            }
        }
    }
    container.sendSetPhantomSlots(container.tile.invBlueprint, stacks);
}
Also used : Ingredient(net.minecraft.item.crafting.Ingredient) ArrayList(java.util.ArrayList) IShapedRecipe(net.minecraftforge.common.crafting.IShapedRecipe) ItemStack(net.minecraft.item.ItemStack)

Example 34 with Ingredient

use of net.minecraft.item.crafting.Ingredient in project pnc-repressurized by TeamPneumatic.

the class CraftingRegistrator method addPressureChamberStorageBlockRecipes.

/**
 * Adds recipes like 9 gold ingot --> 1 gold block, and 1 gold block --> 9 gold ingots.
 */
public static void addPressureChamberStorageBlockRecipes() {
    // search for a 3x3 recipe where all 9 ingredients are the same
    for (IRecipe recipe : CraftingManager.REGISTRY) {
        if (recipe instanceof ShapedRecipes) {
            ShapedRecipes shaped = (ShapedRecipes) recipe;
            NonNullList<Ingredient> ingredients = recipe.getIngredients();
            ItemStack ref = ingredients.get(0).getMatchingStacks()[0];
            if (ref.isEmpty() || ingredients.size() < 9)
                continue;
            boolean valid = true;
            for (int i = 0; i < 9; i++) {
                ItemStack stack = ingredients.get(i).getMatchingStacks()[0];
                if (!stack.isItemEqual(ref)) {
                    valid = false;
                    break;
                }
            }
            if (valid) {
                ItemStack inputStack = ref.copy();
                inputStack.setCount(9);
                PressureChamberRecipe.chamberRecipes.add(new PressureChamberRecipe(new ItemStack[] { inputStack }, 1.0F, new ItemStack[] { shaped.getRecipeOutput() }, false));
                ItemStack inputStack2 = shaped.getRecipeOutput().copy();
                inputStack2.setCount(1);
                PressureChamberRecipe.chamberRecipes.add(new PressureChamberRecipe(new ItemStack[] { inputStack2 }, -0.5F, new ItemStack[] { inputStack }, false));
            }
        }
    }
}
Also used : ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) IRecipe(net.minecraft.item.crafting.IRecipe) Ingredient(net.minecraft.item.crafting.Ingredient) ItemStack(net.minecraft.item.ItemStack)

Example 35 with Ingredient

use of net.minecraft.item.crafting.Ingredient in project FoodCraft-Reloaded by LasmGratel.

the class RecipeManager method getIngredientRecipeNullable.

@Nullable
public <T, R extends Recipe<T>> R getIngredientRecipeNullable(Class<R> recipeClass, T input) {
    if (!(input instanceof RecipeInput) && !((((RecipeInput) input).value instanceof ItemStack[]) || ((RecipeInput) input).value instanceof Item[]))
        return null;
    return getRecipes(recipeClass).stream().filter(recipe -> recipe.getInput() instanceof RecipeInput).filter(recipe -> ((RecipeInput) recipe.getInput()).getValue() instanceof Ingredient[]).filter(recipe -> ((RecipeInput) recipe.getInput()).getValue().length == ((RecipeInput) input).getValue().length).filter(recipe -> {
        Ingredient[] ingredients = (Ingredient[]) ((RecipeInput) recipe.getInput()).getValue();
        Object[] inputs = ((RecipeInput) input).getValue();
        for (int i = 0; i < inputs.length; i++) {
            ItemStack stack;
            if (inputs[i] instanceof Item)
                stack = new ItemStack((Item) inputs[i]);
            else
                stack = (ItemStack) inputs[i];
            if (!ingredients[i].apply(stack))
                return false;
        }
        return true;
    }).findAny().orElse(null);
}
Also used : ItemStack(net.minecraft.item.ItemStack) Ingredient(net.minecraft.item.crafting.Ingredient) java.util(java.util) Item(net.minecraft.item.Item) Nullable(javax.annotation.Nullable) Item(net.minecraft.item.Item) Ingredient(net.minecraft.item.crafting.Ingredient) ItemStack(net.minecraft.item.ItemStack) Nullable(javax.annotation.Nullable)

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