diff --git a/ee3_common/com/pahimar/ee3/core/helper/ItemHelper.java b/ee3_common/com/pahimar/ee3/core/helper/ItemHelper.java index e4f9770f..17b5d931 100644 --- a/ee3_common/com/pahimar/ee3/core/helper/ItemHelper.java +++ b/ee3_common/com/pahimar/ee3/core/helper/ItemHelper.java @@ -2,6 +2,7 @@ package com.pahimar.ee3.core.helper; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -21,6 +22,19 @@ import com.pahimar.ee3.lib.Strings; public class ItemHelper { private static double rand; + + public static boolean compare(ItemStack first, ItemStack second) { + + if ((first != null) && (second != null)) { + if (first.itemID == second.itemID) { + if (first.getItemDamage() == second.getItemDamage()) { + return true; + } + } + } + + return false; + } public static boolean hasColor(ItemStack itemStack) { diff --git a/ee3_common/com/pahimar/ee3/core/helper/RecipeHelper.java b/ee3_common/com/pahimar/ee3/core/helper/RecipeHelper.java index a636d48e..d8b864ad 100644 --- a/ee3_common/com/pahimar/ee3/core/helper/RecipeHelper.java +++ b/ee3_common/com/pahimar/ee3/core/helper/RecipeHelper.java @@ -26,13 +26,19 @@ import cpw.mods.fml.common.registry.GameRegistry; */ public class RecipeHelper { - @SuppressWarnings("unchecked") - // TODO: Not ideal, can be cleaned up further - public static List getRecipeInputs(IRecipe recipe) { + /** + * Returns a list of ItemStacks that represent the itemstacks that make up the given IRecipe + * + * @param recipe The IRecipe being examined + * @return List of ItemStacks that constitute the inputs of the recipe, null if unable to access the inputs of the given IRecipe + */ + public static ArrayList getRecipeInputs(IRecipe recipe) { + ArrayList recipeInputs = null; if (recipe instanceof ShapedRecipes) { + ShapedRecipes shapedRecipe = (ShapedRecipes) recipe; - ArrayList recipeInputs = new ArrayList(); + recipeInputs = new ArrayList(); for (int i = 0; i < shapedRecipe.recipeItems.length; i++) { if (shapedRecipe.recipeItems[i] != null) { @@ -43,43 +49,67 @@ public class RecipeHelper { return recipeInputs; } else if (recipe instanceof ShapelessRecipes) { - return ((ShapelessRecipes) recipe).recipeItems; + + ShapelessRecipes shapelessRecipe = (ShapelessRecipes) recipe; + + recipeInputs = new ArrayList(shapelessRecipe.recipeItems); + + return recipeInputs; } else if (recipe instanceof ShapedOreRecipe) { - ShapedOreRecipe shapedRecipe = (ShapedOreRecipe) recipe; - ArrayList recipeInputs = new ArrayList(); + + ShapedOreRecipe shapedOreRecipe = (ShapedOreRecipe) recipe; + recipeInputs = new ArrayList(); - for (int i = 0; i < shapedRecipe.getInput().length; i++) { - if (shapedRecipe.getInput()[i] != null) { - recipeInputs.add(shapedRecipe.getInput()[i]); + for (int i = 0; i < shapedOreRecipe.getInput().length; i++) { + if (shapedOreRecipe.getInput()[i] instanceof ArrayList) { + ArrayList shapedOreRecipeInputs = (ArrayList) shapedOreRecipe.getInput()[i]; + + for (ItemStack itemStack : shapedOreRecipeInputs) { + recipeInputs.add(itemStack); + } } } return recipeInputs; } + // TODO: Ore Dict recipes should populate some sort of equivalency portion of the dynEMC system + // TODO: Recipe Inputs should populate into separate lists, so that the emc of the lists can be determined and minimized else if (recipe instanceof ShapelessOreRecipe) { + + ShapelessOreRecipe shapelessOreRecipe = (ShapelessOreRecipe) recipe; + recipeInputs = new ArrayList(); + + for (Object recipeInput : shapelessOreRecipe.getInput()) { + if (recipeInput instanceof ArrayList) { + ArrayList shapelessOreRecipeInputs = (ArrayList) recipeInput; + + for (ItemStack itemStack : shapelessOreRecipeInputs) { + recipeInputs.add(itemStack); + } + } + } + return ((ShapelessOreRecipe) recipe).getInput(); } - + return null; } - public static List getReverseRecipes(ItemStack itemStack) { + public static ArrayList getReverseRecipes(ItemStack itemStack) { - @SuppressWarnings("unchecked") - ArrayList recipeList = (ArrayList) CraftingManager.getInstance().getRecipeList(); + ArrayList craftingManagerRecipeList = new ArrayList(CraftingManager.getInstance().getRecipeList()); + ArrayList reverseRecipeList = new ArrayList(); - for (IRecipe recipe : recipeList) { + for (IRecipe recipe : craftingManagerRecipeList) { if (recipe.getRecipeOutput() != null) { - if ((recipe.getRecipeOutput().itemID == itemStack.itemID) && (recipe.getRecipeOutput().getItemDamage() == itemStack.getItemDamage())) { - System.out.println(recipe); - System.out.println(recipe.getRecipeOutput()); - System.out.println(getRecipeInputs(recipe)); + if (ItemHelper.compare(itemStack, recipe.getRecipeOutput())) { + reverseRecipeList.add(recipe); } } } - return null; + return reverseRecipeList; } public static void addRecipe(ItemStack output, Object... input) {