Exemplo n.º 1
0
        /// <summary>
        /// Callback for when the crafting gui is closed.
        /// </summary>
        public virtual void OnCraftGuiClosed(EntityPlayer par1EntityPlayer)
        {
            InventoryPlayer inventoryplayer = par1EntityPlayer.Inventory;

            if (inventoryplayer.GetItemStack() != null)
            {
                par1EntityPlayer.DropPlayerItem(inventoryplayer.GetItemStack());
                inventoryplayer.SetItemStack(null);
            }
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        protected override void HandleMouseClick(Slot par1Slot, int par2, int par3, bool par4)
        {
            if (par1Slot != null)
            {
                if (par1Slot.Inventory == Inventory)
                {
                    InventoryPlayer inventoryplayer = Mc.ThePlayer.Inventory;
                    ItemStack       itemstack1      = inventoryplayer.GetItemStack();
                    ItemStack       itemstack4      = par1Slot.GetStack();

                    if (itemstack1 != null && itemstack4 != null && itemstack1.ItemID == itemstack4.ItemID)
                    {
                        if (par3 == 0)
                        {
                            if (par4)
                            {
                                itemstack1.StackSize = itemstack1.GetMaxStackSize();
                            }
                            else if (itemstack1.StackSize < itemstack1.GetMaxStackSize())
                            {
                                itemstack1.StackSize++;
                            }
                        }
                        else if (itemstack1.StackSize <= 1)
                        {
                            inventoryplayer.SetItemStack(null);
                        }
                        else
                        {
                            itemstack1.StackSize--;
                        }
                    }
                    else if (itemstack1 != null)
                    {
                        inventoryplayer.SetItemStack(null);
                    }
                    else if (itemstack4 == null)
                    {
                        inventoryplayer.SetItemStack(null);
                    }
                    else if (itemstack1 == null || itemstack1.ItemID != itemstack4.ItemID)
                    {
                        inventoryplayer.SetItemStack(ItemStack.CopyItemStack(itemstack4));
                        ItemStack itemstack2 = inventoryplayer.GetItemStack();

                        if (par4)
                        {
                            itemstack2.StackSize = itemstack2.GetMaxStackSize();
                        }
                    }
                }
                else
                {
                    InventorySlots.SlotClick(par1Slot.SlotNumber, par3, par4, Mc.ThePlayer);
                    ItemStack itemstack = InventorySlots.GetSlot(par1Slot.SlotNumber).GetStack();
                    Mc.PlayerController.SendSlotPacket(itemstack, (par1Slot.SlotNumber - InventorySlots.InventorySlots.Count) + 9 + 36);
                }
            }
            else
            {
                InventoryPlayer inventoryplayer1 = Mc.ThePlayer.Inventory;

                if (inventoryplayer1.GetItemStack() != null)
                {
                    if (par3 == 0)
                    {
                        Mc.ThePlayer.DropPlayerItem(inventoryplayer1.GetItemStack());
                        Mc.PlayerController.Func_35639_a(inventoryplayer1.GetItemStack());
                        inventoryplayer1.SetItemStack(null);
                    }

                    if (par3 == 1)
                    {
                        ItemStack itemstack3 = inventoryplayer1.GetItemStack().SplitStack(1);
                        Mc.ThePlayer.DropPlayerItem(itemstack3);
                        Mc.PlayerController.Func_35639_a(itemstack3);

                        if (inventoryplayer1.GetItemStack().StackSize == 0)
                        {
                            inventoryplayer1.SetItemStack(null);
                        }
                    }
                }
            }
        }