Exemple #1
0
        /// <summary>
        /// This function stores as many items of an ItemStack as possible in a matching slot and returns the quantity of
        /// left over items.
        /// </summary>
        private int StorePartialItemStack(ItemStack par1ItemStack)
        {
            int i = par1ItemStack.ItemID;
            int j = par1ItemStack.StackSize;

            if (par1ItemStack.GetMaxStackSize() == 1)
            {
                int k = GetFirstEmptyStack();

                if (k < 0)
                {
                    return(j);
                }

                if (MainInventory[k] == null)
                {
                    MainInventory[k] = ItemStack.CopyItemStack(par1ItemStack);
                }

                return(0);
            }

            int l = StoreItemStack(par1ItemStack);

            if (l < 0)
            {
                l = GetFirstEmptyStack();
            }

            if (l < 0)
            {
                return(j);
            }

            if (MainInventory[l] == null)
            {
                MainInventory[l] = new ItemStack(i, 0, par1ItemStack.GetItemDamage());

                if (par1ItemStack.HasTagCompound())
                {
                    MainInventory[l].SetTagCompound((NBTTagCompound)par1ItemStack.GetTagCompound().Copy());
                }
            }

            int i1 = j;

            if (i1 > MainInventory[l].GetMaxStackSize() - MainInventory[l].StackSize)
            {
                i1 = MainInventory[l].GetMaxStackSize() - MainInventory[l].StackSize;
            }

            if (i1 > GetInventoryStackLimit() - MainInventory[l].StackSize)
            {
                i1 = GetInventoryStackLimit() - MainInventory[l].StackSize;
            }

            if (i1 == 0)
            {
                return(j);
            }
            else
            {
                j -= i1;
                MainInventory[l].StackSize     += i1;
                MainInventory[l].AnimationsToGo = 5;
                return(j);
            }
        }