mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-25 14:24:35 +00:00
Completely refactor inventory management to allow IItemHandler support. Likely many bugs to fix, but it's a start
This commit is contained in:
1 parent
840de86d11
commit
b97b7184c1
15 files changed
+813
-525
No files matched your search
@@ -2,27 +2,34 @@ package mekanism.common.content.transporter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import mekanism.common.util.InventoryUtils;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
public final class InvStack
|
||||
{
|
||||
public IInventory inventory;
|
||||
public TileEntity tileEntity;
|
||||
public ArrayList<ItemStack> itemStacks;
|
||||
public ArrayList<Integer> slotIDs;
|
||||
public EnumFacing side;
|
||||
|
||||
public InvStack(IInventory inv)
|
||||
public InvStack(TileEntity inv, EnumFacing facing)
|
||||
{
|
||||
inventory = inv;
|
||||
tileEntity = inv;
|
||||
itemStacks = new ArrayList<ItemStack>();
|
||||
slotIDs = new ArrayList<Integer>();
|
||||
side = facing;
|
||||
}
|
||||
|
||||
public InvStack(IInventory inv, int id, ItemStack stack)
|
||||
public InvStack(TileEntity inv, int id, ItemStack stack, EnumFacing facing)
|
||||
{
|
||||
inventory = inv;
|
||||
tileEntity = inv;
|
||||
itemStacks = new ArrayList<ItemStack>();
|
||||
slotIDs = new ArrayList<Integer>();
|
||||
side = facing;
|
||||
|
||||
appendStack(id, stack);
|
||||
}
|
||||
@@ -55,25 +62,46 @@ public final class InvStack
|
||||
|
||||
public void use(int amount)
|
||||
{
|
||||
for(int i = 0; i < slotIDs.size(); i++)
|
||||
if(InventoryUtils.isItemHandler(tileEntity, side))
|
||||
{
|
||||
ItemStack stack = itemStacks.get(i);
|
||||
|
||||
if(inventory.getStackInSlot(slotIDs.get(i)).getCount() == stack.getCount() && stack.getCount() <= amount)
|
||||
IItemHandler handler = InventoryUtils.getItemHandler(tileEntity, side);
|
||||
|
||||
for(int i = 0; i < slotIDs.size(); i++)
|
||||
{
|
||||
inventory.setInventorySlotContents(slotIDs.get(i), ItemStack.EMPTY);
|
||||
ItemStack stack = itemStacks.get(i);
|
||||
handler.extractItem(slotIDs.get(i), stack.getCount(), false);
|
||||
amount -= stack.getCount();
|
||||
|
||||
if(amount == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ItemStack ret = stack.copy();
|
||||
ret.setCount(inventory.getStackInSlot(slotIDs.get(i)).getCount() - Math.min(stack.getCount(), amount));
|
||||
inventory.setInventorySlotContents(slotIDs.get(i), ret);
|
||||
amount -= ret.getCount();
|
||||
}
|
||||
|
||||
if(amount == 0)
|
||||
}
|
||||
else if(tileEntity instanceof IInventory)
|
||||
{
|
||||
IInventory inventory = InventoryUtils.checkChestInv((IInventory)tileEntity);
|
||||
|
||||
for(int i = 0; i < slotIDs.size(); i++)
|
||||
{
|
||||
return;
|
||||
ItemStack stack = itemStacks.get(i);
|
||||
|
||||
if(inventory.getStackInSlot(slotIDs.get(i)).getCount() == stack.getCount() && stack.getCount() <= amount)
|
||||
{
|
||||
inventory.setInventorySlotContents(slotIDs.get(i), ItemStack.EMPTY);
|
||||
amount -= stack.getCount();
|
||||
}
|
||||
else {
|
||||
ItemStack ret = stack.copy();
|
||||
ret.setCount(inventory.getStackInSlot(slotIDs.get(i)).getCount() - stack.getCount());
|
||||
inventory.setInventorySlotContents(slotIDs.get(i), ret);
|
||||
amount -= stack.getCount();
|
||||
}
|
||||
|
||||
if(amount == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user