コード例 #1
0
ファイル: WindowArea.cs プロジェクト: cpancake/Craft.Net
 protected internal virtual int MoveOrMergeItem(int index, ItemStack item, WindowArea from)
 {
     int emptyIndex = -1;
     for (int i = 0; i < Length; i++)
     {
         if (this[i].Empty && emptyIndex == -1)
             emptyIndex = i;
         else if (this[i].Id == item.Id &&
             this[i].Metadata == item.Metadata &&
             this[i].Count < item.AsItem().MaximumStack)
         {
             // Merging takes precedence over empty slots
             emptyIndex = -1;
             if (from != null)
                 from[index] = ItemStack.EmptyStack;
             if (this[i].Count + item.Count > item.AsItem().MaximumStack)
             {
                 item = new ItemStack(item.Id, (sbyte)(item.Count - (item.AsItem().MaximumStack - this[i].Count)),
                     item.Metadata, item.Nbt);
                 this[i] = new ItemStack(item.Id, (sbyte)item.AsItem().MaximumStack, item.Metadata, item.Nbt);
                 continue;
             }
             this[i] = new ItemStack(item.Id, (sbyte)(this[i].Count + item.Count), item.Metadata);
             return i;
         }
     }
     if (emptyIndex != -1)
     {
         if (from != null)
             from[index] = ItemStack.EmptyStack;
         this[emptyIndex] = item;
     }
     return emptyIndex;
 }
コード例 #2
0
ファイル: WindowArea.cs プロジェクト: seaboy1234/Craft.Net
 public void CopyTo(WindowArea area)
 {
     for (int i = 0; i < area.Length && i < Length; i++)
     {
         area[i] = this[i];
     }
 }
コード例 #3
0
ファイル: WindowArea.cs プロジェクト: Imperceptus/Craft.Net
 protected internal virtual int MoveOrMergeItem(int index, Slot slot, WindowArea from)
 {
     int emptyIndex = -1;
     for (int i = 0; i < Length; i++)
     {
         if (this[i].Empty && emptyIndex == -1)
             emptyIndex = i;
         else if (this[i].Id == slot.Id &&
                  this[i].Metadata == slot.Metadata &&
                  this[i].Count < slot.Item.MaximumStack)
         {
             // Merging takes precedence over empty slots
             emptyIndex = -1;
             if (from != null)
                 from[index] = new Slot();
             if (this[i].Count + slot.Count > slot.Item.MaximumStack)
             {
                 slot.Count -= (byte)(slot.Item.MaximumStack - this[i].Count);
                 this[i].Count = slot.Item.MaximumStack;
                 continue;
             }
             this[i] = new Slot(slot.Id, (byte)(this[i].Count + slot.Count));
             return i;
         }
     }
     if (emptyIndex != -1)
     {
         if (from != null)
             from[index] = new Slot();
         this[emptyIndex] = slot;
     }
     return emptyIndex;
 }
コード例 #4
0
ファイル: WindowArea.cs プロジェクト: seaboy1234/Craft.Net
        protected internal virtual int MoveOrMergeItem(int index, ItemStack item, WindowArea from)
        {
            int emptyIndex = -1;

            for (int i = 0; i < Length; i++)
            {
                if (this[i].Empty && emptyIndex == -1)
                {
                    emptyIndex = i;
                }
                else if (this[i].Id == item.Id &&
                         this[i].Metadata == item.Metadata &&
                         this[i].Count < item.AsItem().MaximumStack)
                {
                    // Merging takes precedence over empty slots
                    emptyIndex = -1;
                    if (from != null)
                    {
                        from[index] = ItemStack.EmptyStack;
                    }
                    if (this[i].Count + item.Count > item.AsItem().MaximumStack)
                    {
                        item = new ItemStack(item.Id, (sbyte)(item.Count - (item.AsItem().MaximumStack - this[i].Count)),
                                             item.Metadata, item.Nbt);
                        this[i] = new ItemStack(item.Id, (sbyte)item.AsItem().MaximumStack, item.Metadata, item.Nbt);
                        continue;
                    }
                    this[i] = new ItemStack(item.Id, (sbyte)(this[i].Count + item.Count), item.Metadata);
                    return(i);
                }
            }
            if (emptyIndex != -1)
            {
                if (from != null)
                {
                    from[index] = ItemStack.EmptyStack;
                }
                this[emptyIndex] = item;
            }
            return(emptyIndex);
        }
コード例 #5
0
ファイル: WindowArea.cs プロジェクト: cpancake/Craft.Net
 public void CopyTo(WindowArea area)
 {
     for (int i = 0; i < area.Length && i < Length; i++)
         area[i] = this[i];
 }