当前位置: 首页>>代码示例>>C#>>正文


C# ItemStack.Clone方法代码示例

本文整理汇总了C#中ItemStack.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# ItemStack.Clone方法的具体用法?C# ItemStack.Clone怎么用?C# ItemStack.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ItemStack的用法示例。


在下文中一共展示了ItemStack.Clone方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FinishPaint

 private static void FinishPaint(RemoteClient client, ItemStack heldItem, bool onePerSlot)
 {
     sbyte maxStack = (sbyte)Item.GetMaximumStackSize(new ItemDescriptor(heldItem.Id, heldItem.Metadata));
     while (heldItem.Count < client.PaintedSlots.Count)
         client.PaintedSlots.RemoveAt(client.PaintedSlots.Count - 1);
     for (int i = 0; i < client.PaintedSlots.Count; i++)
     {
         if (!client.Entity.Inventory[client.PaintedSlots[i]].CanMerge(heldItem))
         {
             client.PaintedSlots.RemoveAt(i);
             i--;
         }
     }
     int itemsPerSlot = heldItem.Count / client.PaintedSlots.Count;
     if (onePerSlot)
         itemsPerSlot = 1;
     var item = (ItemStack)heldItem.Clone();
     item.Count = (sbyte)itemsPerSlot;
     foreach (var slot in client.PaintedSlots)
     {
         if (client.Entity.Inventory[slot].Empty)
         {
             client.Entity.Inventory[slot] = item;
             heldItem.Count -= item.Count;
         }
         else // Merge
         {
             sbyte total = (sbyte)(client.Entity.Inventory[slot].Count + item.Count);
             if (total <= maxStack)
             {
                 var newSlot = (ItemStack)client.Entity.Inventory[slot].Clone();
                 newSlot.Count = total;
                 client.Entity.Inventory[slot] = newSlot;
                 heldItem.Count -= item.Count;
             }
             else
             {
                 heldItem.Count -= (sbyte)(maxStack - client.Entity.Inventory[slot].Count);
                 var newSlot = (ItemStack)client.Entity.Inventory[slot].Clone();
                 newSlot.Count = maxStack;
                 client.Entity.Inventory[slot] = newSlot;
             }
         }
     }
     client.Entity.ItemInMouse = heldItem;
 }
开发者ID:nevercast,项目名称:Craft.Net,代码行数:46,代码来源:InventoryHandler.cs

示例2: HandleClickPacket

 public static void HandleClickPacket(ClickWindowPacket packet, IWindow window, ref ItemStack itemStaging)
 {
     if (packet.SlotIndex >= window.Length || packet.SlotIndex < 0)
         return;
     var existing = window[packet.SlotIndex];
     if (window.ReadOnlySlots.Contains(packet.SlotIndex))
     {
         if (itemStaging.ID == existing.ID || itemStaging.Empty)
         {
             if (itemStaging.Empty)
                 itemStaging = existing;
             else
                 itemStaging.Count += existing.Count;
             window[packet.SlotIndex] = ItemStack.EmptyStack;
         }
         return;
     }
     if (itemStaging.Empty) // Picking up something
     {
         if (packet.Shift)
         {
             window.MoveToAlternateArea(packet.SlotIndex);
         }
         else
         {
             if (packet.RightClick)
             {
                 sbyte mod = (sbyte)(existing.Count % 2);
                 existing.Count /= 2;
                 itemStaging = existing;
                 itemStaging.Count += mod;
                 window[packet.SlotIndex] = existing;
             }
             else
             {
                 itemStaging = window[packet.SlotIndex];
                 window[packet.SlotIndex] = ItemStack.EmptyStack;
             }
         }
     }
     else // Setting something down
     {
         if (existing.Empty) // Replace empty slot
         {
             if (packet.RightClick)
             {
                 var newItem = (ItemStack)itemStaging.Clone();
                 newItem.Count = 1;
                 itemStaging.Count--;
                 window[packet.SlotIndex] = newItem;
             }
             else
             {
                 window[packet.SlotIndex] = itemStaging;
                 itemStaging = ItemStack.EmptyStack;
             }
         }
         else
         {
             if (existing.CanMerge(itemStaging)) // Merge items
             {
                 // TODO: Consider the maximum stack size
                 if (packet.RightClick)
                 {
                     existing.Count++;
                     itemStaging.Count--;
                     window[packet.SlotIndex] = existing;
                 }
                 else
                 {
                     existing.Count += itemStaging.Count;
                     window[packet.SlotIndex] = existing;
                     itemStaging = ItemStack.EmptyStack;
                 }
             }
             else // Swap items
             {
                 window[packet.SlotIndex] = itemStaging;
                 itemStaging = existing;
             }
         }
     }
 }
开发者ID:Zoxive,项目名称:TrueCraft,代码行数:83,代码来源:Window.cs


注:本文中的ItemStack.Clone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。