Search in sources :

Example 16 with ShapedRecipes

use of net.minecraft.item.crafting.ShapedRecipes in project Engine by VoltzEngine-Project.

the class AutoCraftingManager method getIdealRecipe.

/**
 * Does this player's inventory contain the required resources to craft this item?
 *
 * @return Required items to make the desired item.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public Pair<ItemStack, ItemStack[]> getIdealRecipe(ItemStack outputItem) {
    this.printDebug("IdealRecipe", outputItem.toString());
    for (IRecipe object : RecipeUtility.getRecipesByOutput(outputItem)) {
        if (AutoCraftingManager.areStacksEqual(outputItem, object.getRecipeOutput())) {
            this.printDebug("IdealRecipe", "Output Match Found");
            if (object instanceof ShapedRecipes) {
                if (this.hasResource(((ShapedRecipes) object).recipeItems) != null) {
                    this.printDebug("IdealRecipe", "Shaped Recipe Found");
                    return new Pair<>(object.getRecipeOutput().copy(), ((ShapedRecipes) object).recipeItems);
                }
            } else if (object instanceof ShapelessRecipes) {
                if (this.hasResource(((ShapelessRecipes) object).recipeItems.toArray(new ItemStack[1])) != null) {
                    this.printDebug("IdealRecipe", "Shapeless Recipe Found");
                    return new Pair<>(object.getRecipeOutput().copy(), (ItemStack[]) ((ShapelessRecipes) object).recipeItems.toArray(new ItemStack[1]));
                }
            } else if (object instanceof ShapedOreRecipe) {
                ShapedOreRecipe oreRecipe = (ShapedOreRecipe) object;
                Object[] oreRecipeInput = ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, oreRecipe, "input");
                ArrayList<ItemStack> hasResources = this.hasResource(oreRecipeInput);
                if (hasResources != null) {
                    this.printDebug("IdealRecipe", "ShapedOre Recipe Found");
                    return new Pair<>(object.getRecipeOutput().copy(), hasResources.toArray(new ItemStack[1]));
                }
            } else if (object instanceof ShapelessOreRecipe) {
                ShapelessOreRecipe oreRecipe = (ShapelessOreRecipe) object;
                ArrayList oreRecipeInput = ReflectionHelper.getPrivateValue(ShapelessOreRecipe.class, oreRecipe, "input");
                List<ItemStack> hasResources = this.hasResource(oreRecipeInput.toArray());
                if (hasResources != null) {
                    this.printDebug("IdealRecipe", "ShapelessOre Recipe Found");
                    return new Pair<>(object.getRecipeOutput().copy(), hasResources.toArray(new ItemStack[1]));
                }
            }
        }
    }
    return null;
}
Also used : ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) IRecipe(net.minecraft.item.crafting.IRecipe) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) ArrayList(java.util.ArrayList) ShapelessOreRecipe(net.minecraftforge.oredict.ShapelessOreRecipe) ArrayList(java.util.ArrayList) List(java.util.List) ShapelessRecipes(net.minecraft.item.crafting.ShapelessRecipes) ItemStack(net.minecraft.item.ItemStack) Pair(com.builtbroken.jlib.type.Pair)

Example 17 with ShapedRecipes

use of net.minecraft.item.crafting.ShapedRecipes 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 18 with ShapedRecipes

use of net.minecraft.item.crafting.ShapedRecipes in project SpongeCommon by SpongePowered.

the class SpongeShapedCraftingRecipeBuilder method from.

@Override
public ShapedCraftingRecipe.Builder from(ShapedCraftingRecipe value) {
    this.aisle.clear();
    this.ingredientMap.clear();
    this.groupName = "";
    if (value instanceof ShapedRecipes) {
        this.groupName = ((ShapedRecipes) value).group;
    }
    if (value != null) {
        for (int y = 0; y < value.getHeight(); y++) {
            String row = "";
            for (int x = 0; x < value.getWidth(); x++) {
                char symbol = (char) ('a' + x + y * value.getWidth());
                row += symbol;
                Ingredient ingredient = value.getIngredient(x, y);
                this.ingredientMap.put(symbol, ingredient);
            }
            this.aisle.add(row);
        }
        this.result = value.getExemplaryResult().createStack();
    } else {
        this.result = null;
    }
    return this;
}
Also used : ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) Ingredient(org.spongepowered.api.item.recipe.crafting.Ingredient)

Example 19 with ShapedRecipes

use of net.minecraft.item.crafting.ShapedRecipes in project Charset by CharsetMC.

the class RecipeReplacement method process.

public void process(Collection<IRecipe> registry) {
    for (IRecipe recipe : registry) {
        ResourceLocation recipeName = recipe.getRegistryName();
        boolean dirty = false;
        if (recipe instanceof ShapedRecipes || recipe instanceof ShapelessRecipes || recipe instanceof ShapedOreRecipe || recipe instanceof ShapelessOreRecipe) {
            NonNullList<Ingredient> ingredients = recipe.getIngredients();
            for (int i = 0; i < ingredients.size(); i++) {
                Ingredient ing = ingredients.get(i);
                Ingredient ingNew = replaceIngredient(ing);
                if (ingNew != null) {
                    ingredients.set(i, ingNew);
                    dirty = true;
                }
            }
        } else if (recipe instanceof RecipeCharset) {
            TCharObjectMap<Ingredient> charToIngredient = ((RecipeCharset) recipe).charToIngredient;
            NonNullList<Ingredient> ingredients = recipe.getIngredients();
            for (int i = 0; i < ingredients.size(); i++) {
                Ingredient ing = ingredients.get(i);
                Ingredient ingNew = replaceIngredient(ing);
                if (ingNew != null) {
                    ingredients.set(i, ingNew);
                    TCharIterator iterator = charToIngredient.keySet().iterator();
                    while (iterator.hasNext()) {
                        char c = iterator.next();
                        if (charToIngredient.get(c) == ing) {
                            charToIngredient.put(c, ing);
                        }
                    }
                    dirty = true;
                }
            }
        }
        if (dirty) {
            ModCharset.logger.info("Successfully edited " + recipeName + "!");
        }
    }
}
Also used : ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) IRecipe(net.minecraft.item.crafting.IRecipe) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) TCharIterator(gnu.trove.iterator.TCharIterator) TCharObjectMap(gnu.trove.map.TCharObjectMap) Ingredient(net.minecraft.item.crafting.Ingredient) OreIngredient(net.minecraftforge.oredict.OreIngredient) NonNullList(net.minecraft.util.NonNullList) ResourceLocation(net.minecraft.util.ResourceLocation) ShapelessOreRecipe(net.minecraftforge.oredict.ShapelessOreRecipe) ShapelessRecipes(net.minecraft.item.crafting.ShapelessRecipes)

Example 20 with ShapedRecipes

use of net.minecraft.item.crafting.ShapedRecipes in project Galacticraft by micdoodle8.

the class ShapedRecipeHandler method loadUsageRecipes.

@Override
public void loadUsageRecipes(ItemStack ingredient) {
    for (IRecipe irecipe : (List<IRecipe>) CraftingManager.getInstance().getRecipeList()) {
        CachedShapedRecipe recipe = null;
        if (irecipe instanceof ShapedRecipes) {
            recipe = new CachedShapedRecipe((ShapedRecipes) irecipe);
        } else if (irecipe instanceof ShapedOreRecipe) {
            recipe = forgeShapedRecipe((ShapedOreRecipe) irecipe);
        }
        if (recipe == null || !recipe.contains(recipe.ingredients, ingredient.getItem())) {
            continue;
        }
        recipe.computeVisuals();
        if (recipe.contains(recipe.ingredients, ingredient)) {
            recipe.setIngredientPermutation(recipe.ingredients, ingredient);
            arecipes.add(recipe);
        }
    }
}
Also used : ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) IRecipe(net.minecraft.item.crafting.IRecipe) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ShapedRecipes (net.minecraft.item.crafting.ShapedRecipes)28 ItemStack (net.minecraft.item.ItemStack)19 IRecipe (net.minecraft.item.crafting.IRecipe)18 ShapedOreRecipe (net.minecraftforge.oredict.ShapedOreRecipe)14 ShapelessRecipes (net.minecraft.item.crafting.ShapelessRecipes)13 ArrayList (java.util.ArrayList)10 ShapelessOreRecipe (net.minecraftforge.oredict.ShapelessOreRecipe)8 List (java.util.List)6 Item (net.minecraft.item.Item)6 HashMap (java.util.HashMap)5 Block (net.minecraft.block.Block)5 Ingredient (net.minecraft.item.crafting.Ingredient)5 ResourceLocation (net.minecraft.util.ResourceLocation)3 Pair (com.builtbroken.jlib.type.Pair)2 ItemBlock (net.minecraft.item.ItemBlock)2 SpellRecipeItemsEvent (am2.api.events.SpellRecipeItemsEvent)1 ISkillTreeEntry (am2.api.spell.component.interfaces.ISkillTreeEntry)1 ISpellPart (am2.api.spell.component.interfaces.ISpellPart)1 ItemSpellPart (am2.items.ItemSpellPart)1 RecipeArsMagica (am2.items.RecipeArsMagica)1