make the exporter work
This commit is contained in:
@@ -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