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 x;
|
||||||
private int y;
|
private int y;
|
||||||
private int z;
|
private int z;
|
||||||
// @TODO: this won't work when sorting
|
// @TODO: This won't work when sorting
|
||||||
private int slot;
|
private int slot;
|
||||||
private boolean half;
|
private boolean half;
|
||||||
private boolean shift;
|
private boolean shift;
|
||||||
@@ -67,18 +67,21 @@ public class MessageStoragePull implements IMessage, IMessageHandler<MessageStor
|
|||||||
|
|
||||||
if (message.half && item.getQuantity() > 1) {
|
if (message.half && item.getQuantity() > 1) {
|
||||||
quantity = item.getQuantity() / 2;
|
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) {
|
if (message.shift) {
|
||||||
// @TODO: This doesn't work
|
if (!player.inventory.addItemStackToInventory(took.copy())) {
|
||||||
if (!player.inventory.addItemStackToInventory(stack.copy())) {
|
controller.push(took);
|
||||||
controller.push(stack);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
player.inventory.setItemStack(stack);
|
player.inventory.setItemStack(took);
|
||||||
player.updateHeldItem();
|
player.updateHeldItem();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -42,7 +42,7 @@ public class CellStorage implements IStorage {
|
|||||||
|
|
||||||
StorageItem item = createItemFromNBT(tag);
|
StorageItem item = createItemFromNBT(tag);
|
||||||
|
|
||||||
if (item.getMeta().equals(stack)) {
|
if (item.compareNoQuantity(stack)) {
|
||||||
tag.setInteger(NBT_ITEM_QUANTITY, item.getQuantity() + stack.stackSize);
|
tag.setInteger(NBT_ITEM_QUANTITY, item.getQuantity() + stack.stackSize);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -63,7 +63,7 @@ public class CellStorage implements IStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int take(ItemStack stack) {
|
public ItemStack take(ItemStack stack, int flags) {
|
||||||
int quantity = stack.stackSize;
|
int quantity = stack.stackSize;
|
||||||
|
|
||||||
NBTTagList list = (NBTTagList) cell.stackTagCompound.getTag(NBT_ITEMS);
|
NBTTagList list = (NBTTagList) cell.stackTagCompound.getTag(NBT_ITEMS);
|
||||||
@@ -73,7 +73,7 @@ public class CellStorage implements IStorage {
|
|||||||
|
|
||||||
StorageItem item = createItemFromNBT(tag);
|
StorageItem item = createItemFromNBT(tag);
|
||||||
|
|
||||||
if (item.getMeta().equals(stack)) {
|
if (item.compare(stack, flags)) {
|
||||||
if (quantity > item.getQuantity()) {
|
if (quantity > item.getQuantity()) {
|
||||||
quantity = item.getQuantity();
|
quantity = item.getQuantity();
|
||||||
}
|
}
|
||||||
@@ -86,11 +86,15 @@ public class CellStorage implements IStorage {
|
|||||||
|
|
||||||
cell.stackTagCompound.setInteger(NBT_STORED, ItemStorageCell.getStored(cell) - quantity);
|
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
|
@Override
|
||||||
|
@@ -8,7 +8,7 @@ public interface IStorage {
|
|||||||
|
|
||||||
public void push(ItemStack stack);
|
public void push(ItemStack stack);
|
||||||
|
|
||||||
public int take(ItemStack stack);
|
public ItemStack take(ItemStack stack, int flags);
|
||||||
|
|
||||||
public boolean canPush(ItemStack stack);
|
public boolean canPush(ItemStack stack);
|
||||||
}
|
}
|
||||||
|
@@ -3,27 +3,27 @@ package storagecraft.storage;
|
|||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import storagecraft.util.InventoryUtils;
|
||||||
|
|
||||||
public class StorageItem {
|
public class StorageItem {
|
||||||
private StorageItemMeta meta;
|
private Item type;
|
||||||
private int quantity;
|
private int quantity;
|
||||||
|
private int damage;
|
||||||
public StorageItem(StorageItemMeta meta, int quantity) {
|
private NBTTagCompound tag;
|
||||||
this.meta = meta;
|
|
||||||
this.quantity = quantity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public StorageItem(Item type, int quantity, int damage, 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.quantity = quantity;
|
||||||
|
this.damage = damage;
|
||||||
|
this.tag = tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StorageItem(ItemStack stack) {
|
public StorageItem(ItemStack stack) {
|
||||||
this(stack.getItem(), stack.stackSize, stack.getItemDamage(), stack.stackTagCompound);
|
this(stack.getItem(), stack.stackSize, stack.getItemDamage(), stack.stackTagCompound);
|
||||||
}
|
}
|
||||||
|
|
||||||
public StorageItemMeta getMeta() {
|
public Item getType() {
|
||||||
return meta;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getQuantity() {
|
public int getQuantity() {
|
||||||
@@ -34,23 +34,87 @@ public class StorageItem {
|
|||||||
this.quantity = quantity;
|
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() {
|
public StorageItem copy() {
|
||||||
return copy(quantity);
|
return copy(quantity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public StorageItem copy(int newQuantity) {
|
public StorageItem copy(int newQuantity) {
|
||||||
return new StorageItem(meta, newQuantity);
|
return new StorageItem(type, newQuantity, damage, tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack toItemStack() {
|
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;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean equals(StorageItem other) {
|
public boolean compare(StorageItem other, int flags) {
|
||||||
return other.getQuantity() == quantity && other.getMeta().equals(meta);
|
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.IStorage;
|
||||||
import storagecraft.storage.IStorageProvider;
|
import storagecraft.storage.IStorageProvider;
|
||||||
import storagecraft.storage.StorageItem;
|
import storagecraft.storage.StorageItem;
|
||||||
|
import storagecraft.util.InventoryUtils;
|
||||||
|
|
||||||
public class TileController extends TileBase implements IEnergyReceiver, INetworkTile {
|
public class TileController extends TileBase implements IEnergyReceiver, INetworkTile {
|
||||||
private List<StorageItem> items = new ArrayList<StorageItem>();
|
private List<StorageItem> items = new ArrayList<StorageItem>();
|
||||||
@@ -141,7 +142,7 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
|||||||
|
|
||||||
StorageItem other = items.get(j);
|
StorageItem other = items.get(j);
|
||||||
|
|
||||||
if (item.getMeta().equals(other.getMeta())) {
|
if (item.compareNoQuantity(other)) {
|
||||||
item.setQuantity(item.getQuantity() + other.getQuantity());
|
item.setQuantity(item.getQuantity() + other.getQuantity());
|
||||||
|
|
||||||
markedIndexes.add(j);
|
markedIndexes.add(j);
|
||||||
@@ -181,23 +182,35 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack take(ItemStack stack) {
|
public ItemStack take(ItemStack stack) {
|
||||||
int needed = stack.stackSize;
|
return take(stack, InventoryUtils.COMPARE_DAMAGE | InventoryUtils.COMPARE_NBT);
|
||||||
int took = 0;
|
}
|
||||||
|
|
||||||
|
public ItemStack take(ItemStack stack, int flags) {
|
||||||
|
int requested = stack.stackSize;
|
||||||
|
int receiving = 0;
|
||||||
|
|
||||||
|
ItemStack newStack = null;
|
||||||
|
|
||||||
for (IStorage storage : storages) {
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
syncItems();
|
syncItems();
|
||||||
|
|
||||||
ItemStack newStack = stack.copy();
|
|
||||||
|
|
||||||
newStack.stackSize = took;
|
|
||||||
|
|
||||||
return newStack;
|
return newStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,13 +283,13 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
|||||||
buf.writeInt(items.size());
|
buf.writeInt(items.size());
|
||||||
|
|
||||||
for (StorageItem item : items) {
|
for (StorageItem item : items) {
|
||||||
buf.writeInt(Item.getIdFromItem(item.getMeta().getType()));
|
buf.writeInt(Item.getIdFromItem(item.getType()));
|
||||||
buf.writeInt(item.getQuantity());
|
buf.writeInt(item.getQuantity());
|
||||||
buf.writeInt(item.getMeta().getDamage());
|
buf.writeInt(item.getDamage());
|
||||||
buf.writeBoolean(item.getMeta().getTag() != null);
|
buf.writeBoolean(item.getTag() != null);
|
||||||
|
|
||||||
if (item.getMeta().getTag() != null) {
|
if (item.getTag() != null) {
|
||||||
ByteBufUtils.writeTag(buf, item.getMeta().getTag());
|
ByteBufUtils.writeTag(buf, item.getTag());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -29,7 +29,25 @@ public class TileExporter extends TileMachine implements IInventory {
|
|||||||
IInventory connectedInventory = (IInventory) tile;
|
IInventory connectedInventory = (IInventory) tile;
|
||||||
|
|
||||||
if (ticks % 5 == 0) {
|
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
|
@Override
|
||||||
public int take(ItemStack stack) {
|
public ItemStack take(ItemStack stack, int flags) {
|
||||||
IInventory inventory = getInventory();
|
IInventory inventory = getInventory();
|
||||||
|
|
||||||
if (inventory == null) {
|
if (inventory == null) {
|
||||||
return 0;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
int quantity = stack.stackSize;
|
int quantity = stack.stackSize;
|
||||||
@@ -66,7 +66,7 @@ public class TileStorageProxy extends TileMachine implements IStorageProvider, I
|
|||||||
for (int i = 0; i < inventory.getSizeInventory(); ++i) {
|
for (int i = 0; i < inventory.getSizeInventory(); ++i) {
|
||||||
ItemStack slot = inventory.getStackInSlot(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) {
|
if (quantity > slot.stackSize) {
|
||||||
quantity = slot.stackSize;
|
quantity = slot.stackSize;
|
||||||
}
|
}
|
||||||
@@ -77,11 +77,15 @@ public class TileStorageProxy extends TileMachine implements IStorageProvider, I
|
|||||||
inventory.setInventorySlotContents(i, null);
|
inventory.setInventorySlotContents(i, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
return quantity;
|
ItemStack newItem = slot.copy();
|
||||||
|
|
||||||
|
newItem.stackSize = quantity;
|
||||||
|
|
||||||
|
return newItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user