GT5-Unofficial/src/main/java/gregtech/api/objects/MaterialStack.java

51 lines
1.6 KiB
Java
Raw Normal View History

2015-04-23 16:14:22 +00:00
package gregtech.api.objects;
import gregtech.api.enums.Materials;
public class MaterialStack implements Cloneable {
2015-10-22 02:06:25 +00:00
public long mAmount;
public Materials mMaterial;
public MaterialStack(Materials aMaterial, long aAmount) {
mMaterial = aMaterial == null ? Materials._NULL : aMaterial;
mAmount = aAmount;
}
public MaterialStack copy(long aAmount) {
return new MaterialStack(mMaterial, aAmount);
}
@Override
public MaterialStack clone() {
2016-08-14 02:50:59 +00:00
try { Object cloneMS = super.clone();
return (MaterialStack) cloneMS;} catch (Exception e) { return new MaterialStack(mMaterial, mAmount); }
2015-10-22 02:06:25 +00:00
}
@Override
public boolean equals(Object aObject) {
if (aObject == this) return true;
if (aObject == null) return false;
if (aObject instanceof Materials) return aObject == mMaterial;
if (aObject instanceof MaterialStack)
return ((MaterialStack) aObject).mMaterial == mMaterial && (mAmount < 0 || ((MaterialStack) aObject).mAmount < 0 || ((MaterialStack) aObject).mAmount == mAmount);
return false;
}
@Override
public String toString() {
2016-08-14 07:36:42 +00:00
String temp1 = "", temp2 = mMaterial.getToolTip(true), temp3 = "", temp4 = "";
if (mAmount > 1) {
temp4 = String.valueOf(mAmount);
if (mMaterial.mMaterialList.size() > 1) {
temp1 = "(";
temp3 = ")";
}
}
return String.valueOf(new StringBuilder().append(temp1).append(temp2).append(temp3).append(temp4));
2015-10-22 02:06:25 +00:00
}
@Override
public int hashCode() {
return mMaterial.hashCode();
}
2015-04-23 16:14:22 +00:00
}