/********* ** Private methods *********/ /// <summary>Add an item to the container from the player inventory.</summary> /// <param name="item">The item taken.</param> /// <param name="player">The player taking the item.</param> /// <remarks>This implementation replicates <see cref="Chest.grabItemFromInventory"/> without the slot limit (instead of using <c>Farm::shipItem</c> which does some weird things that don't work well with a full chest UI).</remarks> private void GrabItemFromInventoryImpl(Item item, SFarmer player) { // normalise if (item.Stack == 0) { item.Stack = 1; } // add to shipping bin Item remaining = this.FakeChest.addItem(item); if (remaining != null) { this.FakeChest.items.Add(remaining); } // add item player.removeItemFromInventory(item); this.FakeChest.clearNulls(); // reopen menu IClickableMenu menu = Game1.activeClickableMenu; int snappedComponentID = menu.currentlySnappedComponent?.myID ?? -1; Game1.activeClickableMenu = menu = this.OpenMenu(); if (snappedComponentID != -1) { menu.currentlySnappedComponent = menu.getComponentWithID(snappedComponentID); menu.snapCursorToCurrentSnappedComponent(); } }
/********* ** Private methods *********/ /// <summary>Add an item to the container from the player inventory.</summary> /// <param name="item">The item taken.</param> /// <param name="player">The player taking the item.</param> /// <remarks>This implementation replicates <see cref="StardewValley.Objects.Chest.grabItemFromInventory"/> without the slot limit (instead of using <c>Farm::shipItem</c> which does some weird things that don't work well with a full chest UI).</remarks> private void GrabItemFromInventoryImpl(Item item, SFarmer player) { // normalise if (item.Stack == 0) { item.Stack = 1; } // add to shipping bin this.ShippingBin.Filter(p => p != null); foreach (Item slot in this.Inventory) { if (!slot.canStackWith(item)) { continue; } item.Stack = slot.addToStack(item); if (item.Stack <= 0) { break; } } if (item.Stack > 0) { this.ShippingBin.Add(item); } // remove from player inventory player.removeItemFromInventory(item); // reopen menu IClickableMenu menu = Game1.activeClickableMenu; int snappedComponentID = menu.currentlySnappedComponent?.myID ?? -1; Game1.activeClickableMenu = menu = this.OpenMenu(); if (snappedComponentID != -1) { menu.currentlySnappedComponent = menu.getComponentWithID(snappedComponentID); menu.snapCursorToCurrentSnappedComponent(); } }