public virtual ItemStack SlotClick(int par1, int par2, bool par3, EntityPlayer par4EntityPlayer)
        {
            ItemStack itemstack = null;

            if (par2 > 1)
            {
                return(null);
            }

            if (par2 == 0 || par2 == 1)
            {
                InventoryPlayer inventoryplayer = par4EntityPlayer.Inventory;

                if (par1 == -999)
                {
                    if (inventoryplayer.GetItemStack() != null && par1 == -999)
                    {
                        if (par2 == 0)
                        {
                            par4EntityPlayer.DropPlayerItem(inventoryplayer.GetItemStack());
                            inventoryplayer.SetItemStack(null);
                        }

                        if (par2 == 1)
                        {
                            par4EntityPlayer.DropPlayerItem(inventoryplayer.GetItemStack().SplitStack(1));

                            if (inventoryplayer.GetItemStack().StackSize == 0)
                            {
                                inventoryplayer.SetItemStack(null);
                            }
                        }
                    }
                }
                else if (par3)
                {
                    ItemStack itemstack1 = TransferStackInSlot(par1);

                    if (itemstack1 != null)
                    {
                        int i = itemstack1.ItemID;
                        itemstack = itemstack1.Copy();
                        Slot slot1 = InventorySlots[par1];

                        if (slot1 != null && slot1.GetStack() != null && slot1.GetStack().ItemID == i)
                        {
                            RetrySlotClick(par1, par2, par3, par4EntityPlayer);
                        }
                    }
                }
                else
                {
                    if (par1 < 0)
                    {
                        return(null);
                    }

                    Slot slot = InventorySlots[par1];

                    if (slot != null)
                    {
                        slot.OnSlotChanged();
                        ItemStack itemstack2 = slot.GetStack();
                        ItemStack itemstack4 = inventoryplayer.GetItemStack();

                        if (itemstack2 != null)
                        {
                            itemstack = itemstack2.Copy();
                        }

                        if (itemstack2 == null)
                        {
                            if (itemstack4 != null && slot.IsItemValid(itemstack4))
                            {
                                int j = par2 != 0 ? 1 : itemstack4.StackSize;

                                if (j > slot.GetSlotStackLimit())
                                {
                                    j = slot.GetSlotStackLimit();
                                }

                                slot.PutStack(itemstack4.SplitStack(j));

                                if (itemstack4.StackSize == 0)
                                {
                                    inventoryplayer.SetItemStack(null);
                                }
                            }
                        }
                        else if (itemstack4 == null)
                        {
                            int       k          = par2 != 0 ? (itemstack2.StackSize + 1) / 2 : itemstack2.StackSize;
                            ItemStack itemstack6 = slot.DecrStackSize(k);
                            inventoryplayer.SetItemStack(itemstack6);

                            if (itemstack2.StackSize == 0)
                            {
                                slot.PutStack(null);
                            }

                            slot.OnPickupFromSlot(inventoryplayer.GetItemStack());
                        }
                        else if (slot.IsItemValid(itemstack4))
                        {
                            if (itemstack2.ItemID != itemstack4.ItemID || itemstack2.GetHasSubtypes() && itemstack2.GetItemDamage() != itemstack4.GetItemDamage() || !ItemStack.Func_46154_a(itemstack2, itemstack4))
                            {
                                if (itemstack4.StackSize <= slot.GetSlotStackLimit())
                                {
                                    ItemStack itemstack5 = itemstack2;
                                    slot.PutStack(itemstack4);
                                    inventoryplayer.SetItemStack(itemstack5);
                                }
                            }
                            else
                            {
                                int l = par2 != 0 ? 1 : itemstack4.StackSize;

                                if (l > slot.GetSlotStackLimit() - itemstack2.StackSize)
                                {
                                    l = slot.GetSlotStackLimit() - itemstack2.StackSize;
                                }

                                if (l > itemstack4.GetMaxStackSize() - itemstack2.StackSize)
                                {
                                    l = itemstack4.GetMaxStackSize() - itemstack2.StackSize;
                                }

                                itemstack4.SplitStack(l);

                                if (itemstack4.StackSize == 0)
                                {
                                    inventoryplayer.SetItemStack(null);
                                }

                                itemstack2.StackSize += l;
                            }
                        }
                        else if (itemstack2.ItemID == itemstack4.ItemID && itemstack4.GetMaxStackSize() > 1 && (!itemstack2.GetHasSubtypes() || itemstack2.GetItemDamage() == itemstack4.GetItemDamage()) && ItemStack.Func_46154_a(itemstack2, itemstack4))
                        {
                            int i1 = itemstack2.StackSize;

                            if (i1 > 0 && i1 + itemstack4.StackSize <= itemstack4.GetMaxStackSize())
                            {
                                itemstack4.StackSize += i1;
                                ItemStack itemstack3 = slot.DecrStackSize(i1);

                                if (itemstack3.StackSize == 0)
                                {
                                    slot.PutStack(null);
                                }

                                slot.OnPickupFromSlot(inventoryplayer.GetItemStack());
                            }
                        }
                    }
                }
            }

            return(itemstack);
        }