2013-10-18 02:53:08 +02:00
|
|
|
package com.pahimar.ee3.item;
|
2013-08-23 16:59:50 +02:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraftforge.oredict.OreDictionary;
|
|
|
|
|
2013-09-06 04:21:55 +02:00
|
|
|
public class OreStack implements Comparable<OreStack> {
|
2013-08-23 16:59:50 +02:00
|
|
|
|
2013-10-24 04:22:26 +02:00
|
|
|
public int oreId;
|
2013-08-23 16:59:50 +02:00
|
|
|
public String oreName;
|
|
|
|
public int stackSize;
|
|
|
|
|
|
|
|
public OreStack(String oreName, int stackSize) {
|
2013-10-24 04:22:26 +02:00
|
|
|
|
|
|
|
if (oreName != null && oreName.length() > 0) {
|
|
|
|
|
|
|
|
if (this.oreName == null) {
|
|
|
|
|
|
|
|
for (String oreDictionaryName : OreDictionary.getOreNames()) {
|
|
|
|
|
|
|
|
if (oreDictionaryName.equalsIgnoreCase(oreName)) {
|
|
|
|
|
|
|
|
this.oreId = OreDictionary.getOreID(oreDictionaryName);
|
|
|
|
this.oreName = oreDictionaryName;
|
|
|
|
}
|
|
|
|
}
|
2013-11-08 02:37:44 +01:00
|
|
|
|
|
|
|
if (this.oreName == null) {
|
|
|
|
this.oreId = -1;
|
|
|
|
this.oreName = OreDictionary.getOreName(oreId);
|
|
|
|
}
|
2013-10-24 04:22:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
this.oreId = -1;
|
|
|
|
this.oreName = OreDictionary.getOreName(oreId);
|
|
|
|
}
|
|
|
|
|
2013-08-23 16:59:50 +02:00
|
|
|
this.stackSize = stackSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
public OreStack(String oreName) {
|
|
|
|
|
2013-10-24 04:22:26 +02:00
|
|
|
this(oreName, 1);
|
2013-08-23 16:59:50 +02:00
|
|
|
}
|
|
|
|
|
2013-10-24 04:22:26 +02:00
|
|
|
public OreStack(int oreId) {
|
2013-08-23 16:59:50 +02:00
|
|
|
|
2013-10-24 04:22:26 +02:00
|
|
|
this(oreId, 1);
|
2013-08-23 16:59:50 +02:00
|
|
|
}
|
2013-10-24 04:22:26 +02:00
|
|
|
|
|
|
|
public OreStack(int oreId, int stackSize) {
|
|
|
|
|
|
|
|
this(OreDictionary.getOreName(oreId), stackSize);
|
2013-08-23 16:59:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public OreStack(ItemStack itemStack) {
|
|
|
|
|
|
|
|
this(OreDictionary.getOreID(itemStack), itemStack.stackSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ArrayList<ItemStack> getOres() {
|
|
|
|
|
2013-10-24 04:22:26 +02:00
|
|
|
if (this.oreId != -1) {
|
|
|
|
return OreDictionary.getOres(this.oreId);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new ArrayList<ItemStack>();
|
2013-08-23 16:59:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
|
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
|
2013-10-25 21:22:59 +02:00
|
|
|
stringBuilder.append(String.format("%dxoreDictionary.%s[oreId:%s]", stackSize, oreName, oreId));
|
2013-08-23 16:59:50 +02:00
|
|
|
|
|
|
|
return stringBuilder.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object object) {
|
|
|
|
|
|
|
|
if (!(object instanceof OreStack))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
OreStack oreStackObject = (OreStack) object;
|
|
|
|
|
2013-10-24 04:22:26 +02:00
|
|
|
return (compareTo(oreStackObject) == 0);
|
2013-08-23 16:59:50 +02:00
|
|
|
}
|
|
|
|
|
2013-09-06 04:21:55 +02:00
|
|
|
public static boolean compareOreNames(OreStack oreStack1, OreStack oreStack2) {
|
2013-08-23 16:59:50 +02:00
|
|
|
|
2013-09-06 19:50:17 +02:00
|
|
|
if (oreStack1 != null && oreStack2 != null) {
|
|
|
|
if ((oreStack1.oreName != null) && (oreStack2.oreName != null)) {
|
|
|
|
return oreStack1.oreName.equalsIgnoreCase(oreStack2.oreName);
|
|
|
|
}
|
2013-08-23 16:59:50 +02:00
|
|
|
}
|
|
|
|
|
2013-09-06 04:21:55 +02:00
|
|
|
return false;
|
2013-08-23 16:59:50 +02:00
|
|
|
}
|
|
|
|
|
2013-09-06 19:50:17 +02:00
|
|
|
@Override
|
|
|
|
public int compareTo(OreStack oreStack) {
|
|
|
|
|
|
|
|
if (oreStack != null) {
|
2013-10-24 04:22:26 +02:00
|
|
|
|
|
|
|
if (this.oreId != oreStack.oreId) {
|
|
|
|
if (this.oreId > oreStack.oreId) {
|
|
|
|
return 1;
|
2013-09-06 19:50:17 +02:00
|
|
|
}
|
|
|
|
else {
|
2013-10-24 04:22:26 +02:00
|
|
|
return -1;
|
2013-09-06 19:50:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2013-10-24 04:22:26 +02:00
|
|
|
if ((this.oreName != null) && (oreStack.oreName != null)) {
|
|
|
|
if (this.oreName.equalsIgnoreCase(oreStack.oreName)) {
|
|
|
|
return (this.stackSize - oreStack.stackSize);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return this.oreName.compareToIgnoreCase(oreStack.oreName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((this.oreName != null) && (oreStack.oreName == null)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else if ((this.oreName == null) && (oreStack.oreName != null)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return (this.stackSize - oreStack.stackSize);
|
|
|
|
}
|
2013-09-06 19:50:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2013-08-23 16:59:50 +02:00
|
|
|
}
|