Search in sources :

Example 41 with Ingredient

use of net.minecraft.item.crafting.Ingredient in project MC-Prefab by Brian-Wuest.

the class ModRegistry method AddShapelessRecipe.

/**
 * This should only be used for registering recipes for vanilla objects and not mod-specific objects.
 * @param name The name of the recipe.
 * @param stack The output stack.
 * @param recipeComponents The recipe components.
 */
public static ShapelessRecipes AddShapelessRecipe(String name, String groupName, ItemStack stack, Object... recipeComponents) {
    name = Prefab.MODID.toLowerCase().replace(' ', '_') + ":" + name;
    NonNullList<Ingredient> list = NonNullList.create();
    for (Object object : recipeComponents) {
        if (object instanceof ItemStack) {
            list.add(Ingredient.fromStacks(((ItemStack) object).copy()));
        } else if (object instanceof Item) {
            list.add(Ingredient.fromStacks(new ItemStack((Item) object)));
        } else {
            if (!(object instanceof Block)) {
                throw new IllegalArgumentException("Invalid shapeless recipe: unknown type " + object.getClass().getName() + "!");
            }
            list.add(Ingredient.fromStacks(new ItemStack((Block) object)));
        }
    }
    ShapelessRecipes shapelessRecipes = new ShapelessRecipes(groupName, stack, list);
    shapelessRecipes.setRegistryName(name);
    ForgeRegistries.RECIPES.register(shapelessRecipes);
    return shapelessRecipes;
}
Also used : Item(net.minecraft.item.Item) Ingredient(net.minecraft.item.crafting.Ingredient) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) ItemStack(net.minecraft.item.ItemStack) ShapelessRecipes(net.minecraft.item.crafting.ShapelessRecipes)

Example 42 with Ingredient

use of net.minecraft.item.crafting.Ingredient in project Solar by Martacus.

the class TileOfferingShrine method onUse.

public void onUse(EntityPlayer player, EnumHand hand) {
    ItemStack heldItem = player.getHeldItem(hand);
    if (heldItem.getItem() == ModItems.RITUAL_AMULET) {
        if (!this.validMultiblock()) {
            // todo: let player know multiblock aint valid maybe?
            return;
        }
        LinkedList<ItemStack> itemStacks = this.itemStackHandler.getOfferItemStacks();
        List<OfferingRecipe> offeringRecipes = OfferingRecipeRegister.getRecipes();
        for (OfferingRecipe recipe : offeringRecipes) {
            boolean matches = true;
            List<Ingredient> ingredients = recipe.getIngredients();
            for (int i = 7; i >= 0; i--) {
                ItemStack ingredientStack = ingredients.get(i).getMatchingStacks()[0];
                if (!itemStacks.get(i).isItemEqual(ingredientStack)) {
                    matches = false;
                }
            }
            if (matches) {
                this.offeringRecipe = OfferingRecipeRegister.getRegistrationName(recipe);
                notifyUpdate();
                break;
            }
        }
        return;
    }
    ItemStack returnStack;
    ItemStack insertStack = heldItem.copy();
    insertStack.setCount(1);
    returnStack = this.itemStackHandler.insertItem(insertStack, false);
    if (returnStack.isEmpty()) {
        if (heldItem.getCount() <= 1) {
            player.setHeldItem(hand, ItemStack.EMPTY);
        } else {
            heldItem.setCount(heldItem.getCount() - 1);
        }
    }
    notifyUpdate();
}
Also used : Ingredient(net.minecraft.item.crafting.Ingredient) OfferingRecipe(com.mart.solar.api.recipes.OfferingRecipe) ItemStack(net.minecraft.item.ItemStack)

Example 43 with Ingredient

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

the class GuiAutoCraftItems 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 44 with Ingredient

use of net.minecraft.item.crafting.Ingredient in project RebornCore by TechReborn.

the class RebornCraftingHelper method buildInput.

/**
 * Converts an object array into a NonNullList of Ingredients
 */
private static NonNullList<Ingredient> buildInput(Object[] input) {
    NonNullList<Ingredient> list = NonNullList.create();
    for (Object obj : input) {
        if (obj instanceof Ingredient) {
            list.add((Ingredient) obj);
        } else {
            Ingredient ingredient = CraftingHelper.getIngredient(obj);
            if (ingredient == null) {
                ingredient = Ingredient.EMPTY;
            }
            list.add(ingredient);
        }
    }
    return list;
}
Also used : Ingredient(net.minecraft.item.crafting.Ingredient)

Example 45 with Ingredient

use of net.minecraft.item.crafting.Ingredient in project Wizardry by TeamWizardry.

the class FluidRecipeJEI method getIngredients.

@Override
public void getIngredients(@Nonnull IIngredients ingredients) {
    List<List<ItemStack>> stacks = Lists.newArrayList();
    stacks.add(Lists.newArrayList(builder.getMainInput().getMatchingStacks()));
    for (Ingredient ingredient : builder.getInputs()) stacks.add(Lists.newArrayList(ingredient.getMatchingStacks()));
    if (!isFluidOutput())
        for (List<ItemStack> stackList : stacks) stackList.removeIf(Ingredient.fromStacks(builder.getOutput())::apply);
    ingredients.setInputLists(ItemStack.class, stacks);
    ingredients.setInput(FluidStack.class, new FluidStack(builder.getFluid(), 1000));
    if (isFluidOutput())
        ingredients.setOutput(FluidStack.class, builder.getFluidOutput());
    else
        ingredients.setOutput(ItemStack.class, builder.getOutput());
}
Also used : Ingredient(net.minecraft.item.crafting.Ingredient) FluidStack(net.minecraftforge.fluids.FluidStack) List(java.util.List) 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