Fix edge weights not getting assigned properly, still some edge exceptions to handle in the graph construction

This commit is contained in:
pahimar 2013-06-01 21:49:21 -04:00
parent 0c35d8cf24
commit d8e80366e1
6 changed files with 87 additions and 105 deletions

View file

@ -9,7 +9,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary;
import com.pahimar.ee3.item.CustomStackWrapper; import com.pahimar.ee3.item.CustomWrappedStack;
import com.pahimar.ee3.item.ModItems; import com.pahimar.ee3.item.ModItems;
import com.pahimar.ee3.lib.Colours; import com.pahimar.ee3.lib.Colours;
import com.pahimar.ee3.lib.Strings; import com.pahimar.ee3.lib.Strings;
@ -91,10 +91,9 @@ public class ItemUtil {
return false; return false;
} }
@SuppressWarnings({ "rawtypes", "unchecked" }) public static ArrayList<CustomWrappedStack> collateStacks(List<CustomWrappedStack> unCollatedStacks) {
public static ArrayList<CustomStackWrapper> collateStacks(List<CustomStackWrapper> unCollatedStacks) {
ArrayList collatedStacks = new ArrayList(); ArrayList<CustomWrappedStack> collatedStacks = new ArrayList<CustomWrappedStack>();
for (int i = 0; i < unCollatedStacks.size(); i++) { for (int i = 0; i < unCollatedStacks.size(); i++) {
@ -105,21 +104,15 @@ public class ItemUtil {
boolean found = false; boolean found = false;
for (int j = 0; j < collatedStacks.size(); j++) { for (int j = 0; j < collatedStacks.size(); j++) {
if ((unCollatedStacks.get(i) instanceof ItemStack) && (collatedStacks.get(j) instanceof ItemStack)) { if (unCollatedStacks.get(i).getItemStack() != null && collatedStacks.get(j).getItemStack() != null) {
ItemStack unCollatedStack = (ItemStack) unCollatedStacks.get(i); if (compare(unCollatedStacks.get(i).getItemStack(), collatedStacks.get(j).getItemStack())) {
ItemStack collatedStack = (ItemStack) collatedStacks.get(j); collatedStacks.get(j).setStackSize(collatedStacks.get(j).getStackSize() + 1);
if (compare(unCollatedStack, collatedStack)) {
((ItemStack) collatedStacks.get(j)).stackSize += 1;
found = true; found = true;
} }
} }
else if ((unCollatedStacks.get(i) instanceof OreStack) && (collatedStacks.get(j) instanceof OreStack)) { else if (unCollatedStacks.get(i).getOreStack() != null && collatedStacks.get(j).getOreStack() != null) {
OreStack unCollatedStack = (OreStack) unCollatedStacks.get(i); if (OreStack.compareStacks(unCollatedStacks.get(i).getOreStack(), collatedStacks.get(j).getOreStack())) {
OreStack collatedStack = (OreStack) collatedStacks.get(j); collatedStacks.get(j).setStackSize(collatedStacks.get(j).getStackSize() + 1);
if (OreStack.compareStacks(unCollatedStack, collatedStack)) {
((OreStack) collatedStacks.get(j)).stackSize += 1;
found = true; found = true;
} }
} }

View file

@ -13,7 +13,7 @@ import net.minecraft.item.crafting.ShapelessRecipes;
import net.minecraftforge.oredict.ShapedOreRecipe; import net.minecraftforge.oredict.ShapedOreRecipe;
import net.minecraftforge.oredict.ShapelessOreRecipe; import net.minecraftforge.oredict.ShapelessOreRecipe;
import com.pahimar.ee3.item.CustomStackWrapper; import com.pahimar.ee3.item.CustomWrappedStack;
import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.GameRegistry;
@ -37,9 +37,9 @@ public class RecipeHelper {
* Could be an ItemStack or an Arraylist * Could be an ItemStack or an Arraylist
*/ */
@SuppressWarnings({ "rawtypes" }) @SuppressWarnings({ "rawtypes" })
public static ArrayList<CustomStackWrapper> getRecipeInputs(IRecipe recipe) { public static ArrayList<CustomWrappedStack> getRecipeInputs(IRecipe recipe) {
ArrayList<CustomStackWrapper> recipeInputs = new ArrayList<CustomStackWrapper>(); ArrayList<CustomWrappedStack> recipeInputs = new ArrayList<CustomWrappedStack>();
if (recipe instanceof ShapedRecipes) { if (recipe instanceof ShapedRecipes) {
@ -51,7 +51,7 @@ public class RecipeHelper {
ItemStack itemStack = shapedRecipe.recipeItems[i]; ItemStack itemStack = shapedRecipe.recipeItems[i];
itemStack.stackSize = 1; itemStack.stackSize = 1;
recipeInputs.add(new CustomStackWrapper(itemStack)); recipeInputs.add(new CustomWrappedStack(itemStack));
} }
} }
} }
@ -65,7 +65,7 @@ public class RecipeHelper {
ItemStack itemStack = (ItemStack) object; ItemStack itemStack = (ItemStack) object;
itemStack.stackSize = 1; itemStack.stackSize = 1;
recipeInputs.add(new CustomStackWrapper(itemStack)); recipeInputs.add(new CustomWrappedStack(itemStack));
} }
} }
} }
@ -85,7 +85,7 @@ public class RecipeHelper {
OreStack oreStack = new OreStack((ItemStack) shapedOreRecipeList.get(0)); OreStack oreStack = new OreStack((ItemStack) shapedOreRecipeList.get(0));
oreStack.stackSize = 1; oreStack.stackSize = 1;
recipeInputs.add(new CustomStackWrapper(oreStack)); recipeInputs.add(new CustomWrappedStack(oreStack));
} }
} }
/* /*
@ -96,7 +96,7 @@ public class RecipeHelper {
ItemStack itemStack = (ItemStack) shapedOreRecipe.getInput()[i]; ItemStack itemStack = (ItemStack) shapedOreRecipe.getInput()[i];
itemStack.stackSize = 1; itemStack.stackSize = 1;
recipeInputs.add(new CustomStackWrapper(itemStack)); recipeInputs.add(new CustomWrappedStack(itemStack));
} }
} }
} }
@ -113,14 +113,14 @@ public class RecipeHelper {
OreStack oreStack = new OreStack((ItemStack) shapelessOreRecipeList.get(0)); OreStack oreStack = new OreStack((ItemStack) shapelessOreRecipeList.get(0));
oreStack.stackSize = 1; oreStack.stackSize = 1;
recipeInputs.add(new CustomStackWrapper(oreStack)); recipeInputs.add(new CustomWrappedStack(oreStack));
} }
} }
else if (object instanceof ItemStack) { else if (object instanceof ItemStack) {
ItemStack itemStack = (ItemStack) object; ItemStack itemStack = (ItemStack) object;
itemStack.stackSize = 1; itemStack.stackSize = 1;
recipeInputs.add(new CustomStackWrapper(itemStack)); recipeInputs.add(new CustomWrappedStack(itemStack));
} }
} }
} }
@ -128,13 +128,12 @@ public class RecipeHelper {
return recipeInputs; return recipeInputs;
} }
@SuppressWarnings("unchecked") public static ArrayList<CustomWrappedStack> getCollatedRecipeInputs(IRecipe recipe) {
public static ArrayList<CustomStackWrapper> getCollatedRecipeInputs(IRecipe recipe) {
return ItemUtil.collateStacks(getRecipeInputs(recipe)); return ItemUtil.collateStacks(getRecipeInputs(recipe));
} }
public static ArrayList<IRecipe> getReverseRecipes(CustomStackWrapper customStackWrapper) { public static ArrayList<IRecipe> getReverseRecipes(CustomWrappedStack customStackWrapper) {
return getReverseRecipes(customStackWrapper.getItemStack()); return getReverseRecipes(customStackWrapper.getItemStack());
} }

View file

@ -18,19 +18,19 @@ import com.pahimar.ee3.core.util.OreStack;
import com.pahimar.ee3.core.util.RecipeHelper; import com.pahimar.ee3.core.util.RecipeHelper;
import com.pahimar.ee3.emc.graph.WeightedDirectedGraph; import com.pahimar.ee3.emc.graph.WeightedDirectedGraph;
import com.pahimar.ee3.emc.graph.WeightedEdge; import com.pahimar.ee3.emc.graph.WeightedEdge;
import com.pahimar.ee3.item.CustomStackWrapper; import com.pahimar.ee3.item.CustomWrappedStack;
public class DynEMC { public class DynEMC {
private static DynEMC dynEMC = null; private static DynEMC dynEMC = null;
private ArrayList<CustomStackWrapper> discoveredItems; private ArrayList<CustomWrappedStack> discoveredItems;
private WeightedDirectedGraph<CustomStackWrapper> graph; private WeightedDirectedGraph<CustomWrappedStack> graph;
private DynEMC() { private DynEMC() {
discoveredItems = new ArrayList<CustomStackWrapper>(); discoveredItems = new ArrayList<CustomWrappedStack>();
graph = new WeightedDirectedGraph<CustomStackWrapper>(); graph = new WeightedDirectedGraph<CustomWrappedStack>();
init(); init();
} }
@ -44,7 +44,7 @@ public class DynEMC {
return dynEMC; return dynEMC;
} }
public List<CustomStackWrapper> getDiscoveredItems() { public List<CustomWrappedStack> getDiscoveredItems() {
return discoveredItems; return discoveredItems;
} }
@ -62,7 +62,7 @@ public class DynEMC {
*/ */
for (String oreName : OreDictionary.getOreNames()) { for (String oreName : OreDictionary.getOreNames()) {
CustomStackWrapper customWrappedStack = new CustomStackWrapper(new OreStack(oreName)); CustomWrappedStack customWrappedStack = new CustomWrappedStack(new OreStack(oreName));
if (!discoveredItems.contains(customWrappedStack)) { if (!discoveredItems.contains(customWrappedStack)) {
discoveredItems.add(customWrappedStack); discoveredItems.add(customWrappedStack);
@ -75,17 +75,17 @@ public class DynEMC {
if (craftingResult != null) { if (craftingResult != null) {
if (craftingResult.getItemDamage() == OreDictionary.WILDCARD_VALUE) { if (craftingResult.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
CustomStackWrapper wrappedCraftingResult = new CustomStackWrapper(craftingResult); CustomWrappedStack wrappedCraftingResult = new CustomWrappedStack(craftingResult);
if (!discoveredItems.contains(wrappedCraftingResult)) { if (!discoveredItems.contains(wrappedCraftingResult)) {
discoveredItems.add(wrappedCraftingResult); discoveredItems.add(wrappedCraftingResult);
} }
} }
for (CustomStackWrapper wrappedRecipeInput : RecipeHelper.getCollatedRecipeInputs((IRecipe) recipe)) { for (CustomWrappedStack wrappedRecipeInput : RecipeHelper.getCollatedRecipeInputs((IRecipe) recipe)) {
if ((wrappedRecipeInput.getItemStack() != null) && (wrappedRecipeInput.getItemStack().getItemDamage() == OreDictionary.WILDCARD_VALUE)) { if ((wrappedRecipeInput.getItemStack() != null) && (wrappedRecipeInput.getItemStack().getItemDamage() == OreDictionary.WILDCARD_VALUE)) {
wrappedRecipeInput.setWrappedStackSize(1); wrappedRecipeInput.setStackSize(1);
if (!discoveredItems.contains(wrappedRecipeInput)) { if (!discoveredItems.contains(wrappedRecipeInput)) {
discoveredItems.add(wrappedRecipeInput); discoveredItems.add(wrappedRecipeInput);
} }
@ -109,7 +109,7 @@ public class DynEMC {
for (ItemStack itemStack : subItems) { for (ItemStack itemStack : subItems) {
if (itemStack != null) { if (itemStack != null) {
CustomStackWrapper customStackWrapper = new CustomStackWrapper(itemStack); CustomWrappedStack customStackWrapper = new CustomWrappedStack(itemStack);
if (!discoveredItems.contains(customStackWrapper)) { if (!discoveredItems.contains(customStackWrapper)) {
discoveredItems.add(customStackWrapper); discoveredItems.add(customStackWrapper);
@ -121,7 +121,7 @@ public class DynEMC {
ItemStack itemStack = new ItemStack(Item.itemsList[i]); ItemStack itemStack = new ItemStack(Item.itemsList[i]);
CustomStackWrapper customStackWrapper = new CustomStackWrapper(itemStack); CustomWrappedStack customStackWrapper = new CustomWrappedStack(itemStack);
if (!discoveredItems.contains(customStackWrapper)) { if (!discoveredItems.contains(customStackWrapper)) {
discoveredItems.add(customStackWrapper); discoveredItems.add(customStackWrapper);
} }
@ -133,42 +133,41 @@ public class DynEMC {
* Now that we have discovered as many items as possible, trim out the * Now that we have discovered as many items as possible, trim out the
* items that are black listed * items that are black listed
*/ */
for (CustomStackWrapper customStackWrapper : EmcBlackList.getInstance().getBlackListStacks()) { for (CustomWrappedStack customStackWrapper : EmcBlackList.getInstance().getBlackListStacks()) {
while (discoveredItems.contains(customStackWrapper)) { while (discoveredItems.contains(customStackWrapper)) {
discoveredItems.remove(customStackWrapper); discoveredItems.remove(customStackWrapper);
} }
} }
for (CustomStackWrapper customWrappedStack : discoveredItems) { for (CustomWrappedStack customWrappedStack : discoveredItems) {
if (!graph.nodeExists(customWrappedStack)) { if (!graph.nodeExists(customWrappedStack)) {
graph.addNode(customWrappedStack); graph.addNode(customWrappedStack);
} }
} }
for (CustomStackWrapper customWrappedStack : discoveredItems) { for (CustomWrappedStack customWrappedStack : discoveredItems) {
ArrayList<IRecipe> recipes = RecipeHelper.getReverseRecipes(customWrappedStack); ArrayList<IRecipe> recipes = RecipeHelper.getReverseRecipes(customWrappedStack);
for (IRecipe recipe : recipes) { for (IRecipe recipe : recipes) {
ArrayList<CustomStackWrapper> recipeInputs = RecipeHelper.getCollatedRecipeInputs(recipe); ArrayList<CustomWrappedStack> recipeInputs = RecipeHelper.getCollatedRecipeInputs(recipe);
System.out.println(recipeInputs); for (CustomWrappedStack wrappedRecipeInput : recipeInputs) {
for (CustomStackWrapper wrappedRecipeInput : recipeInputs) {
if (wrappedRecipeInput.getItemStack() != null) { if (wrappedRecipeInput.getItemStack() != null) {
ItemStack itemStack = wrappedRecipeInput.getItemStack(); ItemStack itemStack = wrappedRecipeInput.getItemStack();
itemStack.stackSize = wrappedRecipeInput.getStackSize();
if (OreDictionary.getOreID(itemStack) != -1) { if (OreDictionary.getOreID(itemStack) != -1) {
wrappedRecipeInput = new CustomStackWrapper(new OreStack(itemStack)); wrappedRecipeInput = new CustomWrappedStack(new OreStack(itemStack));
} }
} }
float weight = wrappedRecipeInput.getWrappedStackSize(); float weight = wrappedRecipeInput.getStackSize();
wrappedRecipeInput.setWrappedStackSize(1); wrappedRecipeInput.setStackSize(1);
try { try {
graph.addEdge(customWrappedStack, wrappedRecipeInput, weight); graph.addEdge(customWrappedStack, wrappedRecipeInput, weight);
@ -187,9 +186,9 @@ public class DynEMC {
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
LogHelper.log(Level.INFO, "***** START NODES *****"); LogHelper.log(Level.INFO, "***** START NODES *****");
Iterator<CustomStackWrapper> nodeIter = graph.iterator(); Iterator<CustomWrappedStack> nodeIter = graph.iterator();
while (nodeIter.hasNext()) { while (nodeIter.hasNext()) {
CustomStackWrapper node = nodeIter.next(); CustomWrappedStack node = nodeIter.next();
LogHelper.log(Level.INFO, "Node: " + node); LogHelper.log(Level.INFO, "Node: " + node);
} }
LogHelper.log(Level.INFO, "***** END NODES *****"); LogHelper.log(Level.INFO, "***** END NODES *****");
@ -197,9 +196,9 @@ public class DynEMC {
LogHelper.log(Level.INFO, "***** START EDGES FROM *****"); LogHelper.log(Level.INFO, "***** START EDGES FROM *****");
nodeIter = graph.iterator(); nodeIter = graph.iterator();
while (nodeIter.hasNext()) { while (nodeIter.hasNext()) {
CustomStackWrapper node = nodeIter.next(); CustomWrappedStack node = nodeIter.next();
Set<WeightedEdge<CustomStackWrapper>> edgesFrom = graph.edgesFrom(node); Set<WeightedEdge<CustomWrappedStack>> edgesFrom = graph.edgesFrom(node);
for (WeightedEdge<CustomStackWrapper> edge : edgesFrom) { for (WeightedEdge<CustomWrappedStack> edge : edgesFrom) {
LogHelper.log(Level.INFO, "Crafting Output: " + node); LogHelper.log(Level.INFO, "Crafting Output: " + node);
LogHelper.log(Level.INFO, "Crafting Input: " + edge.getTarget()); LogHelper.log(Level.INFO, "Crafting Input: " + edge.getTarget());
LogHelper.log(Level.INFO, "Weight: " + edge.getWeight()); LogHelper.log(Level.INFO, "Weight: " + edge.getWeight());

View file

@ -8,13 +8,13 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary;
import com.pahimar.ee3.item.CustomStackWrapper; import com.pahimar.ee3.item.CustomWrappedStack;
public class EmcBlackList { public class EmcBlackList {
private static EmcBlackList emcBlackList = null; private static EmcBlackList emcBlackList = null;
private ArrayList<CustomStackWrapper> stackBlackList = new ArrayList<CustomStackWrapper>(); private ArrayList<CustomWrappedStack> stackBlackList = new ArrayList<CustomWrappedStack>();
private EmcBlackList() { private EmcBlackList() {
@ -31,14 +31,14 @@ public class EmcBlackList {
return emcBlackList; return emcBlackList;
} }
public List<CustomStackWrapper> getBlackListStacks() { public List<CustomWrappedStack> getBlackListStacks() {
return stackBlackList; return stackBlackList;
} }
public void add(ItemStack itemStack) { public void add(ItemStack itemStack) {
CustomStackWrapper customStackWrapper = new CustomStackWrapper(itemStack); CustomWrappedStack customStackWrapper = new CustomWrappedStack(itemStack);
if (!stackBlackList.contains(customStackWrapper)) { if (!stackBlackList.contains(customStackWrapper)) {
stackBlackList.add(customStackWrapper); stackBlackList.add(customStackWrapper);
@ -72,7 +72,7 @@ public class EmcBlackList {
itemStack.stackSize = 1; itemStack.stackSize = 1;
} }
return stackBlackList.contains(new CustomStackWrapper(itemStack)); return stackBlackList.contains(new CustomWrappedStack(itemStack));
} }
public boolean contains(Item item) { public boolean contains(Item item) {
@ -97,7 +97,7 @@ public class EmcBlackList {
public void remove(ItemStack itemStack) { public void remove(ItemStack itemStack) {
CustomStackWrapper customStackWrapper = new CustomStackWrapper(itemStack); CustomWrappedStack customStackWrapper = new CustomWrappedStack(itemStack);
while (stackBlackList.contains(customStackWrapper)) { while (stackBlackList.contains(customStackWrapper)) {
stackBlackList.remove(customStackWrapper); stackBlackList.remove(customStackWrapper);

View file

@ -5,64 +5,64 @@ import java.util.List;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import com.pahimar.ee3.item.CustomStackWrapper; import com.pahimar.ee3.item.CustomWrappedStack;
public class EquivalencyGroup { public class EquivalencyGroup {
private List<CustomStackWrapper> equivalentItems; private List<CustomWrappedStack> equivalentItems;
public EquivalencyGroup() { public EquivalencyGroup() {
equivalentItems = new ArrayList<CustomStackWrapper>(); equivalentItems = new ArrayList<CustomWrappedStack>();
} }
public EquivalencyGroup(List<ItemStack> equivalentItems) { public EquivalencyGroup(List<ItemStack> equivalentItems) {
this.equivalentItems = new ArrayList<CustomStackWrapper>(); this.equivalentItems = new ArrayList<CustomWrappedStack>();
for (ItemStack itemStack : equivalentItems) { for (ItemStack itemStack : equivalentItems) {
this.equivalentItems.add(new CustomStackWrapper(itemStack)); this.equivalentItems.add(new CustomWrappedStack(itemStack));
} }
} }
public List<CustomStackWrapper> getMembers() { public List<CustomWrappedStack> getMembers() {
return equivalentItems; return equivalentItems;
} }
public boolean containsMember(ItemStack itemStack) { public boolean containsMember(ItemStack itemStack) {
return containsMember(new CustomStackWrapper(itemStack)); return containsMember(new CustomWrappedStack(itemStack));
} }
public boolean containsMember(CustomStackWrapper customStackWrapper) { public boolean containsMember(CustomWrappedStack customStackWrapper) {
return equivalentItems.contains(customStackWrapper); return equivalentItems.contains(customStackWrapper);
} }
public void addMember(ItemStack itemStack) { public void addMember(ItemStack itemStack) {
this.addMember(new CustomStackWrapper(itemStack)); this.addMember(new CustomWrappedStack(itemStack));
} }
public void addMember(CustomStackWrapper customStackWrapper) { public void addMember(CustomWrappedStack customStackWrapper) {
if (!containsMember(customStackWrapper)) { if (!containsMember(customStackWrapper)) {
equivalentItems.add(customStackWrapper); equivalentItems.add(customStackWrapper);
} }
} }
public void setEquivalentItems(List<CustomStackWrapper> equivalentItems) { public void setEquivalentItems(List<CustomWrappedStack> equivalentItems) {
this.equivalentItems = equivalentItems; this.equivalentItems = equivalentItems;
} }
public void removeMember(ItemStack itemStack) { public void removeMember(ItemStack itemStack) {
removeMember(new CustomStackWrapper(itemStack)); removeMember(new CustomWrappedStack(itemStack));
} }
public void removeMember(CustomStackWrapper customStackWrapper) { public void removeMember(CustomWrappedStack customStackWrapper) {
while (containsMember(customStackWrapper)) { while (containsMember(customStackWrapper)) {
equivalentItems.remove(customStackWrapper); equivalentItems.remove(customStackWrapper);
@ -71,7 +71,7 @@ public class EquivalencyGroup {
public void clearMembers() { public void clearMembers() {
equivalentItems = new ArrayList<CustomStackWrapper>(); equivalentItems = new ArrayList<CustomWrappedStack>();
} }
@Override @Override
@ -92,7 +92,7 @@ public class EquivalencyGroup {
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Equivalent Group Members: "); stringBuilder.append("Equivalent Group Members: ");
for (CustomStackWrapper customStackWrapper : equivalentItems) { for (CustomWrappedStack customStackWrapper : equivalentItems) {
stringBuilder.append(String.format("%s ", customStackWrapper)); stringBuilder.append(String.format("%s ", customStackWrapper));
} }
@ -104,7 +104,7 @@ public class EquivalencyGroup {
int hashCode = 1; int hashCode = 1;
for (CustomStackWrapper customStackWrapper : equivalentItems) { for (CustomWrappedStack customStackWrapper : equivalentItems) {
hashCode = 37 * hashCode + customStackWrapper.hashCode(); hashCode = 37 * hashCode + customStackWrapper.hashCode();
} }

View file

@ -6,51 +6,42 @@ import net.minecraftforge.oredict.OreDictionary;
import com.pahimar.ee3.core.util.ItemUtil; import com.pahimar.ee3.core.util.ItemUtil;
import com.pahimar.ee3.core.util.OreStack; import com.pahimar.ee3.core.util.OreStack;
public class CustomStackWrapper { public class CustomWrappedStack {
private int stackSize;
private ItemStack itemStack; private ItemStack itemStack;
private OreStack oreStack; private OreStack oreStack;
public CustomStackWrapper(ItemStack itemStack) { public CustomWrappedStack(ItemStack itemStack) {
this.itemStack = itemStack; this.itemStack = itemStack;
this.oreStack = null; this.oreStack = null;
stackSize = itemStack.stackSize;
if (this.itemStack != null) { if (this.itemStack != null) {
this.itemStack.stackSize = 1; this.itemStack.stackSize = 1;
} }
} }
public CustomStackWrapper(OreStack oreStack) { public CustomWrappedStack(OreStack oreStack) {
this.itemStack = null; this.itemStack = null;
this.oreStack = oreStack; this.oreStack = oreStack;
stackSize = oreStack.stackSize;
if (this.oreStack != null) { if (this.oreStack != null) {
this.oreStack.stackSize = 1; this.oreStack.stackSize = 1;
} }
} }
public int getWrappedStackSize() { public int getStackSize() {
if (itemStack != null) { return stackSize;
return itemStack.stackSize;
}
else if (oreStack != null) {
return oreStack.stackSize;
} }
return -1; public void setStackSize(int stackSize) {
}
public void setWrappedStackSize(int stackSize) { this.stackSize = stackSize;
if (itemStack != null) {
itemStack.stackSize = stackSize;
}
else if (oreStack != null) {
oreStack.stackSize = stackSize;
}
} }
public ItemStack getItemStack() { public ItemStack getItemStack() {
@ -66,19 +57,19 @@ public class CustomStackWrapper {
@Override @Override
public boolean equals(Object object) { public boolean equals(Object object) {
if (!(object instanceof CustomStackWrapper)) { if (!(object instanceof CustomWrappedStack)) {
return false; return false;
} }
CustomStackWrapper customWrappedStack = (CustomStackWrapper) object; CustomWrappedStack customWrappedStack = (CustomWrappedStack) object;
if (itemStack != null) { if (itemStack != null) {
if (customWrappedStack.itemStack != null) { if (customWrappedStack.itemStack != null) {
return ItemUtil.compare(this.itemStack, customWrappedStack.itemStack); return (ItemUtil.compare(this.itemStack, customWrappedStack.itemStack) && stackSize == customWrappedStack.itemStack.stackSize);
} }
else if (customWrappedStack.oreStack != null) { else if (customWrappedStack.oreStack != null) {
for (ItemStack oreDictItemStack : OreDictionary.getOres(customWrappedStack.oreStack.oreName)) { for (ItemStack oreDictItemStack : OreDictionary.getOres(customWrappedStack.oreStack.oreName)) {
if (ItemUtil.compare(itemStack, oreDictItemStack)) { if (ItemUtil.compare(itemStack, oreDictItemStack) && stackSize == oreDictItemStack.stackSize) {
return true; return true;
} }
} }
@ -87,13 +78,13 @@ public class CustomStackWrapper {
else if (oreStack != null) { else if (oreStack != null) {
if (customWrappedStack.itemStack != null) { if (customWrappedStack.itemStack != null) {
for (ItemStack oreDictItemStack : OreDictionary.getOres(oreStack.oreName)) { for (ItemStack oreDictItemStack : OreDictionary.getOres(oreStack.oreName)) {
if (ItemUtil.compare(customWrappedStack.itemStack, oreDictItemStack)) { if (ItemUtil.compare(customWrappedStack.itemStack, oreDictItemStack) && stackSize == oreDictItemStack.stackSize) {
return true; return true;
} }
} }
} }
else if (customWrappedStack.oreStack != null) { else if (customWrappedStack.oreStack != null) {
return oreStack.equals(customWrappedStack.oreStack); return (oreStack.equals(customWrappedStack.oreStack) && stackSize == oreStack.stackSize);
} }
} }
@ -118,6 +109,8 @@ public class CustomStackWrapper {
int hashCode = 1; int hashCode = 1;
hashCode = 37 * hashCode + stackSize;
if (itemStack != null) { if (itemStack != null) {
hashCode = 37 * hashCode + itemStack.itemID; hashCode = 37 * hashCode + itemStack.itemID;
@ -128,11 +121,9 @@ public class CustomStackWrapper {
hashCode = 37 * hashCode + itemStack.getItemDamage(); hashCode = 37 * hashCode + itemStack.getItemDamage();
} }
hashCode = 37 * hashCode + itemStack.stackSize;
hashCode = 37 * hashCode + itemStack.getItemName().hashCode(); hashCode = 37 * hashCode + itemStack.getItemName().hashCode();
} }
else if (oreStack != null) { else if (oreStack != null) {
hashCode = 37 * hashCode + oreStack.stackSize;
hashCode = 37 * hashCode + oreStack.oreName.hashCode(); hashCode = 37 * hashCode + oreStack.oreName.hashCode();
} }