From b1f2a61e20834551a8a190233e631431a4183370 Mon Sep 17 00:00:00 2001 From: "Aidan C. Brady" Date: Wed, 6 Nov 2013 16:04:34 -0500 Subject: [PATCH] Minor changes, nothing noticeable --- .../TileEntityLogisticalSorter.java | 14 ++--- .../mekanism/common/transporter/InvStack.java | 54 +++++++++++++++++++ .../mekanism/common/transporter/SlotInfo.java | 15 ------ .../common/util/TransporterUtils.java | 10 ++-- 4 files changed, 67 insertions(+), 26 deletions(-) create mode 100644 common/mekanism/common/transporter/InvStack.java delete mode 100644 common/mekanism/common/transporter/SlotInfo.java diff --git a/common/mekanism/common/tileentity/TileEntityLogisticalSorter.java b/common/mekanism/common/tileentity/TileEntityLogisticalSorter.java index 2f2f6630d..06ea39290 100644 --- a/common/mekanism/common/tileentity/TileEntityLogisticalSorter.java +++ b/common/mekanism/common/tileentity/TileEntityLogisticalSorter.java @@ -13,7 +13,7 @@ import mekanism.common.PacketHandler; import mekanism.common.PacketHandler.Transmission; import mekanism.common.block.BlockMachine.MachineType; import mekanism.common.network.PacketTileEntity; -import mekanism.common.transporter.SlotInfo; +import mekanism.common.transporter.InvStack; import mekanism.common.transporter.TransporterFilter; import mekanism.common.util.MekanismUtils; import mekanism.common.util.TransporterUtils; @@ -78,16 +78,16 @@ public class TileEntityLogisticalSorter extends TileEntityElectricBlock implemen IInventory inventory = (IInventory)back; TileEntityLogisticalTransporter transporter = (TileEntityLogisticalTransporter)front; - SlotInfo inInventory = TransporterUtils.takeItem(inventory, ForgeDirection.getOrientation(facing).getOpposite().ordinal()); + InvStack inInventory = TransporterUtils.takeItem(inventory, ForgeDirection.getOrientation(facing).getOpposite().ordinal()); - if(inInventory != null && inInventory.itemStack != null) + if(inInventory != null && inInventory.getStack() != null) { boolean hasFilter = false; EnumColor filterColor = color; for(TransporterFilter filter : filters) { - if(filter.canFilter(inInventory.itemStack)) + if(filter.canFilter(inInventory.getStack())) { filterColor = filter.color; hasFilter = true; @@ -95,13 +95,13 @@ public class TileEntityLogisticalSorter extends TileEntityElectricBlock implemen } } - if((hasFilter || autoEject) && TransporterUtils.insert(this, transporter, inInventory.itemStack, filterColor)) + if((hasFilter || autoEject) && TransporterUtils.insert(this, transporter, inInventory.getStack(), filterColor)) { - inventory.setInventorySlotContents(inInventory.slotID, null); + inInventory.use(); setActive(true); } else { - inventory.setInventorySlotContents(inInventory.slotID, inInventory.itemStack); + inInventory.reset(); } } diff --git a/common/mekanism/common/transporter/InvStack.java b/common/mekanism/common/transporter/InvStack.java new file mode 100644 index 000000000..0f146ff66 --- /dev/null +++ b/common/mekanism/common/transporter/InvStack.java @@ -0,0 +1,54 @@ +package mekanism.common.transporter; + +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; + +public final class InvStack +{ + public IInventory inventory; + public ItemStack[] itemStacks; + public int[] slotIDs; + + public InvStack(IInventory inv, ItemStack[] stacks, int[] ids) + { + inventory = inv; + itemStacks = stacks; + slotIDs = ids; + } + + public ItemStack getStack() + { + int size = 0; + + for(ItemStack stack : itemStacks) + { + size += stack.stackSize; + } + + if(itemStacks[0] != null) + { + ItemStack ret = itemStacks[0].copy(); + ret.stackSize = size; + + return ret; + } + + return null; + } + + public void use() + { + for(int id : slotIDs) + { + inventory.setInventorySlotContents(id, null); + } + } + + public void reset() + { + for(int i = 0; i < slotIDs.length; i++) + { + inventory.setInventorySlotContents(slotIDs[i], itemStacks[i]); + } + } +} diff --git a/common/mekanism/common/transporter/SlotInfo.java b/common/mekanism/common/transporter/SlotInfo.java deleted file mode 100644 index 661fa1f81..000000000 --- a/common/mekanism/common/transporter/SlotInfo.java +++ /dev/null @@ -1,15 +0,0 @@ -package mekanism.common.transporter; - -import net.minecraft.item.ItemStack; - -public final class SlotInfo -{ - public ItemStack itemStack; - public int slotID; - - public SlotInfo(ItemStack stack, int i) - { - itemStack = stack; - slotID = i; - } -} diff --git a/common/mekanism/common/util/TransporterUtils.java b/common/mekanism/common/util/TransporterUtils.java index f4e774e5a..6dcf63eca 100644 --- a/common/mekanism/common/util/TransporterUtils.java +++ b/common/mekanism/common/util/TransporterUtils.java @@ -8,7 +8,7 @@ import mekanism.api.IConfigurable; import mekanism.api.Object3D; import mekanism.api.transmitters.ITransmitter; import mekanism.common.tileentity.TileEntityLogisticalTransporter; -import mekanism.common.transporter.SlotInfo; +import mekanism.common.transporter.InvStack; import mekanism.common.transporter.TransporterStack; import net.minecraft.entity.item.EntityItem; import net.minecraft.inventory.IInventory; @@ -385,10 +385,12 @@ public final class TransporterUtils return toInsert; } - public static SlotInfo takeItem(IInventory inventory, int side) + public static InvStack takeItem(IInventory inventory, int side) { if(!(inventory instanceof ISidedInventory)) { + inventory = checkChestInv(inventory); + for(int i = inventory.getSizeInventory() - 1; i >= 0; i--) { if(inventory.getStackInSlot(i) != null) @@ -396,7 +398,7 @@ public final class TransporterUtils ItemStack toSend = inventory.getStackInSlot(i).copy(); inventory.setInventorySlotContents(i, null); - return new SlotInfo(toSend, i); + return new InvStack(inventory, new ItemStack[] {toSend}, new int[] {i}); } } } @@ -418,7 +420,7 @@ public final class TransporterUtils { sidedInventory.setInventorySlotContents(slotID, null); - return new SlotInfo(toSend, slotID); + return new InvStack(inventory, new ItemStack[] {toSend}, new int[] {slotID}); } } }