make the exporter work
This commit is contained in:
@@ -14,7 +14,7 @@ public class MessageStoragePull implements IMessage, IMessageHandler<MessageStor
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
// @TODO: this won't work when sorting
|
||||
// @TODO: This won't work when sorting
|
||||
private int slot;
|
||||
private boolean half;
|
||||
private boolean shift;
|
||||
@@ -67,18 +67,21 @@ public class MessageStoragePull implements IMessage, IMessageHandler<MessageStor
|
||||
|
||||
if (message.half && item.getQuantity() > 1) {
|
||||
quantity = item.getQuantity() / 2;
|
||||
|
||||
if (quantity > 64) {
|
||||
quantity = 64;
|
||||
}
|
||||
}
|
||||
|
||||
ItemStack stack = controller.take(item.copy(quantity).toItemStack());
|
||||
ItemStack took = controller.take(item.copy(quantity).toItemStack());
|
||||
|
||||
if (stack.stackSize > 0) {
|
||||
if (took != null) {
|
||||
if (message.shift) {
|
||||
// @TODO: This doesn't work
|
||||
if (!player.inventory.addItemStackToInventory(stack.copy())) {
|
||||
controller.push(stack);
|
||||
if (!player.inventory.addItemStackToInventory(took.copy())) {
|
||||
controller.push(took);
|
||||
}
|
||||
} else {
|
||||
player.inventory.setItemStack(stack);
|
||||
player.inventory.setItemStack(took);
|
||||
player.updateHeldItem();
|
||||
}
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
@@ -15,6 +15,7 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
import storagecraft.storage.IStorage;
|
||||
import storagecraft.storage.IStorageProvider;
|
||||
import storagecraft.storage.StorageItem;
|
||||
import storagecraft.util.InventoryUtils;
|
||||
|
||||
public class TileController extends TileBase implements IEnergyReceiver, INetworkTile {
|
||||
private List<StorageItem> items = new ArrayList<StorageItem>();
|
||||
@@ -141,7 +142,7 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
|
||||
StorageItem other = items.get(j);
|
||||
|
||||
if (item.getMeta().equals(other.getMeta())) {
|
||||
if (item.compareNoQuantity(other)) {
|
||||
item.setQuantity(item.getQuantity() + other.getQuantity());
|
||||
|
||||
markedIndexes.add(j);
|
||||
@@ -181,23 +182,35 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
}
|
||||
|
||||
public ItemStack take(ItemStack stack) {
|
||||
int needed = stack.stackSize;
|
||||
int took = 0;
|
||||
return take(stack, InventoryUtils.COMPARE_DAMAGE | InventoryUtils.COMPARE_NBT);
|
||||
}
|
||||
|
||||
public ItemStack take(ItemStack stack, int flags) {
|
||||
int requested = stack.stackSize;
|
||||
int receiving = 0;
|
||||
|
||||
ItemStack newStack = null;
|
||||
|
||||
for (IStorage storage : storages) {
|
||||
took += storage.take(stack);
|
||||
ItemStack took = storage.take(stack, flags);
|
||||
|
||||
if (took == needed) {
|
||||
if (took != null) {
|
||||
if (newStack == null) {
|
||||
newStack = took;
|
||||
} else {
|
||||
newStack.stackSize += took.stackSize;
|
||||
}
|
||||
|
||||
receiving += took.stackSize;
|
||||
}
|
||||
|
||||
if (requested == receiving) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
syncItems();
|
||||
|
||||
ItemStack newStack = stack.copy();
|
||||
|
||||
newStack.stackSize = took;
|
||||
|
||||
return newStack;
|
||||
}
|
||||
|
||||
@@ -270,13 +283,13 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
buf.writeInt(items.size());
|
||||
|
||||
for (StorageItem item : items) {
|
||||
buf.writeInt(Item.getIdFromItem(item.getMeta().getType()));
|
||||
buf.writeInt(Item.getIdFromItem(item.getType()));
|
||||
buf.writeInt(item.getQuantity());
|
||||
buf.writeInt(item.getMeta().getDamage());
|
||||
buf.writeBoolean(item.getMeta().getTag() != null);
|
||||
buf.writeInt(item.getDamage());
|
||||
buf.writeBoolean(item.getTag() != null);
|
||||
|
||||
if (item.getMeta().getTag() != null) {
|
||||
ByteBufUtils.writeTag(buf, item.getMeta().getTag());
|
||||
if (item.getTag() != null) {
|
||||
ByteBufUtils.writeTag(buf, item.getTag());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -29,7 +29,25 @@ public class TileExporter extends TileMachine implements IInventory {
|
||||
IInventory connectedInventory = (IInventory) tile;
|
||||
|
||||
if (ticks % 5 == 0) {
|
||||
// @TODO: ...
|
||||
for (int i = 0; i < inventory.getSizeInventory(); ++i) {
|
||||
ItemStack slot = inventory.getStackInSlot(i);
|
||||
|
||||
if (slot != null) {
|
||||
ItemStack toTake = slot.copy();
|
||||
|
||||
toTake.stackSize = 64;
|
||||
|
||||
ItemStack took = getController().take(toTake, compareFlags);
|
||||
|
||||
if (took != null) {
|
||||
if (InventoryUtils.canPushToInventory(connectedInventory, took)) {
|
||||
InventoryUtils.pushToInventory(connectedInventory, took);
|
||||
} else {
|
||||
getController().push(took);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -54,11 +54,11 @@ public class TileStorageProxy extends TileMachine implements IStorageProvider, I
|
||||
}
|
||||
|
||||
@Override
|
||||
public int take(ItemStack stack) {
|
||||
public ItemStack take(ItemStack stack, int flags) {
|
||||
IInventory inventory = getInventory();
|
||||
|
||||
if (inventory == null) {
|
||||
return 0;
|
||||
return null;
|
||||
}
|
||||
|
||||
int quantity = stack.stackSize;
|
||||
@@ -66,7 +66,7 @@ public class TileStorageProxy extends TileMachine implements IStorageProvider, I
|
||||
for (int i = 0; i < inventory.getSizeInventory(); ++i) {
|
||||
ItemStack slot = inventory.getStackInSlot(i);
|
||||
|
||||
if (slot != null && InventoryUtils.compareStackNoQuantity(slot, stack)) {
|
||||
if (slot != null && InventoryUtils.compareStack(slot, stack, flags)) {
|
||||
if (quantity > slot.stackSize) {
|
||||
quantity = slot.stackSize;
|
||||
}
|
||||
@@ -77,11 +77,15 @@ public class TileStorageProxy extends TileMachine implements IStorageProvider, I
|
||||
inventory.setInventorySlotContents(i, null);
|
||||
}
|
||||
|
||||
return quantity;
|
||||
ItemStack newItem = slot.copy();
|
||||
|
||||
newItem.stackSize = quantity;
|
||||
|
||||
return newItem;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user