Just some bleary eyed, crack of dawn, coding

This commit is contained in:
pahimar 2013-07-22 06:48:31 -04:00
parent 79adec9ed5
commit 2c35d3adca
6 changed files with 60 additions and 35 deletions

View file

@ -125,11 +125,16 @@ public class RecipeHelper {
ShapedOreRecipe shapedOreRecipe = (ShapedOreRecipe) recipe; ShapedOreRecipe shapedOreRecipe = (ShapedOreRecipe) recipe;
for (int i = 0; i < shapedOreRecipe.getInput().length; i++) { for (int i = 0; i < shapedOreRecipe.getInput().length; i++) {
/* /*
* If the element is a list, then it is an OreStack * If the element is a list, then it is an OreStack
*/ */
if (shapedOreRecipe.getInput()[i] instanceof ArrayList) { 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) { else if (shapedOreRecipe.getInput()[i] instanceof ItemStack) {

View file

@ -57,21 +57,34 @@ public class DynEMC {
recipeOutput = recipeKeySetIterator.next(); recipeOutput = recipeKeySetIterator.next();
for (List<CustomWrappedStack> recipeInputs : recipeMappings.get(recipeOutput)) { for (List<CustomWrappedStack> recipeInputs : recipeMappings.get(recipeOutput)) {
for (CustomWrappedStack recipeInput : recipeInputs) {
CustomWrappedStack unWrappedRecipeOutput = new CustomWrappedStack(recipeOutput.getWrappedStack());
// Unwrapped the wrapped stacks so that we actually find them in the graph
CustomWrappedStack unWrappedRecipeOutput = new CustomWrappedStack(recipeOutput.getWrappedStack()); if (graph.nodeExists(unWrappedRecipeOutput)) {
CustomWrappedStack unWrappedRecipeInput = new CustomWrappedStack(recipeInput.getWrappedStack()); for (CustomWrappedStack recipeInput : recipeInputs) {
if (recipeOutput.getStackSize() != 0) { // Unwrapped the wrapped stacks so that we actually find them in the graph
try { CustomWrappedStack unWrappedRecipeInput = new CustomWrappedStack(recipeInput.getWrappedStack());
graph.addEdge(unWrappedRecipeOutput, unWrappedRecipeInput, (recipeInput.getStackSize() * 1.0f) / recipeOutput.getStackSize());
} catch (NoSuchElementException e) { if (graph.nodeExists(unWrappedRecipeInput)) {
LogHelper.severe(e.getLocalizedMessage()); 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");
}
} }
} }
} }

View file

@ -49,8 +49,10 @@ public class WeightedDirectedGraph<T> implements Iterable<T> {
if (!(graph.containsKey(from) && graph.containsKey(to))) { if (!(graph.containsKey(from) && graph.containsKey(to))) {
if (!graph.containsKey(from)) { if (!graph.containsKey(from)) {
LogHelper.severe("From node doesn't exist: " + from.toString()); LogHelper.severe("From node doesn't exist: " + from.toString());
LogHelper.severe("To node: " + to.toString());
} }
if (!graph.containsKey(to)) { if (!graph.containsKey(to)) {
LogHelper.severe("From node: " + from.toString());
LogHelper.severe("To node doesn't exist: " + to.toString()); LogHelper.severe("To node doesn't exist: " + to.toString());
} }
throw new NoSuchElementException("Missing nodes from graph"); throw new NoSuchElementException("Missing nodes from graph");

View file

@ -226,6 +226,9 @@ public class CustomWrappedStack {
else if (energyStack != null) { else if (energyStack != null) {
stringBuilder.append(String.format("%dxenergyStack.%s", stackSize, energyStack.energyName)); stringBuilder.append(String.format("%dxenergyStack.%s", stackSize, energyStack.energyName));
} }
else {
stringBuilder.append("null");
}
return stringBuilder.toString(); return stringBuilder.toString();
} }
@ -264,7 +267,11 @@ public class CustomWrappedStack {
hashCode = 37 * hashCode + itemStack.getItemDamage(); 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) { else if (oreStack != null) {
hashCode = 37 * hashCode + oreStack.oreName.hashCode(); hashCode = 37 * hashCode + oreStack.oreName.hashCode();

View file

@ -92,7 +92,7 @@ public class RecipeRegistry {
while (recipeKeySetIterator.hasNext()) { while (recipeKeySetIterator.hasNext()) {
recipeOutput = recipeKeySetIterator.next(); 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())); discoveredStacks.add(new CustomWrappedStack(recipeOutput.getWrappedStack()));
} }
@ -101,37 +101,34 @@ public class RecipeRegistry {
CustomWrappedStack unwrappedRecipeInput = new CustomWrappedStack(recipeInput.getWrappedStack()); CustomWrappedStack unwrappedRecipeInput = new CustomWrappedStack(recipeInput.getWrappedStack());
if (!discoveredStacks.contains(unwrappedRecipeInput)) { if (!discoveredStacks.contains(unwrappedRecipeInput) && recipeInput.getWrappedStack() != null) {
discoveredStacks.add(unwrappedRecipeInput); discoveredStacks.add(unwrappedRecipeInput);
} }
} }
} }
} }
// Discover all stacks from the vanilla Items array CustomWrappedStack customWrappedStack;
ArrayList<ItemStack> subItemList = new ArrayList<ItemStack>();
// Discover all stacks from the vanilla Items array
for (int i = 0; i < Item.itemsList.length; i++) { for (int i = 0; i < Item.itemsList.length; i++) {
if (Item.itemsList[i] != null) { if (Item.itemsList[i] != null) {
if (Item.itemsList[i].getHasSubtypes()) { if (Item.itemsList[i].getHasSubtypes()) {
subItemList.clear(); for (int meta = 0; meta < 16; meta++) {
Item.itemsList[i].getSubItems(i, Item.itemsList[i].getCreativeTab(), subItemList);
customWrappedStack = new CustomWrappedStack(new ItemStack(Item.itemsList[i].itemID, 1, meta));
for (ItemStack itemStack : subItemList) {
if (itemStack != null) { if (!discoveredStacks.contains(customWrappedStack)) {
discoveredStacks.add(customWrappedStack);
CustomWrappedStack customWrappedStack = new CustomWrappedStack(itemStack);
if (!discoveredStacks.contains(customWrappedStack)) {
discoveredStacks.add(customWrappedStack);
}
} }
} }
} }
else { else {
CustomWrappedStack customWrappedStack = new CustomWrappedStack(new ItemStack(Item.itemsList[i])); customWrappedStack = new CustomWrappedStack(new ItemStack(Item.itemsList[i]));
if (!discoveredStacks.contains(customWrappedStack)) { if (!discoveredStacks.contains(customWrappedStack)) {
discoveredStacks.add(customWrappedStack); discoveredStacks.add(customWrappedStack);

View file

@ -39,6 +39,7 @@ public class RecipesVanilla {
ItemStack recipeOutput = recipe.getRecipeOutput(); ItemStack recipeOutput = recipe.getRecipeOutput();
if (recipeOutput != null) { if (recipeOutput != null) {
ArrayList<CustomWrappedStack> recipeInputs = RecipeHelper.getRecipeInputs(recipe); ArrayList<CustomWrappedStack> recipeInputs = RecipeHelper.getRecipeInputs(recipe);
vanillaRecipes.put(new CustomWrappedStack(recipeOutput), recipeInputs); vanillaRecipes.put(new CustomWrappedStack(recipeOutput), recipeInputs);
} }