Still a small bug (not the error), but yeah, getting there
This commit is contained in:
parent
16b632acfb
commit
0c35d8cf24
|
@ -9,9 +9,9 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import com.pahimar.ee3.item.CustomStackWrapper;
|
||||
import com.pahimar.ee3.item.ModItems;
|
||||
import com.pahimar.ee3.lib.Colours;
|
||||
import com.pahimar.ee3.lib.ItemIds;
|
||||
import com.pahimar.ee3.lib.Strings;
|
||||
|
||||
/**
|
||||
|
@ -61,7 +61,7 @@ public class ItemUtil {
|
|||
// Check the meta data
|
||||
|
||||
if ((first.getItemDamage() == OreDictionary.WILDCARD_VALUE) || (second.getItemDamage() == OreDictionary.WILDCARD_VALUE)) {
|
||||
return true;
|
||||
//return true;
|
||||
}
|
||||
|
||||
if (first.getItemDamage() == second.getItemDamage()) {
|
||||
|
@ -88,16 +88,11 @@ public class ItemUtil {
|
|||
}
|
||||
}
|
||||
|
||||
if (first.itemID == ItemIds.MINIUM_STONE && second.itemID == ItemIds.MINIUM_STONE) {
|
||||
System.out.println("First: " + ItemUtil.toString(first));
|
||||
System.out.println("Second: " + ItemUtil.toString(second));
|
||||
System.out.println("False Default");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public static ArrayList collateStacks(List unCollatedStacks) {
|
||||
public static ArrayList<CustomStackWrapper> collateStacks(List<CustomStackWrapper> unCollatedStacks) {
|
||||
|
||||
ArrayList collatedStacks = new ArrayList();
|
||||
|
||||
|
|
|
@ -17,10 +17,15 @@ public class OreStack implements Comparator<OreStack> {
|
|||
oreName = null;
|
||||
}
|
||||
|
||||
public OreStack(String oreName) {
|
||||
public OreStack(String oreName, int stackSize) {
|
||||
|
||||
this.oreName = oreName;
|
||||
stackSize = 1;
|
||||
this.stackSize = stackSize;
|
||||
}
|
||||
|
||||
public OreStack(String oreName) {
|
||||
|
||||
this(oreName, 1);
|
||||
}
|
||||
|
||||
public OreStack(int oreID) {
|
||||
|
@ -28,9 +33,14 @@ public class OreStack implements Comparator<OreStack> {
|
|||
this(OreDictionary.getOreName(oreID));
|
||||
}
|
||||
|
||||
public OreStack(int oreID, int stackSize) {
|
||||
|
||||
this(OreDictionary.getOreName(oreID), stackSize);
|
||||
}
|
||||
|
||||
public OreStack(ItemStack itemStack) {
|
||||
|
||||
this(OreDictionary.getOreID(itemStack));
|
||||
this(OreDictionary.getOreID(itemStack), itemStack.stackSize);
|
||||
}
|
||||
|
||||
public ArrayList<ItemStack> getOres() {
|
||||
|
|
|
@ -36,7 +36,7 @@ public class RecipeHelper {
|
|||
* @return List of elements that constitute the input of the given IRecipe.
|
||||
* Could be an ItemStack or an Arraylist
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
public static ArrayList<CustomStackWrapper> getRecipeInputs(IRecipe recipe) {
|
||||
|
||||
ArrayList<CustomStackWrapper> recipeInputs = new ArrayList<CustomStackWrapper>();
|
||||
|
@ -54,8 +54,6 @@ public class RecipeHelper {
|
|||
recipeInputs.add(new CustomStackWrapper(itemStack));
|
||||
}
|
||||
}
|
||||
|
||||
return ItemUtil.collateStacks(recipeInputs);
|
||||
}
|
||||
else if (recipe instanceof ShapelessRecipes) {
|
||||
|
||||
|
|
|
@ -1,14 +1,23 @@
|
|||
package com.pahimar.ee3.emc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
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;
|
||||
|
||||
import com.pahimar.ee3.core.util.LogHelper;
|
||||
import com.pahimar.ee3.core.util.OreStack;
|
||||
import com.pahimar.ee3.core.util.RecipeHelper;
|
||||
import com.pahimar.ee3.emc.graph.WeightedDirectedGraph;
|
||||
import com.pahimar.ee3.emc.graph.WeightedEdge;
|
||||
import com.pahimar.ee3.item.CustomStackWrapper;
|
||||
|
||||
public class DynEMC {
|
||||
|
@ -19,10 +28,10 @@ public class DynEMC {
|
|||
private WeightedDirectedGraph<CustomStackWrapper> graph;
|
||||
|
||||
private DynEMC() {
|
||||
|
||||
|
||||
discoveredItems = new ArrayList<CustomStackWrapper>();
|
||||
graph = new WeightedDirectedGraph<CustomStackWrapper>();
|
||||
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
|
@ -39,27 +48,53 @@ public class DynEMC {
|
|||
|
||||
return discoveredItems;
|
||||
}
|
||||
|
||||
|
||||
private void init() {
|
||||
|
||||
populateItemList();
|
||||
}
|
||||
|
||||
|
||||
private void populateItemList() {
|
||||
ArrayList<ItemStack> subItems = new ArrayList<ItemStack>();
|
||||
|
||||
/*
|
||||
* Add all entries from the OreDictionary
|
||||
*/
|
||||
for (String oreName: OreDictionary.getOreNames()) {
|
||||
for (String oreName : OreDictionary.getOreNames()) {
|
||||
|
||||
CustomStackWrapper customWrappedStack = new CustomStackWrapper(new OreStack(oreName));
|
||||
|
||||
|
||||
if (!discoveredItems.contains(customWrappedStack)) {
|
||||
discoveredItems.add(customWrappedStack);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (Object recipe : CraftingManager.getInstance().getRecipeList()) {
|
||||
if (recipe instanceof IRecipe) {
|
||||
ItemStack craftingResult = ((IRecipe) recipe).getRecipeOutput();
|
||||
|
||||
if (craftingResult != null) {
|
||||
if (craftingResult.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
|
||||
CustomStackWrapper wrappedCraftingResult = new CustomStackWrapper(craftingResult);
|
||||
|
||||
if (!discoveredItems.contains(wrappedCraftingResult)) {
|
||||
discoveredItems.add(wrappedCraftingResult);
|
||||
}
|
||||
}
|
||||
|
||||
for (CustomStackWrapper wrappedRecipeInput : RecipeHelper.getCollatedRecipeInputs((IRecipe) recipe)) {
|
||||
if ((wrappedRecipeInput.getItemStack() != null) && (wrappedRecipeInput.getItemStack().getItemDamage() == OreDictionary.WILDCARD_VALUE)) {
|
||||
|
||||
wrappedRecipeInput.setWrappedStackSize(1);
|
||||
if (!discoveredItems.contains(wrappedRecipeInput)) {
|
||||
discoveredItems.add(wrappedRecipeInput);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* For every possible item (and sub item), add them to the discovered
|
||||
* items list
|
||||
|
@ -75,6 +110,7 @@ public class DynEMC {
|
|||
if (itemStack != null) {
|
||||
|
||||
CustomStackWrapper customStackWrapper = new CustomStackWrapper(itemStack);
|
||||
|
||||
if (!discoveredItems.contains(customStackWrapper)) {
|
||||
discoveredItems.add(customStackWrapper);
|
||||
}
|
||||
|
@ -92,7 +128,7 @@ public class DynEMC {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Now that we have discovered as many items as possible, trim out the
|
||||
* items that are black listed
|
||||
|
@ -103,13 +139,89 @@ public class DynEMC {
|
|||
discoveredItems.remove(customStackWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
for (CustomStackWrapper customWrappedStack : discoveredItems) {
|
||||
|
||||
if (!graph.nodeExists(customWrappedStack)) {
|
||||
graph.addNode(customWrappedStack);
|
||||
}
|
||||
}
|
||||
|
||||
for (CustomStackWrapper customWrappedStack : discoveredItems) {
|
||||
|
||||
ArrayList<IRecipe> recipes = RecipeHelper.getReverseRecipes(customWrappedStack);
|
||||
|
||||
for (IRecipe recipe : recipes) {
|
||||
|
||||
ArrayList<CustomStackWrapper> recipeInputs = RecipeHelper.getCollatedRecipeInputs(recipe);
|
||||
|
||||
System.out.println(recipeInputs);
|
||||
|
||||
for (CustomStackWrapper wrappedRecipeInput : recipeInputs) {
|
||||
|
||||
if (wrappedRecipeInput.getItemStack() != null) {
|
||||
ItemStack itemStack = wrappedRecipeInput.getItemStack();
|
||||
|
||||
if (OreDictionary.getOreID(itemStack) != -1) {
|
||||
wrappedRecipeInput = new CustomStackWrapper(new OreStack(itemStack));
|
||||
}
|
||||
}
|
||||
|
||||
float weight = wrappedRecipeInput.getWrappedStackSize();
|
||||
wrappedRecipeInput.setWrappedStackSize(1);
|
||||
|
||||
try {
|
||||
graph.addEdge(customWrappedStack, wrappedRecipeInput, weight);
|
||||
}
|
||||
catch (NoSuchElementException e) {
|
||||
LogHelper.log(Level.SEVERE, e.getMessage() + " from: [" + customWrappedStack + "], to: [" + wrappedRecipeInput + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
LogHelper.log(Level.INFO, "***** START NODES *****");
|
||||
Iterator<CustomStackWrapper> nodeIter = graph.iterator();
|
||||
while (nodeIter.hasNext()) {
|
||||
CustomStackWrapper node = nodeIter.next();
|
||||
LogHelper.log(Level.INFO, "Node: " + node);
|
||||
}
|
||||
LogHelper.log(Level.INFO, "***** END NODES *****");
|
||||
|
||||
LogHelper.log(Level.INFO, "***** START EDGES FROM *****");
|
||||
nodeIter = graph.iterator();
|
||||
while (nodeIter.hasNext()) {
|
||||
CustomStackWrapper node = nodeIter.next();
|
||||
Set<WeightedEdge<CustomStackWrapper>> edgesFrom = graph.edgesFrom(node);
|
||||
for (WeightedEdge<CustomStackWrapper> edge : edgesFrom) {
|
||||
LogHelper.log(Level.INFO, "Crafting Output: " + node);
|
||||
LogHelper.log(Level.INFO, "Crafting Input: " + edge.getTarget());
|
||||
LogHelper.log(Level.INFO, "Weight: " + edge.getWeight());
|
||||
LogHelper.log(Level.INFO, "");
|
||||
}
|
||||
}
|
||||
LogHelper.log(Level.INFO, "***** END EDGES FROM *****");
|
||||
|
||||
// LogHelper.log(Level.INFO, "***** START EDGES TO *****");
|
||||
// nodeIter = graph.iterator();
|
||||
// while (nodeIter.hasNext()) {
|
||||
// CustomStackWrapper node = nodeIter.next();
|
||||
// Set<WeightedEdge<CustomStackWrapper>> edgesTo = graph.edgesTo(node);
|
||||
// for (WeightedEdge<CustomStackWrapper> edge : edgesTo) {
|
||||
// LogHelper.log(Level.INFO, "From: " + node);
|
||||
// LogHelper.log(Level.INFO, "To: " + edge.getTarget());
|
||||
// LogHelper.log(Level.INFO, "Weight: " + edge.getWeight());
|
||||
// LogHelper.log(Level.INFO, "");
|
||||
// }
|
||||
// }
|
||||
// LogHelper.log(Level.INFO, "***** END EDGES TO *****");
|
||||
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue