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

53 lines
1.5 KiB
Java
Raw Normal View History

2015-04-23 16:14:22 +00:00
package gregtech.api.objects;
import gregtech.api.util.GT_Utility;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
public class GT_ItemStack {
2015-10-22 02:15:09 +00:00
public final Item mItem;
public final byte mStackSize;
public final short mMetaData;
public GT_ItemStack(Item aItem, long aStackSize, long aMetaData) {
mItem = aItem;
mStackSize = (byte) aStackSize;
mMetaData = (short) aMetaData;
}
public GT_ItemStack(ItemStack aStack) {
this(aStack == null ? null : aStack.getItem(), aStack == null ? 0 : aStack.stackSize, aStack == null ? 0 : Items.feather.getDamage(aStack));
}
public GT_ItemStack(int aHashCode) {
this(GT_Utility.intToStack(aHashCode));
}
public ItemStack toStack() {
if (mItem == null) return null;
return new ItemStack(mItem, 1, mMetaData);
}
public boolean isStackEqual(ItemStack aStack) {
return GT_Utility.areStacksEqual(toStack(), aStack);
}
public boolean isStackEqual(GT_ItemStack aStack) {
return GT_Utility.areStacksEqual(toStack(), aStack.toStack());
}
@Override
public boolean equals(Object aStack) {
if (aStack == this) return true;
if (aStack instanceof GT_ItemStack) {
return ((GT_ItemStack) aStack).mItem == mItem && ((GT_ItemStack) aStack).mMetaData == mMetaData;
}
return false;
}
@Override
public int hashCode() {
return GT_Utility.stackToInt(toStack());
}
2015-04-23 16:14:22 +00:00
}