make the exporter work

This commit is contained in:
Raoul Van den Berge
2015-12-19 10:47:22 +01:00
parent 8fc7eb8563
commit 68a4656f22
8 changed files with 153 additions and 92 deletions

View File

@@ -42,7 +42,7 @@ public class CellStorage implements IStorage {
StorageItem item = createItemFromNBT(tag);
if (item.getMeta().equals(stack)) {
if (item.compareNoQuantity(stack)) {
tag.setInteger(NBT_ITEM_QUANTITY, item.getQuantity() + stack.stackSize);
return;
@@ -63,7 +63,7 @@ public class CellStorage implements IStorage {
}
@Override
public int take(ItemStack stack) {
public ItemStack take(ItemStack stack, int flags) {
int quantity = stack.stackSize;
NBTTagList list = (NBTTagList) cell.stackTagCompound.getTag(NBT_ITEMS);
@@ -73,7 +73,7 @@ public class CellStorage implements IStorage {
StorageItem item = createItemFromNBT(tag);
if (item.getMeta().equals(stack)) {
if (item.compare(stack, flags)) {
if (quantity > item.getQuantity()) {
quantity = item.getQuantity();
}
@@ -86,11 +86,15 @@ public class CellStorage implements IStorage {
cell.stackTagCompound.setInteger(NBT_STORED, ItemStorageCell.getStored(cell) - quantity);
return quantity;
ItemStack newItem = item.toItemStack();
newItem.stackSize = quantity;
return newItem;
}
}
return 0;
return null;
}
@Override

View File

@@ -8,7 +8,7 @@ public interface IStorage {
public void push(ItemStack stack);
public int take(ItemStack stack);
public ItemStack take(ItemStack stack, int flags);
public boolean canPush(ItemStack stack);
}

View File

@@ -3,27 +3,27 @@ package storagecraft.storage;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import storagecraft.util.InventoryUtils;
public class StorageItem {
private StorageItemMeta meta;
private Item type;
private int quantity;
public StorageItem(StorageItemMeta meta, int quantity) {
this.meta = meta;
this.quantity = quantity;
}
private int damage;
private NBTTagCompound tag;
public StorageItem(Item type, int quantity, int damage, NBTTagCompound tag) {
this.meta = new StorageItemMeta(type, damage, tag);
this.type = type;
this.quantity = quantity;
this.damage = damage;
this.tag = tag;
}
public StorageItem(ItemStack stack) {
this(stack.getItem(), stack.stackSize, stack.getItemDamage(), stack.stackTagCompound);
}
public StorageItemMeta getMeta() {
return meta;
public Item getType() {
return type;
}
public int getQuantity() {
@@ -34,23 +34,87 @@ public class StorageItem {
this.quantity = quantity;
}
public int getDamage() {
return damage;
}
public void setDamage(int damage) {
this.damage = damage;
}
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(meta, newQuantity);
return new StorageItem(type, newQuantity, damage, tag);
}
public ItemStack toItemStack() {
ItemStack stack = new ItemStack(meta.getType(), quantity, meta.getDamage());
ItemStack stack = new ItemStack(type, quantity, damage);
stack.stackTagCompound = meta.getTag();
stack.stackTagCompound = tag;
return stack;
}
public boolean equals(StorageItem other) {
return other.getQuantity() == quantity && other.getMeta().equals(meta);
public boolean compare(StorageItem other, int flags) {
if ((flags & InventoryUtils.COMPARE_NBT) == InventoryUtils.COMPARE_NBT) {
if (tag != null && !tag.equals(other.getTag())) {
return false;
}
}
if ((flags & InventoryUtils.COMPARE_DAMAGE) == InventoryUtils.COMPARE_DAMAGE) {
if (damage != other.getDamage()) {
return false;
}
}
if ((flags & InventoryUtils.COMPARE_QUANTITY) == InventoryUtils.COMPARE_QUANTITY) {
if (quantity != other.getQuantity()) {
return false;
}
}
return type == other.getType();
}
public boolean compare(ItemStack stack, int flags) {
if ((flags & InventoryUtils.COMPARE_NBT) == InventoryUtils.COMPARE_NBT) {
if (tag != null && !tag.equals(stack.stackTagCompound)) {
return false;
}
}
if ((flags & InventoryUtils.COMPARE_DAMAGE) == InventoryUtils.COMPARE_DAMAGE) {
if (damage != stack.getItemDamage()) {
return false;
}
}
if ((flags & InventoryUtils.COMPARE_QUANTITY) == InventoryUtils.COMPARE_QUANTITY) {
if (quantity != stack.stackSize) {
return false;
}
}
return type == stack.getItem();
}
public boolean compareNoQuantity(StorageItem other) {
return compare(other, InventoryUtils.COMPARE_NBT | InventoryUtils.COMPARE_DAMAGE);
}
public boolean compareNoQuantity(ItemStack stack) {
return compare(stack, InventoryUtils.COMPARE_NBT | InventoryUtils.COMPARE_DAMAGE);
}
}

View File

@@ -1,45 +0,0 @@
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();
}
}