Getting back on board with pstone functionality
This commit is contained in:
parent
cce75edd86
commit
5a6fc15b2c
64
ee3_common/ee3/common/core/handlers/EquivalencyHandler.java
Normal file
64
ee3_common/ee3/common/core/handlers/EquivalencyHandler.java
Normal file
|
@ -0,0 +1,64 @@
|
|||
package ee3.common.core.handlers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import ee3.common.core.helper.GeneralHelper;
|
||||
import net.minecraft.src.ItemStack;
|
||||
|
||||
public class EquivalencyHandler {
|
||||
|
||||
public static ArrayList<ArrayList<ItemStack>> equivalencyList = new ArrayList<ArrayList<ItemStack>>();
|
||||
|
||||
public static void addObjectToEquivalencyList(Object obj1, Object obj2) {
|
||||
ItemStack stack1 = GeneralHelper.convertObjectToItemStack(obj1);
|
||||
ItemStack stack2 = GeneralHelper.convertObjectToItemStack(obj2);
|
||||
|
||||
ArrayList<ItemStack> currentList = new ArrayList<ItemStack>();
|
||||
|
||||
Integer stack1Index = getEquivalencyIndexForItem(stack1);
|
||||
Integer stack2Index = getEquivalencyIndexForItem(stack2);
|
||||
|
||||
if ((stack1Index != null) && (stack2Index != null)) {
|
||||
return;
|
||||
} else if ((stack1Index != null) && (stack2Index == null)) {
|
||||
currentList = equivalencyList.get(stack1Index.intValue());
|
||||
currentList.add(stack2);
|
||||
equivalencyList.set(stack1Index.intValue(), currentList);
|
||||
} else if ((stack1Index == null) && (stack2Index != null)) {
|
||||
currentList = equivalencyList.get(stack2Index.intValue());
|
||||
currentList.add(stack1);
|
||||
equivalencyList.set(stack2Index.intValue(), currentList);
|
||||
} else if ((stack1Index == null) && (stack2Index == null)) {
|
||||
currentList.add(stack1);
|
||||
currentList.add(stack2);
|
||||
equivalencyList.add(currentList);
|
||||
}
|
||||
}
|
||||
|
||||
public static Integer getEquivalencyIndexForItem(Object obj) {
|
||||
ItemStack checkStack = GeneralHelper.convertObjectToItemStack(obj);
|
||||
ArrayList<ItemStack> currentList;
|
||||
int i = 0;
|
||||
|
||||
while (i < equivalencyList.size()) {
|
||||
currentList = equivalencyList.get(i);
|
||||
for (ItemStack currentStack : currentList) {
|
||||
if (checkStack.isStackEqual(currentStack)) {
|
||||
return new Integer(i);
|
||||
}
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void debug() {
|
||||
int i = 0;
|
||||
for (ArrayList list : equivalencyList) {
|
||||
System.out
|
||||
.println("equivalencyList[" + i + "]: " + list.toString());
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
35
ee3_common/ee3/common/core/helper/GeneralHelper.java
Normal file
35
ee3_common/ee3/common/core/helper/GeneralHelper.java
Normal file
|
@ -0,0 +1,35 @@
|
|||
package ee3.common.core.helper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.src.Block;
|
||||
import net.minecraft.src.Item;
|
||||
import net.minecraft.src.ItemStack;
|
||||
|
||||
public class GeneralHelper {
|
||||
|
||||
public static ItemStack convertObjectToItemStack(Object obj) {
|
||||
if (obj instanceof Item) {
|
||||
return new ItemStack((Item) obj);
|
||||
} else if (obj instanceof Block) {
|
||||
return new ItemStack((Block) obj);
|
||||
} else if (obj instanceof ItemStack) {
|
||||
return (ItemStack) obj;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Object[] convertSingleStackToPluralStacks(ItemStack stack) {
|
||||
ArrayList<ItemStack> list = new ArrayList<ItemStack>();
|
||||
ItemStack currentStack;
|
||||
|
||||
for (int i = 0; i < stack.stackSize; i++) {
|
||||
currentStack = new ItemStack(stack.itemID, 1, stack.getItemDamage());
|
||||
list.add(currentStack);
|
||||
}
|
||||
|
||||
return list.toArray();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue