add meta object to storage items
This commit is contained in:
@@ -12,7 +12,7 @@ public class CellStorage implements IStorage {
|
||||
|
||||
public static final String NBT_ITEM_TYPE = "Type";
|
||||
public static final String NBT_ITEM_QUANTITY = "Quantity";
|
||||
public static final String NBT_ITEM_META = "Meta";
|
||||
public static final String NBT_ITEM_DAMAGE = "Damage";
|
||||
public static final String NBT_ITEM_NBT = "NBT";
|
||||
|
||||
private ItemStack cell;
|
||||
@@ -22,7 +22,7 @@ public class CellStorage implements IStorage {
|
||||
}
|
||||
|
||||
private StorageItem createItemFromNBT(NBTTagCompound tag) {
|
||||
return new StorageItem(Item.getItemById(tag.getInteger(NBT_ITEM_TYPE)), tag.getInteger(NBT_ITEM_QUANTITY), tag.getInteger(NBT_ITEM_META), tag.hasKey(NBT_ITEM_NBT) ? ((NBTTagCompound) tag.getTag(NBT_ITEM_NBT)) : null);
|
||||
return new StorageItem(Item.getItemById(tag.getInteger(NBT_ITEM_TYPE)), tag.getInteger(NBT_ITEM_QUANTITY), tag.getInteger(NBT_ITEM_DAMAGE), tag.hasKey(NBT_ITEM_NBT) ? ((NBTTagCompound) tag.getTag(NBT_ITEM_NBT)) : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,7 +45,7 @@ public class CellStorage implements IStorage {
|
||||
|
||||
StorageItem item = createItemFromNBT(tag);
|
||||
|
||||
if (item.equalsIgnoreQuantity(stack)) {
|
||||
if (item.getMeta().equals(stack)) {
|
||||
tag.setInteger(NBT_ITEM_QUANTITY, item.getQuantity() + stack.stackSize);
|
||||
|
||||
return;
|
||||
@@ -56,7 +56,7 @@ public class CellStorage implements IStorage {
|
||||
|
||||
tag.setInteger(NBT_ITEM_TYPE, Item.getIdFromItem(stack.getItem()));
|
||||
tag.setInteger(NBT_ITEM_QUANTITY, stack.stackSize);
|
||||
tag.setInteger(NBT_ITEM_META, stack.getItemDamage());
|
||||
tag.setInteger(NBT_ITEM_DAMAGE, stack.getItemDamage());
|
||||
|
||||
if (stack.stackTagCompound != null) {
|
||||
tag.setTag(NBT_ITEM_NBT, stack.stackTagCompound);
|
||||
@@ -76,7 +76,7 @@ public class CellStorage implements IStorage {
|
||||
|
||||
StorageItem item = createItemFromNBT(tag);
|
||||
|
||||
if (item.equalsIgnoreQuantity(stack)) {
|
||||
if (item.getMeta().equals(stack)) {
|
||||
if (quantity > item.getQuantity()) {
|
||||
quantity = item.getQuantity();
|
||||
}
|
||||
|
||||
@@ -5,28 +5,25 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class StorageItem {
|
||||
private Item type;
|
||||
private StorageItemMeta meta;
|
||||
private int quantity;
|
||||
private int meta;
|
||||
private NBTTagCompound tag;
|
||||
|
||||
public StorageItem(Item type, int quantity, int meta, NBTTagCompound tag) {
|
||||
this.type = type;
|
||||
public StorageItem(StorageItemMeta meta, int quantity) {
|
||||
this.meta = meta;
|
||||
this.quantity = quantity;
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public StorageItem(Item type, int quantity, int damage, NBTTagCompound tag) {
|
||||
this.meta = new StorageItemMeta(type, damage, tag);
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
public StorageItem(ItemStack stack) {
|
||||
this(stack.getItem(), stack.stackSize, stack.getItemDamage(), stack.stackTagCompound);
|
||||
}
|
||||
|
||||
public Item getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(Item type) {
|
||||
this.type = type;
|
||||
public StorageItemMeta getMeta() {
|
||||
return meta;
|
||||
}
|
||||
|
||||
public int getQuantity() {
|
||||
@@ -37,63 +34,23 @@ public class StorageItem {
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
public int getMeta() {
|
||||
return meta;
|
||||
}
|
||||
|
||||
public void setMeta(int meta) {
|
||||
this.meta = meta;
|
||||
}
|
||||
|
||||
public NBTTagCompound getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
public void setTag(NBTTagCompound tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public StorageItem copy() {
|
||||
return copy(quantity);
|
||||
}
|
||||
|
||||
public StorageItem copy(int newQuantity) {
|
||||
return new StorageItem(type, newQuantity, meta, tag);
|
||||
return new StorageItem(meta, newQuantity);
|
||||
}
|
||||
|
||||
public ItemStack toItemStack() {
|
||||
ItemStack stack = new ItemStack(type, quantity, meta);
|
||||
ItemStack stack = new ItemStack(meta.getType(), quantity, meta.getDamage());
|
||||
|
||||
stack.stackTagCompound = tag;
|
||||
stack.stackTagCompound = meta.getTag();
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
public boolean equalsIgnoreQuantity(ItemStack other) {
|
||||
if (tag != null && !tag.equals(other.stackTagCompound)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return type == other.getItem() && meta == other.getItemDamage();
|
||||
}
|
||||
|
||||
public boolean equalsIgnoreQuantity(StorageItem other) {
|
||||
if (tag != null && !tag.equals(other.getTag())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return type == other.getType() && meta == other.getMeta();
|
||||
}
|
||||
|
||||
public static boolean equalsIgnoreQuantity(ItemStack first, ItemStack second) {
|
||||
if (first.stackTagCompound != null && !first.stackTagCompound.equals(second.stackTagCompound)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return first.getItem() == second.getItem() && first.getItemDamage() == second.getItemDamage();
|
||||
}
|
||||
|
||||
public boolean equals(StorageItem other) {
|
||||
return other.getQuantity() == quantity && equalsIgnoreQuantity(other);
|
||||
return other.getQuantity() == quantity && other.getMeta().equals(meta);
|
||||
}
|
||||
}
|
||||
|
||||
45
src/main/java/storagecraft/storage/StorageItemMeta.java
Normal file
45
src/main/java/storagecraft/storage/StorageItemMeta.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package storagecraft.storage;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class StorageItemMeta {
|
||||
private Item type;
|
||||
private int damage;
|
||||
private NBTTagCompound tag;
|
||||
|
||||
public StorageItemMeta(Item type, int damage, NBTTagCompound tag) {
|
||||
this.type = type;
|
||||
this.damage = damage;
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public Item getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public int getDamage() {
|
||||
return damage;
|
||||
}
|
||||
|
||||
public NBTTagCompound getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
public boolean equals(StorageItemMeta meta) {
|
||||
if (tag != null && !tag.equals(meta.getTag())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return type == meta.getType() && damage == meta.getDamage();
|
||||
}
|
||||
|
||||
public boolean equals(ItemStack stack) {
|
||||
if (tag != null && !tag.equals(stack.stackTagCompound)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return type == stack.getItem() && damage == stack.getItemDamage();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user