From 2c35d3adca0310448e5dc8aee8fb483bfb8656e4 Mon Sep 17 00:00:00 2001 From: pahimar Date: Mon, 22 Jul 2013 06:48:31 -0400 Subject: [PATCH] Just some bleary eyed, crack of dawn, coding --- .../pahimar/ee3/core/util/RecipeHelper.java | 7 ++- ee3_common/com/pahimar/ee3/emc/DynEMC.java | 43 ++++++++++++------- .../ee3/emc/graph/WeightedDirectedGraph.java | 2 + .../pahimar/ee3/item/CustomWrappedStack.java | 9 +++- .../ee3/item/crafting/RecipeRegistry.java | 33 +++++++------- .../ee3/item/crafting/RecipesVanilla.java | 1 + 6 files changed, 60 insertions(+), 35 deletions(-) diff --git a/ee3_common/com/pahimar/ee3/core/util/RecipeHelper.java b/ee3_common/com/pahimar/ee3/core/util/RecipeHelper.java index 0e234c1a..8e616bf9 100644 --- a/ee3_common/com/pahimar/ee3/core/util/RecipeHelper.java +++ b/ee3_common/com/pahimar/ee3/core/util/RecipeHelper.java @@ -125,11 +125,16 @@ public class RecipeHelper { ShapedOreRecipe shapedOreRecipe = (ShapedOreRecipe) recipe; for (int i = 0; i < shapedOreRecipe.getInput().length; i++) { + /* * If the element is a list, then it is an OreStack */ if (shapedOreRecipe.getInput()[i] instanceof ArrayList) { - recipeInputs.add(new CustomWrappedStack(shapedOreRecipe.getInput()[i])); + CustomWrappedStack oreStack = new CustomWrappedStack(shapedOreRecipe.getInput()[i]); + + if (oreStack.getWrappedStack() instanceof OreStack) { + recipeInputs.add(new CustomWrappedStack(shapedOreRecipe.getInput()[i])); + } } else if (shapedOreRecipe.getInput()[i] instanceof ItemStack) { diff --git a/ee3_common/com/pahimar/ee3/emc/DynEMC.java b/ee3_common/com/pahimar/ee3/emc/DynEMC.java index e787c39d..f5891f8d 100644 --- a/ee3_common/com/pahimar/ee3/emc/DynEMC.java +++ b/ee3_common/com/pahimar/ee3/emc/DynEMC.java @@ -57,21 +57,34 @@ public class DynEMC { recipeOutput = recipeKeySetIterator.next(); for (List recipeInputs : recipeMappings.get(recipeOutput)) { - for (CustomWrappedStack recipeInput : recipeInputs) { - - // Unwrapped the wrapped stacks so that we actually find them in the graph - CustomWrappedStack unWrappedRecipeOutput = new CustomWrappedStack(recipeOutput.getWrappedStack()); - CustomWrappedStack unWrappedRecipeInput = new CustomWrappedStack(recipeInput.getWrappedStack()); - - if (recipeOutput.getStackSize() != 0) { - - try { - graph.addEdge(unWrappedRecipeOutput, unWrappedRecipeInput, (recipeInput.getStackSize() * 1.0f) / recipeOutput.getStackSize()); - } catch (NoSuchElementException e) { - LogHelper.severe(e.getLocalizedMessage()); - } - } - } + + CustomWrappedStack unWrappedRecipeOutput = new CustomWrappedStack(recipeOutput.getWrappedStack()); + + if (graph.nodeExists(unWrappedRecipeOutput)) { + for (CustomWrappedStack recipeInput : recipeInputs) { + + // Unwrapped the wrapped stacks so that we actually find them in the graph + + CustomWrappedStack unWrappedRecipeInput = new CustomWrappedStack(recipeInput.getWrappedStack()); + + if (graph.nodeExists(unWrappedRecipeInput)) { + if (recipeOutput.getStackSize() != 0) { + try { + graph.addEdge(unWrappedRecipeOutput, unWrappedRecipeInput, (recipeInput.getStackSize() * 1.0f) / recipeOutput.getStackSize()); + } catch (NoSuchElementException e) { + LogHelper.severe(e.getLocalizedMessage()); + } + } + } + else { + LogHelper.debug("Recipe output '" + unWrappedRecipeOutput.toString() + "' exists in the crafting relationship graph"); + LogHelper.debug("Recipe input '" + unWrappedRecipeInput.toString() + "' does not exist in the crafting relationship graph"); + } + } + } + else { + LogHelper.debug("Recipe output '" + unWrappedRecipeOutput.toString() + "' does not exist in the crafting relationship graph"); + } } } } diff --git a/ee3_common/com/pahimar/ee3/emc/graph/WeightedDirectedGraph.java b/ee3_common/com/pahimar/ee3/emc/graph/WeightedDirectedGraph.java index 1cb586c7..59e39bce 100644 --- a/ee3_common/com/pahimar/ee3/emc/graph/WeightedDirectedGraph.java +++ b/ee3_common/com/pahimar/ee3/emc/graph/WeightedDirectedGraph.java @@ -49,8 +49,10 @@ public class WeightedDirectedGraph implements Iterable { if (!(graph.containsKey(from) && graph.containsKey(to))) { if (!graph.containsKey(from)) { LogHelper.severe("From node doesn't exist: " + from.toString()); + LogHelper.severe("To node: " + to.toString()); } if (!graph.containsKey(to)) { + LogHelper.severe("From node: " + from.toString()); LogHelper.severe("To node doesn't exist: " + to.toString()); } throw new NoSuchElementException("Missing nodes from graph"); diff --git a/ee3_common/com/pahimar/ee3/item/CustomWrappedStack.java b/ee3_common/com/pahimar/ee3/item/CustomWrappedStack.java index 32b72133..60923788 100644 --- a/ee3_common/com/pahimar/ee3/item/CustomWrappedStack.java +++ b/ee3_common/com/pahimar/ee3/item/CustomWrappedStack.java @@ -226,6 +226,9 @@ public class CustomWrappedStack { else if (energyStack != null) { stringBuilder.append(String.format("%dxenergyStack.%s", stackSize, energyStack.energyName)); } + else { + stringBuilder.append("null"); + } return stringBuilder.toString(); } @@ -264,7 +267,11 @@ public class CustomWrappedStack { hashCode = 37 * hashCode + itemStack.getItemDamage(); } - hashCode = 37 * hashCode + itemStack.getItemName().hashCode(); + try { + hashCode = 37 * hashCode + itemStack.getItemName().hashCode(); + } catch (ArrayIndexOutOfBoundsException e) { + + } } else if (oreStack != null) { hashCode = 37 * hashCode + oreStack.oreName.hashCode(); diff --git a/ee3_common/com/pahimar/ee3/item/crafting/RecipeRegistry.java b/ee3_common/com/pahimar/ee3/item/crafting/RecipeRegistry.java index e8c47395..48079f93 100644 --- a/ee3_common/com/pahimar/ee3/item/crafting/RecipeRegistry.java +++ b/ee3_common/com/pahimar/ee3/item/crafting/RecipeRegistry.java @@ -92,7 +92,7 @@ public class RecipeRegistry { while (recipeKeySetIterator.hasNext()) { recipeOutput = recipeKeySetIterator.next(); - if (!discoveredStacks.contains(new CustomWrappedStack(recipeOutput.getWrappedStack()))) { + if (!discoveredStacks.contains(new CustomWrappedStack(recipeOutput.getWrappedStack())) && recipeOutput.getWrappedStack() != null) { discoveredStacks.add(new CustomWrappedStack(recipeOutput.getWrappedStack())); } @@ -101,37 +101,34 @@ public class RecipeRegistry { CustomWrappedStack unwrappedRecipeInput = new CustomWrappedStack(recipeInput.getWrappedStack()); - if (!discoveredStacks.contains(unwrappedRecipeInput)) { + if (!discoveredStacks.contains(unwrappedRecipeInput) && recipeInput.getWrappedStack() != null) { discoveredStacks.add(unwrappedRecipeInput); } } } } - // Discover all stacks from the vanilla Items array - ArrayList subItemList = new ArrayList(); + CustomWrappedStack customWrappedStack; + // Discover all stacks from the vanilla Items array for (int i = 0; i < Item.itemsList.length; i++) { + if (Item.itemsList[i] != null) { + if (Item.itemsList[i].getHasSubtypes()) { - - subItemList.clear(); - Item.itemsList[i].getSubItems(i, Item.itemsList[i].getCreativeTab(), subItemList); - - for (ItemStack itemStack : subItemList) { - if (itemStack != null) { - - CustomWrappedStack customWrappedStack = new CustomWrappedStack(itemStack); - - if (!discoveredStacks.contains(customWrappedStack)) { - discoveredStacks.add(customWrappedStack); - } + + for (int meta = 0; meta < 16; meta++) { + + customWrappedStack = new CustomWrappedStack(new ItemStack(Item.itemsList[i].itemID, 1, meta)); + + if (!discoveredStacks.contains(customWrappedStack)) { + discoveredStacks.add(customWrappedStack); } - } + } } else { - CustomWrappedStack customWrappedStack = new CustomWrappedStack(new ItemStack(Item.itemsList[i])); + customWrappedStack = new CustomWrappedStack(new ItemStack(Item.itemsList[i])); if (!discoveredStacks.contains(customWrappedStack)) { discoveredStacks.add(customWrappedStack); diff --git a/ee3_common/com/pahimar/ee3/item/crafting/RecipesVanilla.java b/ee3_common/com/pahimar/ee3/item/crafting/RecipesVanilla.java index ea9acf32..5b504acb 100644 --- a/ee3_common/com/pahimar/ee3/item/crafting/RecipesVanilla.java +++ b/ee3_common/com/pahimar/ee3/item/crafting/RecipesVanilla.java @@ -39,6 +39,7 @@ public class RecipesVanilla { ItemStack recipeOutput = recipe.getRecipeOutput(); if (recipeOutput != null) { + ArrayList recipeInputs = RecipeHelper.getRecipeInputs(recipe); vanillaRecipes.put(new CustomWrappedStack(recipeOutput), recipeInputs); }