From 0bb73d5183d985a6cfdde6efe3ea02a83253be7b Mon Sep 17 00:00:00 2001 From: Aidan Brady Date: Sun, 4 Aug 2013 21:15:16 -0400 Subject: [PATCH] Just about finished inventory management, onto logistics --- .../battery/TileEntityBattery.java | 60 ++++++++++++++++++- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/src/resonantinduction/battery/TileEntityBattery.java b/src/resonantinduction/battery/TileEntityBattery.java index d8b2686ef..7fe31ed54 100644 --- a/src/resonantinduction/battery/TileEntityBattery.java +++ b/src/resonantinduction/battery/TileEntityBattery.java @@ -82,6 +82,7 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver { super.readFromNBT(nbtTags); + //Main inventory NBTTagList tagList = nbtTags.getTagList("Items"); structure.inventory = new HashSet(); @@ -91,6 +92,21 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver structure.inventory.add(ItemStack.loadItemStackFromNBT(tagCompound)); } + + //Visible inventory + NBTTagList tagList1 = nbtTags.getTagList("VisibleItems"); + structure.visibleInventory = new ItemStack[3]; + + for(int tagCount = 0; tagCount < tagList1.tagCount(); tagCount++) + { + NBTTagCompound tagCompound = (NBTTagCompound)tagList1.tagAt(tagCount); + byte slotID = tagCompound.getByte("Slot"); + + if(slotID >= 0 && slotID < structure.visibleInventory.length) + { + setInventorySlotContents(slotID, ItemStack.loadItemStackFromNBT(tagCompound)); + } + } } @Override @@ -98,6 +114,7 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver { super.writeToNBT(nbtTags); + //Inventory NBTTagList tagList = new NBTTagList(); for(ItemStack itemStack : structure.inventory) @@ -111,6 +128,22 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver } nbtTags.setTag("Items", tagList); + + //Visible inventory + NBTTagList tagList1 = new NBTTagList(); + + for(int slotCount = 0; slotCount < structure.visibleInventory.length; slotCount++) + { + if(getStackInSlot(slotCount) != null) + { + NBTTagCompound tagCompound = new NBTTagCompound(); + tagCompound.setByte("Slot", (byte)slotCount); + getStackInSlot(slotCount).writeToNBT(tagCompound); + tagList1.appendTag(tagCompound); + } + } + + nbtTags.setTag("VisibleItems", tagList1); } public void update() @@ -246,9 +279,32 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver } @Override - public ItemStack decrStackSize(int i, int j) + public ItemStack decrStackSize(int slotID, int amount) { - return null; + if(getStackInSlot(slotID) != null) + { + ItemStack tempStack; + + if(getStackInSlot(slotID).stackSize <= amount) + { + tempStack = getStackInSlot(slotID); + setInventorySlotContents(slotID, null); + return tempStack; + } + else { + tempStack = getStackInSlot(slotID).splitStack(amount); + + if(getStackInSlot(slotID).stackSize == 0) + { + setInventorySlotContents(slotID, null); + } + + return tempStack; + } + } + else { + return null; + } } @Override