equivalent-exchange-3/common/com/pahimar/ee3/item/OreStack.java

138 lines
3.6 KiB
Java
Raw Normal View History

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;
public class OreStack implements Comparable<OreStack> {
2013-08-23 16:59:50 +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) {
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;
}
}
}
}
else {
this.oreId = -1;
this.oreName = OreDictionary.getOreName(oreId);
}
2013-08-23 16:59:50 +02:00
this.stackSize = stackSize;
}
public OreStack(String oreName) {
this(oreName, 1);
2013-08-23 16:59:50 +02:00
}
public OreStack(int oreId) {
2013-08-23 16:59:50 +02:00
this(oreId, 1);
2013-08-23 16:59:50 +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() {
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();
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;
return (compareTo(oreStackObject) == 0);
2013-08-23 16:59:50 +02:00
}
public static boolean compareOreNames(OreStack oreStack1, OreStack oreStack2) {
2013-08-23 16:59:50 +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
}
return false;
2013-08-23 16:59:50 +02:00
}
@Override
public int compareTo(OreStack oreStack) {
if (oreStack != null) {
if (this.oreId != oreStack.oreId) {
if (this.oreId > oreStack.oreId) {
return 1;
}
else {
return -1;
}
}
else {
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);
}
}
}
else {
return 1;
}
}
2013-08-23 16:59:50 +02:00
}