Exemple #1
0
 public void CopyTo(WindowArea area)
 {
     for (int i = 0; i < area.Length && i < Length; i++)
     {
         area[i] = this[i];
     }
 }
Exemple #2
0
 protected internal virtual int MoveOrMergeItem(int index, ItemStack item, WindowArea from)
 {
     int emptyIndex = -1;
     var maximumStackSize = Item.GetMaximumStackSize(new ItemDescriptor(item.Id, item.Metadata));
     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 < maximumStackSize)
         {
             // Merging takes precedence over empty slots
             emptyIndex = -1;
             if (from != null)
                 from[index] = ItemStack.EmptyStack;
             if (this[i].Count + item.Count > maximumStackSize)
             {
                 item = new ItemStack(item.Id, (sbyte)(item.Count - (maximumStackSize - this[i].Count)),
                     item.Metadata, item.Nbt);
                 this[i] = new ItemStack(item.Id, (sbyte)maximumStackSize, 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;
 }
Exemple #3
0
 protected internal override int MoveOrMergeItem(int index, ItemStack slot, WindowArea from)
 {
     for (int i = 0; i < Length; i++)
     {
         if (IsValid(slot, i))
         {
             if (this[i].Empty)
             {
                 this[i] = slot;
                 from[index] = ItemStack.EmptyStack;
                 return i;
             }
         }
     }
     return -1;
 }
Exemple #4
0
 protected internal override int MoveOrMergeItem(int index, ItemStack slot, WindowArea from)
 {
     for (int i = 0; i < Length; i++)
     {
         if (IsValid(slot, i))
         {
             if (this[i].Empty)
             {
                 this[i]     = slot;
                 from[index] = ItemStack.EmptyStack;
                 return(i);
             }
         }
     }
     return(-1);
 }
Exemple #5
0
        protected internal virtual int MoveOrMergeItem(int index, ItemStack item, WindowArea from)
        {
            int emptyIndex = -1;
            //var maximumStackSize = Item.GetMaximumStackSize(new ItemDescriptor(item.Id, item.Metadata));
            // TODO
            var maximumStackSize = 64;

            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 < maximumStackSize)
                {
                    // Merging takes precedence over empty slots
                    emptyIndex = -1;
                    if (from != null)
                    {
                        from[index] = ItemStack.EmptyStack;
                    }
                    if (this[i].Count + item.Count > maximumStackSize)
                    {
                        item = new ItemStack(item.Id, (sbyte)(item.Count - (maximumStackSize - this[i].Count)),
                                             item.Metadata, item.Nbt);
                        this[i] = new ItemStack(item.Id, (sbyte)maximumStackSize, 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);
        }
Exemple #6
0
 public void CopyTo(WindowArea area)
 {
     for (int i = 0; i < area.Length && i < Length; i++)
         area[i] = this[i];
 }