diff --git a/ee3_common/com/pahimar/ee3/core/util/RecipeHelper.java b/ee3_common/com/pahimar/ee3/core/util/RecipeHelper.java index 1e38f935..1f72bd74 100644 --- a/ee3_common/com/pahimar/ee3/core/util/RecipeHelper.java +++ b/ee3_common/com/pahimar/ee3/core/util/RecipeHelper.java @@ -94,8 +94,16 @@ public class RecipeHelper { ShapedRecipes shapedRecipe = (ShapedRecipes) recipe; for (int i = 0; i < shapedRecipe.recipeItems.length; i++) { + if (shapedRecipe.recipeItems[i] instanceof ItemStack) { - recipeInputs.add(new CustomWrappedStack(shapedRecipe.recipeItems[i])); + + ItemStack itemStack = shapedRecipe.recipeItems[i].copy(); + + if (itemStack.stackSize > 1) { + itemStack.stackSize = 1; + } + + recipeInputs.add(new CustomWrappedStack(itemStack)); } } } @@ -104,8 +112,16 @@ public class RecipeHelper { ShapelessRecipes shapelessRecipe = (ShapelessRecipes) recipe; for (Object object : shapelessRecipe.recipeItems) { + if (object instanceof ItemStack) { - recipeInputs.add(new CustomWrappedStack(object)); + + ItemStack itemStack = ((ItemStack) object).copy(); + + if (itemStack.stackSize > 1) { + itemStack.stackSize = 1; + } + + recipeInputs.add(new CustomWrappedStack(itemStack)); } } } @@ -117,9 +133,19 @@ public class RecipeHelper { /* * If the element is a list, then it is an OreStack */ - if (shapedOreRecipe.getInput()[i] instanceof ArrayList || shapedOreRecipe.getInput()[i] instanceof ItemStack) { + if (shapedOreRecipe.getInput()[i] instanceof ArrayList) { recipeInputs.add(new CustomWrappedStack(shapedOreRecipe.getInput()[i])); } + else if (shapedOreRecipe.getInput()[i] instanceof ItemStack) { + + ItemStack itemStack = ((ItemStack) shapedOreRecipe.getInput()[i]).copy(); + + if (itemStack.stackSize > 1) { + itemStack.stackSize = 1; + } + + recipeInputs.add(new CustomWrappedStack(itemStack)); + } } } else if (recipe instanceof ShapelessOreRecipe) { @@ -127,9 +153,20 @@ public class RecipeHelper { ShapelessOreRecipe shapelessOreRecipe = (ShapelessOreRecipe) recipe; for (Object object : shapelessOreRecipe.getInput()) { - if (object instanceof ArrayList || object instanceof ItemStack) { + + if (object instanceof ArrayList) { recipeInputs.add(new CustomWrappedStack(object)); } + else if (object instanceof ItemStack) { + + ItemStack itemStack = ((ItemStack) object).copy(); + + if (itemStack.stackSize > 1) { + itemStack.stackSize = 1; + } + + recipeInputs.add(new CustomWrappedStack(itemStack)); + } } } diff --git a/ee3_common/com/pahimar/ee3/emc/DynEMC.java b/ee3_common/com/pahimar/ee3/emc/DynEMC.java index feed6e3a..3354780d 100644 --- a/ee3_common/com/pahimar/ee3/emc/DynEMC.java +++ b/ee3_common/com/pahimar/ee3/emc/DynEMC.java @@ -8,7 +8,6 @@ import java.util.Set; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.CraftingManager; import net.minecraft.item.crafting.IRecipe; import net.minecraftforge.oredict.OreDictionary; @@ -29,12 +28,15 @@ public class DynEMC { private static DynEMC dynEMC = null; - private ArrayList discoveredItems; + private ArrayList discoveredStacks; + private ArrayList stacksWithoutRecipes; + private WeightedDirectedGraph graph; private DynEMC() { - discoveredItems = new ArrayList(); + discoveredStacks = new ArrayList(); + stacksWithoutRecipes = new ArrayList(); graph = new WeightedDirectedGraph(); init(); @@ -54,9 +56,6 @@ public class DynEMC { RecipeRegistry recipeManager = RecipeRegistry.getInstance(); Multimap> recipes = HashMultimap.create(); - Set recipeKeySet = null; - Iterator recipeKeySetIterator = null; - CustomWrappedStack recipeOutput = null; // Add potion recipes recipes.putAll(RecipesPotions.getPotionRecipes()); @@ -70,128 +69,89 @@ public class DynEMC { // Add recipes gathered via IMC // TODO Gather IMC recipes - // Add items that have no recipe + // Populate the discovered stacks list with all stacks that we are involved in a recipe we are aware of + discoverStacks(recipes); + + // Add items that have no recipe, using the list of discovered stacks to determine if it's in a recipe or not + for (CustomWrappedStack stack : stacksWithoutRecipes) { + recipes.put(stack, new ArrayList()); + } // Iterate through every recipe in the map, and add them to the registry - recipeKeySet = recipes.keySet(); - recipeKeySetIterator = recipeKeySet.iterator(); - recipeOutput = null; + Set recipeKeySet = recipes.keySet(); + Iterator recipeKeySetIterator = recipeKeySet.iterator(); + CustomWrappedStack recipeOutput = null; while (recipeKeySetIterator.hasNext()) { recipeOutput = recipeKeySetIterator.next(); - + for (List recipeInputs : recipes.get(recipeOutput)) { recipeManager.addRecipe(recipeOutput, recipeInputs); } } - - LogHelper.debug(recipeManager.toString()); } - @SuppressWarnings("unused") - private void populateItemList() { - - ArrayList subItems = new ArrayList(); - - /* - * Add all entries from the OreDictionary - */ - for (String oreName : OreDictionary.getOreNames()) { - - CustomWrappedStack customWrappedStack = new CustomWrappedStack(new OreStack(oreName)); - - if (!discoveredItems.contains(customWrappedStack)) { - discoveredItems.add(customWrappedStack); + private void discoverStacks(Multimap> recipes) { + + Set recipeKeySet = recipes.keySet(); + Iterator recipeKeySetIterator = recipeKeySet.iterator(); + CustomWrappedStack recipeOutput = null; + + while (recipeKeySetIterator.hasNext()) { + recipeOutput = recipeKeySetIterator.next(); + + if (!discoveredStacks.contains(new CustomWrappedStack(recipeOutput.getWrappedStack()))) { + discoveredStacks.add(new CustomWrappedStack(recipeOutput.getWrappedStack())); } - } - - for (Object recipe : CraftingManager.getInstance().getRecipeList()) { - if (recipe instanceof IRecipe) { - ItemStack craftingResult = ((IRecipe) recipe).getRecipeOutput(); - - if (craftingResult != null) { - if (craftingResult.getItemDamage() == OreDictionary.WILDCARD_VALUE) { - CustomWrappedStack wrappedCraftingResult = new CustomWrappedStack(craftingResult); - - if (!discoveredItems.contains(wrappedCraftingResult)) { - discoveredItems.add(wrappedCraftingResult); - } - } - - for (CustomWrappedStack wrappedRecipeInput : RecipeHelper.getCollatedRecipeInputs((IRecipe) recipe)) { - if (wrappedRecipeInput.getWrappedStack() instanceof ItemStack) { - ItemStack wrappedItemStack = (ItemStack) wrappedRecipeInput.getWrappedStack(); - if (wrappedItemStack.getItemDamage() == OreDictionary.WILDCARD_VALUE) { - - wrappedRecipeInput.setStackSize(1); - - if (!discoveredItems.contains(wrappedRecipeInput)) { - discoveredItems.add(wrappedRecipeInput); - } - } - } + + for (List recipeInputs : recipes.get(recipeOutput)) { + for (CustomWrappedStack recipeInput : recipeInputs) { + + if (!discoveredStacks.contains(new CustomWrappedStack(recipeInput.getWrappedStack()))) { + discoveredStacks.add(new CustomWrappedStack(recipeInput.getWrappedStack())); } } } } - /* - * For every possible item (and sub item), add them to the discovered - * items list - */ + ArrayList subItemList = new ArrayList(); + for (int i = 0; i < Item.itemsList.length; i++) { if (Item.itemsList[i] != null) { if (Item.itemsList[i].getHasSubtypes()) { - subItems.clear(); - Item.itemsList[i].getSubItems(i, Item.itemsList[i].getCreativeTab(), subItems); + subItemList.clear(); + Item.itemsList[i].getSubItems(i, Item.itemsList[i].getCreativeTab(), subItemList); - for (ItemStack itemStack : subItems) { + for (ItemStack itemStack : subItemList) { if (itemStack != null) { CustomWrappedStack customWrappedStack = new CustomWrappedStack(itemStack); - if (!discoveredItems.contains(customWrappedStack)) { - discoveredItems.add(customWrappedStack); + if (!discoveredStacks.contains(customWrappedStack)) { + discoveredStacks.add(customWrappedStack); + stacksWithoutRecipes.add(customWrappedStack); } } } } else { - - ItemStack itemStack = new ItemStack(Item.itemsList[i]); - - CustomWrappedStack customWrappedStack = new CustomWrappedStack(itemStack); - if (!discoveredItems.contains(customWrappedStack)) { - discoveredItems.add(customWrappedStack); + + CustomWrappedStack customWrappedStack = new CustomWrappedStack(new ItemStack(Item.itemsList[i])); + + if (!discoveredStacks.contains(customWrappedStack)) { + discoveredStacks.add(customWrappedStack); + stacksWithoutRecipes.add(customWrappedStack); } } } } - - /** - * Now that we have discovered as many items as possible, trim out the - * items that are black listed - */ - for (CustomWrappedStack customWrappedStack : EmcBlackList.getInstance().getBlackListStacks()) { - - while (discoveredItems.contains(customWrappedStack)) { - discoveredItems.remove(customWrappedStack); - } - } - - for (CustomWrappedStack customWrappedStack : discoveredItems) { - - if (!graph.nodeExists(customWrappedStack)) { - graph.addNode(customWrappedStack); - } - } } @SuppressWarnings("unused") private void populateGraph() { - for (CustomWrappedStack customWrappedStack : discoveredItems) { + for (CustomWrappedStack customWrappedStack : discoveredStacks) { ArrayList recipes = RecipeHelper.getReverseRecipes(customWrappedStack);