* @return
*/
public static ItemStack[] removeItems(IInventory inv, int numItems) {
if (inv instanceof ISpecialInventory)
return ((ISpecialInventory) inv).extractItem(true, ForgeDirection.UNKNOWN, numItems);
PlainInventory output = new PlainInventory(27, "temp");
for (int i = 0; i < inv.getSizeInventory(); i++) {
if (numItems <= 0)
break;
ItemStack slot = inv.getStackInSlot(i);
if (slot == null)
continue;
ItemStack removed = inv.decrStackSize(i, numItems);
numItems -= removed.stackSize;
ItemStack remainder = moveItemStack(removed, output);
if (remainder != null) {
moveItemStack(remainder, inv);
numItems += remainder.stackSize;
break;
}
}
List<ItemStack> list = new LinkedList<ItemStack>();
for (ItemStack stack : output.getContents()) {
if (stack != null)
list.add(stack);
}
return list.toArray(new ItemStack[0]);
}