Ejemplo n.º 1
0
        public void ExchangeItemStacks(IItemStackSlot @from, IItemStackSlot @to)
        {
            if (!to.CanFit(from.ItemStack))
            {
                return;
            }

            if (from.Controller != to.Controller)
            {
                CrossControllerExchange(from, to);
            }
            else if (from.Inventory != to.Inventory)
            {
                CrossInventoryExchange(from, to);
            }
            else if (from.ItemStack.Item == to.ItemStack.Item)
            {
                to.Inventory.CombineStacks(from.InventoryIndex, to.InventoryIndex);
            }
            else
            {
                to.Inventory.SwapSlots(from.InventoryIndex, to.InventoryIndex, out var _, out var _);
            }

            from.UpdateUi();
            to.UpdateUi();
        }
Ejemplo n.º 2
0
        public void CrossInventoryExchange(IItemStackSlot @from, IItemStackSlot to)
        {
            IInventory fromInventory = from.Inventory;
            IInventory toInventory   = to.Inventory;

            ItemStack fromStack = fromInventory.RemoveStackAtSlot(from.InventoryIndex);

            if (to.ItemStack.IsEmpty)
            {
                toInventory.AddStackAtSlot(fromStack, to.InventoryIndex);
            }
            else
            {
                ItemStack toStack = toInventory.RemoveStackAtSlot(to.InventoryIndex);

                fromInventory.AddItemStacks(new[] { toInventory.AddStackAtSlot(fromStack, to.InventoryIndex) });
                toInventory.AddItemStacks(new[] { fromInventory.AddStackAtSlot(toStack, from.InventoryIndex) });
            }
        }
Ejemplo n.º 3
0
 public void ClearSlot(IItemStackSlot slot)
 {
     slot.Inventory.RemoveStackAtSlot(slot.InventoryIndex);
     slot.UpdateUi();
 }
Ejemplo n.º 4
0
 public void SplitSlot(IItemStackSlot slot)
 {
     slot.Inventory.SplitStack(slot.InventoryIndex, slot.ItemStack.Amount / 2);
     UpdateSlots();
 }
Ejemplo n.º 5
0
 public void CrossControllerExchange(IItemStackSlot @from, IItemStackSlot @to) => CrossInventoryExchange(@from, to);