package net.teamio.taam.gui;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.SlotItemHandler;

public class ContainerConveyorSmallInventory extends Container {
	protected final IItemHandler tileEntity;

	public ContainerConveyorSmallInventory(InventoryPlayer inventoryPlayer, ICapabilityProvider te, EnumFacing side) {
		this(inventoryPlayer, te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side));
	}

	public ContainerConveyorSmallInventory(InventoryPlayer inventoryPlayer, IItemHandler te) {
		tileEntity = te;

		for (int i = 0; i < te.getSlots(); i++) {
			addSlotToContainer(new SlotItemHandler(te, i, 44 + i * 18, 20));
		}

		bindPlayerInventory(inventoryPlayer);
	}

	@Override
	public boolean canInteractWith(EntityPlayer player) {
		return true;
	}

	protected void bindPlayerInventory(InventoryPlayer inventoryPlayer) {
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 9; j++) {
				addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, /*84*/51 + i * 18));
			}
		}

		for (int i = 0; i < 9; i++) {
			addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 109));
		}
	}

	@Override
	public ItemStack transferStackInSlot(EntityPlayer player, int slotID) {
		ItemStack stack = null;
		Slot slot = inventorySlots.get(slotID);

		// null checks and checks if the item can be stacked (maxStackSize > 1)
		if (slot != null && slot.getHasStack()) {
			ItemStack stackInSlot = slot.getStack();
			if (stackInSlot != null) {
				stack = stackInSlot.copy();

				// merges the item into player inventory since its in the tileEntity
				if (slotID < tileEntity.getSlots()) {
					if (!mergeItemStack(stackInSlot, tileEntity.getSlots(), inventorySlots.size(), true)) {
						return null;
					}
				}
				// merge into tileEntity inventory, since it is in player's inventory
				else if (!mergeItemStack(stackInSlot, 0, tileEntity.getSlots(), false)) {
					return null;
				}
			}

			if (stackInSlot == null || stackInSlot.getCount() == 0) {
				slot.putStack(null);
			} else {
				slot.onSlotChanged();
			}
		}
		return stack;
	}
}

@@ -494,16 +494,60 @@
 Handler;
+%0Aimport net.teamio.taam.util.InventoryUtils;
 %0A%0Apublic
@@ -1679,20 +1679,31 @@
 stack = 
-null
+ItemStack.EMPTY
 ;%0A%09%09Slot
@@ -1903,24 +1903,48 @@
 ck();%0A%09%09%09if 
+(!InventoryUtils.isEmpty
 (stackInSlot
@@ -1943,24 +1943,17 @@
 ckInSlot
- != null
+)
 ) %7B%0A%09%09%09%09
@@ -2198,28 +2198,39 @@
 %09%09%09%09%09return 
-null
+ItemStack.EMPTY
 ;%0A%09%09%09%09%09%7D%0A%09%09%09
@@ -2396,20 +2396,31 @@
 %09return 
-null
+ItemStack.EMPTY
 ;%0A%09%09%09%09%7D%0A
@@ -2436,58 +2436,43 @@
 if (
-stackInSlot == null %7C%7C stackInSlot.getCount() == 0
+InventoryUtils.isEmpty(stackInSlot)
 ) %7B%0A
@@ -2489,20 +2489,31 @@
 utStack(
-null
+ItemStack.EMPTY
 );%0A%09%09%09%7D 

Fix null stacks when shift-clicking in conveyor-related inventories