Now the fun and painful part - building the relational graph. LOTS of work to do here, expect many things being changed in the near future

This commit is contained in:
pahimar 2013-05-31 15:47:56 -04:00
parent 7877ef2781
commit 16b632acfb
7 changed files with 256 additions and 81 deletions

View file

@ -24,12 +24,12 @@ import com.pahimar.ee3.core.proxy.CommonProxy;
import com.pahimar.ee3.core.util.LogHelper;
import com.pahimar.ee3.core.util.VersionHelper;
import com.pahimar.ee3.creativetab.CreativeTabEE3;
import com.pahimar.ee3.emc.DynEMC;
import com.pahimar.ee3.item.ModItems;
import com.pahimar.ee3.item.crafting.RecipesAlchemicalBagDyes;
import com.pahimar.ee3.lib.Reference;
import com.pahimar.ee3.lib.Strings;
import com.pahimar.ee3.network.PacketHandler;
import com.pahimar.ee3.recipe.RecipesTransmutationStone;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.FingerprintWarning;
@ -151,7 +151,7 @@ public class EquivalentExchange3 {
proxy.initRenderingAndTextures();
// Load the Transmutation Stone recipes
RecipesTransmutationStone.init();
//RecipesTransmutationStone.init();
// Add in the ability to dye Alchemical Bags
CraftingManager.getInstance().getRecipeList().add(new RecipesAlchemicalBagDyes());
@ -167,6 +167,6 @@ public class EquivalentExchange3 {
// Initialize the Addon Handler
AddonHandler.init();
//DynEMC.getInstance().toString();
DynEMC.getInstance().toString();
}
}

View file

@ -11,6 +11,7 @@ import net.minecraftforge.oredict.OreDictionary;
import com.pahimar.ee3.item.ModItems;
import com.pahimar.ee3.lib.Colours;
import com.pahimar.ee3.lib.ItemIds;
import com.pahimar.ee3.lib.Strings;
/**
@ -30,7 +31,13 @@ public class ItemUtil {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(String.format("itemID: %d, metaData: %d, stackSize: %d, itemName: %s, className: %s", itemStack.itemID, itemStack.getItemDamage(), itemStack.stackSize, itemStack.getItemName(), itemStack.getItem().getClass().toString()));
stringBuilder.append(String.format("itemID: %d, metaData: %d, stackSize: %d, ", itemStack.itemID, itemStack.getItemDamage(), itemStack.stackSize));
if (itemStack.hasTagCompound()) {
stringBuilder.append(String.format("nbtTagCompound: %s, ", itemStack.getTagCompound().toString()));
}
stringBuilder.append(String.format("itemName: %s, className: %s ", itemStack.getItemName(), itemStack.getItem().getClass().toString()));
return stringBuilder.toString();
}
@ -81,6 +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;
}

View file

@ -8,7 +8,7 @@ import net.minecraftforge.oredict.OreDictionary;
public class OreStack implements Comparator<OreStack> {
private String oreName;
public String oreName;
public int stackSize;
public OreStack() {
@ -47,6 +47,18 @@ public class OreStack implements Comparator<OreStack> {
return "" + stackSize + "xoreDictionary." + oreName;
}
@Override
public boolean equals(Object object) {
if (!(object instanceof OreStack)) {
return false;
}
OreStack oreStackObject = (OreStack) object;
return ((stackSize == oreStackObject.stackSize) && (oreName.equals(oreStackObject.oreName)));
}
@Override
public int compare(OreStack oreStack1, OreStack oreStack2) {

View file

@ -12,6 +12,9 @@ import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraft.item.crafting.ShapelessRecipes;
import net.minecraftforge.oredict.ShapedOreRecipe;
import net.minecraftforge.oredict.ShapelessOreRecipe;
import com.pahimar.ee3.item.CustomStackWrapper;
import cpw.mods.fml.common.registry.GameRegistry;
/**
@ -30,23 +33,25 @@ public class RecipeHelper {
*
* @param recipe
* The IRecipe being examined
* @return
* List of elements that constitute the input of the given IRecipe. Could be an ItemStack or an Arraylist
* @return List of elements that constitute the input of the given IRecipe.
* Could be an ItemStack or an Arraylist
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public static ArrayList getRecipeInputs(IRecipe recipe) {
public static ArrayList<CustomStackWrapper> getRecipeInputs(IRecipe recipe) {
ArrayList<CustomStackWrapper> recipeInputs = new ArrayList<CustomStackWrapper>();
if (recipe instanceof ShapedRecipes) {
ShapedRecipes shapedRecipe = (ShapedRecipes) recipe;
ArrayList<ItemStack> recipeInputs = new ArrayList<ItemStack>();
for (int i = 0; i < shapedRecipe.recipeItems.length; i++) {
if (shapedRecipe.recipeItems[i] != null) {
ItemStack shapedRecipeStack = shapedRecipe.recipeItems[i];
shapedRecipeStack.stackSize = 1;
recipeInputs.add(shapedRecipeStack);
ItemStack itemStack = shapedRecipe.recipeItems[i];
itemStack.stackSize = 1;
recipeInputs.add(new CustomStackWrapper(itemStack));
}
}
@ -56,62 +61,94 @@ public class RecipeHelper {
ShapelessRecipes shapelessRecipe = (ShapelessRecipes) recipe;
return ItemUtil.collateStacks(new ArrayList<Object>(shapelessRecipe.recipeItems));
for (Object object : shapelessRecipe.recipeItems) {
if (object instanceof ItemStack) {
ItemStack itemStack = (ItemStack) object;
itemStack.stackSize = 1;
recipeInputs.add(new CustomStackWrapper(itemStack));
}
}
}
else if (recipe instanceof ShapedOreRecipe) {
ShapedOreRecipe shapedOreRecipe = (ShapedOreRecipe) recipe;
ArrayList recipeInputs = new ArrayList<Object>();
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) {
ArrayList shapedOreRecipeList = (ArrayList<?>) shapedOreRecipe.getInput()[i];
if (shapedOreRecipeList.size() > 0) {
recipeInputs.add(new OreStack((ItemStack)shapedOreRecipeList.get(0)));
}
}
else {
if (shapedOreRecipe.getInput()[i] != null) {
recipeInputs.add(shapedOreRecipe.getInput()[i]);
}
}
}
if (!shapedOreRecipeList.isEmpty()) {
return ItemUtil.collateStacks(recipeInputs);
OreStack oreStack = new OreStack((ItemStack) shapedOreRecipeList.get(0));
oreStack.stackSize = 1;
recipeInputs.add(new CustomStackWrapper(oreStack));
}
}
/*
* Else it is possibly an ItemStack
*/
else if (shapedOreRecipe.getInput()[i] instanceof ItemStack) {
ItemStack itemStack = (ItemStack) shapedOreRecipe.getInput()[i];
itemStack.stackSize = 1;
recipeInputs.add(new CustomStackWrapper(itemStack));
}
}
}
else if (recipe instanceof ShapelessOreRecipe) {
ShapelessOreRecipe shapelessOreRecipe = (ShapelessOreRecipe) recipe;
ArrayList recipeInputs = new ArrayList<Object>();
for (Object o : shapelessOreRecipe.getInput()) {
if (o instanceof ArrayList) {
ArrayList shapelessOreRecipeList = (ArrayList<?>) o;
for (Object object : shapelessOreRecipe.getInput()) {
if (object instanceof ArrayList) {
ArrayList shapelessOreRecipeList = (ArrayList<?>) object;
if (shapelessOreRecipeList.size() > 0) {
recipeInputs.add(new OreStack((ItemStack) shapelessOreRecipeList.get(0)));
if (!shapelessOreRecipeList.isEmpty()) {
OreStack oreStack = new OreStack((ItemStack) shapelessOreRecipeList.get(0));
oreStack.stackSize = 1;
recipeInputs.add(new CustomStackWrapper(oreStack));
}
}
else {
if (o != null) {
recipeInputs.add(o);
else if (object instanceof ItemStack) {
ItemStack itemStack = (ItemStack) object;
itemStack.stackSize = 1;
recipeInputs.add(new CustomStackWrapper(itemStack));
}
}
}
return ItemUtil.collateStacks(recipeInputs);
return recipeInputs;
}
return null;
@SuppressWarnings("unchecked")
public static ArrayList<CustomStackWrapper> getCollatedRecipeInputs(IRecipe recipe) {
return ItemUtil.collateStacks(getRecipeInputs(recipe));
}
public static ArrayList<IRecipe> getReverseRecipes(CustomStackWrapper customStackWrapper) {
return getReverseRecipes(customStackWrapper.getItemStack());
}
@SuppressWarnings("unchecked")
public static ArrayList<IRecipe> getReverseRecipes(ItemStack itemStack) {
ArrayList<IRecipe> craftingManagerRecipeList = new ArrayList<IRecipe>(CraftingManager.getInstance().getRecipeList());
ArrayList<IRecipe> reverseRecipeList = new ArrayList<IRecipe>();
if (itemStack != null) {
ArrayList<IRecipe> craftingManagerRecipeList = new ArrayList<IRecipe>(CraftingManager.getInstance().getRecipeList());
for (IRecipe recipe : craftingManagerRecipeList) {
if (recipe.getRecipeOutput() != null) {
if (ItemUtil.compare(itemStack, recipe.getRecipeOutput())) {
@ -119,6 +156,7 @@ public class RecipeHelper {
}
}
}
}
return reverseRecipeList;
}

View file

@ -1,15 +1,14 @@
package com.pahimar.ee3.emc;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import com.pahimar.ee3.core.util.OreStack;
import com.pahimar.ee3.emc.graph.WeightedDirectedGraph;
import com.pahimar.ee3.item.CustomStackWrapper;
public class DynEMC {
@ -17,18 +16,14 @@ public class DynEMC {
private static DynEMC dynEMC = null;
private ArrayList<CustomStackWrapper> discoveredItems;
private HashMap<EquivalencyGroup, EmcValue> emcMap;
private WeightedDirectedGraph<CustomStackWrapper> graph;
private DynEMC() {
discoveredItems = new ArrayList<CustomStackWrapper>();
emcMap = new HashMap<EquivalencyGroup, EmcValue>();
graph = new WeightedDirectedGraph<CustomStackWrapper>();
init();
for (String oreName : OreDictionary.getOreNames()) {
emcMap.put(new EquivalencyGroup(OreDictionary.getOres(oreName)), new EmcValue());
}
}
public static DynEMC getInstance() {
@ -47,8 +42,24 @@ public class DynEMC {
private void init() {
populateItemList();
}
private void populateItemList() {
ArrayList<ItemStack> subItems = new ArrayList<ItemStack>();
/*
* Add all entries from the OreDictionary
*/
for (String oreName: OreDictionary.getOreNames()) {
CustomStackWrapper customWrappedStack = new CustomStackWrapper(new OreStack(oreName));
if (!discoveredItems.contains(customWrappedStack)) {
discoveredItems.add(customWrappedStack);
}
}
/*
* For every possible item (and sub item), add them to the discovered
* items list
@ -99,13 +110,6 @@ public class DynEMC {
StringBuilder stringBuilder = new StringBuilder();
Set<EquivalencyGroup> keySet = emcMap.keySet();
Iterator<EquivalencyGroup> iter = keySet.iterator();
while (iter.hasNext()) {
System.out.println(iter.next());
}
return stringBuilder.toString();
}
}

View file

@ -11,6 +11,9 @@ import java.util.NoSuchElementException;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.logging.Level;
import com.pahimar.ee3.core.util.LogHelper;
public class WeightedDirectedGraph<T> implements Iterable<T> {
@ -44,6 +47,12 @@ public class WeightedDirectedGraph<T> implements Iterable<T> {
public void addEdge(T from, T to, float weight) {
if (!(graph.containsKey(from) && graph.containsKey(to))) {
if (!(graph.containsKey(from))) {
LogHelper.log(Level.SEVERE, "From node doesn't exist: " + from.toString());
}
if (!(graph.containsKey(to))) {
LogHelper.log(Level.SEVERE, "To node doesn't exist: " + to.toString());
}
throw new NoSuchElementException("Missing nodes from graph");
}
@ -73,6 +82,14 @@ public class WeightedDirectedGraph<T> implements Iterable<T> {
public boolean edgeExists(T from, T to, float weight) {
if (!(graph.containsKey(from) && graph.containsKey(to))) {
if (!(graph.containsKey(from))) {
LogHelper.log(Level.SEVERE, "From node doesn't exist: " + from.toString());
LogHelper.log(Level.SEVERE, "To node: " + to.toString());
}
if (!(graph.containsKey(to))) {
LogHelper.log(Level.SEVERE, "To node doesn't exist: " + to.toString());
LogHelper.log(Level.SEVERE, "From node: " + from.toString());
}
throw new NoSuchElementException("Missing nodes from graph");
}

View file

@ -1,22 +1,68 @@
package com.pahimar.ee3.item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import com.pahimar.ee3.core.util.ItemUtil;
import com.pahimar.ee3.core.util.OreStack;
public class CustomStackWrapper {
public ItemStack itemStack;
private ItemStack itemStack;
private OreStack oreStack;
public CustomStackWrapper(ItemStack itemStack) {
this.itemStack = itemStack;
this.oreStack = null;
if (this.itemStack != null) {
this.itemStack.stackSize = 1;
}
}
public CustomStackWrapper(OreStack oreStack) {
this.itemStack = null;
this.oreStack = oreStack;
if (this.oreStack != null) {
this.oreStack.stackSize = 1;
}
}
public int getWrappedStackSize() {
if (itemStack != null) {
return itemStack.stackSize;
}
else if (oreStack != null) {
return oreStack.stackSize;
}
return -1;
}
public void setWrappedStackSize(int stackSize) {
if (itemStack != null) {
itemStack.stackSize = stackSize;
}
else if (oreStack != null) {
oreStack.stackSize = stackSize;
}
}
public ItemStack getItemStack() {
return itemStack;
}
public OreStack getOreStack() {
return oreStack;
}
@Override
public boolean equals(Object object) {
@ -24,15 +70,47 @@ public class CustomStackWrapper {
return false;
}
CustomStackWrapper wrappedItemStack = (CustomStackWrapper) object;
CustomStackWrapper customWrappedStack = (CustomStackWrapper) object;
return ItemUtil.compare(this.itemStack, wrappedItemStack.itemStack);
if (itemStack != null) {
if (customWrappedStack.itemStack != null) {
return ItemUtil.compare(this.itemStack, customWrappedStack.itemStack);
}
else if (customWrappedStack.oreStack != null) {
for (ItemStack oreDictItemStack : OreDictionary.getOres(customWrappedStack.oreStack.oreName)) {
if (ItemUtil.compare(itemStack, oreDictItemStack)) {
return true;
}
}
}
}
else if (oreStack != null) {
if (customWrappedStack.itemStack != null) {
for (ItemStack oreDictItemStack : OreDictionary.getOres(oreStack.oreName)) {
if (ItemUtil.compare(customWrappedStack.itemStack, oreDictItemStack)) {
return true;
}
}
}
else if (customWrappedStack.oreStack != null) {
return oreStack.equals(customWrappedStack.oreStack);
}
}
return false;
}
@Override
public String toString() {
return itemStack.toString();
if (itemStack != null) {
return ItemUtil.toString(itemStack);
}
else if (oreStack != null) {
return oreStack.toString();
}
return null;
}
@Override
@ -40,9 +118,23 @@ public class CustomStackWrapper {
int hashCode = 1;
if (itemStack != null) {
hashCode = 37 * hashCode + itemStack.itemID;
if (itemStack.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
hashCode = 37 * hashCode;
}
else {
hashCode = 37 * hashCode + itemStack.getItemDamage();
}
hashCode = 37 * hashCode + itemStack.stackSize;
hashCode = 37 * hashCode + itemStack.getItemName().hashCode();
}
else if (oreStack != null) {
hashCode = 37 * hashCode + oreStack.stackSize;
hashCode = 37 * hashCode + oreStack.oreName.hashCode();
}
return hashCode;
}