コード例 #1
0
        // Remove Item by Meta
        public int Remove(ItemMeta itemMeta, int amount)
        {
            if (itemMeta == null || amount == 0)
            {
                return(0);
            }
            int minStackSize = 0;

            foreach (ItemStack itemStack in itemStacks)
            {
                if (itemStack.IsEmpty())
                {
                    continue;
                }

                if (!itemMeta.Equals(itemStack.GetItemMeta()))
                {
                    continue;
                }

                if (itemStack.GetAmount() - amount > minStackSize)
                {
                    itemStack.SetAmount(itemStack.GetAmount() - amount);
                    amount = 0;
                    break;
                }
                else
                {
                    amount = Mathf.Abs(itemStack.GetAmount() - amount);
                    itemStack.Clear();
                }
            }
            return(amount);
        }
コード例 #2
0
 // Start
 private void Start()
 {
     // Register Item Metas
     foreach (ItemMeta itemMeta in itemMetas)
     {
         if (!ItemMeta.Register(itemMeta))
         {
             Debug.LogError("Could not register " + itemMeta.Id);
         }
     }
 }
コード例 #3
0
 // Get Item Meta
 public ItemMeta GetItemMeta()
 {
     return(itemMeta ?? (itemMeta = ItemMeta.GetItemMeta(id)));
 }
コード例 #4
0
        // Add Item by Meta
        public int Add(ItemMeta itemMeta, int amount)
        {
            if (itemMeta == null || amount == 0)
            {
                return(0);
            }
            int maxStackSize = itemMeta.GetItemType().MaxStackSize;

            foreach (ItemStack itemStack in itemStacks)
            {
                if (itemStack.IsEmpty())
                {
                    continue;
                }

                if (!itemMeta.Equals(itemStack.GetItemMeta()))
                {
                    continue;
                }

                if (itemStack.GetAmount() == maxStackSize)
                {
                    continue;
                }

                if (itemStack.GetAmount() + amount <= maxStackSize)
                {
                    itemStack.SetAmount(itemStack.GetAmount() + amount);
                    amount = 0;
                    break;
                }
                else
                {
                    amount -= itemStack.GetAmount() + amount - maxStackSize;
                    itemStack.SetAmount(maxStackSize);
                }
            }

            if (amount > 0)
            {
                int firstEmpty = FindEmpty();

                if (firstEmpty != -1 && firstEmpty < itemStacks.Length)
                {
                    ItemStack itemStack = itemStacks[firstEmpty];

                    if (itemStack == null || !itemStack.IsEmpty())
                    {
                        return(amount);
                    }

                    if (amount <= maxStackSize)
                    {
                        itemStack.SetItemStack(itemMeta, amount);
                        amount = 0;
                    }
                    else
                    {
                        amount -= maxStackSize;
                        itemStack.SetItemStack(itemMeta, maxStackSize);
                        Add(itemMeta, amount);
                    }
                }
            }
            return(amount);
        }
コード例 #5
0
 // Add Item by Meta
 public int Add(ItemMeta itemMeta)
 {
     return(Add(itemMeta, 1));
 }
コード例 #6
0
 // Remove Item by Meta
 public int Remove(ItemMeta itemMeta)
 {
     return(Remove(itemMeta, 1));
 }