Just some bleary eyed, crack of dawn, coding
This commit is contained in:
parent
79adec9ed5
commit
2c35d3adca
6 changed files with 60 additions and 35 deletions
|
@ -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) {
|
||||
|
||||
|
|
|
@ -57,21 +57,34 @@ public class DynEMC {
|
|||
recipeOutput = recipeKeySetIterator.next();
|
||||
|
||||
for (List<CustomWrappedStack> 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,8 +49,10 @@ public class WeightedDirectedGraph<T> implements Iterable<T> {
|
|||
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");
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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<ItemStack> subItemList = new ArrayList<ItemStack>();
|
||||
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);
|
||||
|
|
|
@ -39,6 +39,7 @@ public class RecipesVanilla {
|
|||
ItemStack recipeOutput = recipe.getRecipeOutput();
|
||||
|
||||
if (recipeOutput != null) {
|
||||
|
||||
ArrayList<CustomWrappedStack> recipeInputs = RecipeHelper.getRecipeInputs(recipe);
|
||||
vanillaRecipes.put(new CustomWrappedStack(recipeOutput), recipeInputs);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue