public int HarvestContents(StardewValley.Farmer player) { int numItemsHarvested = 0; //Harvest items into inventory foreach (var container in _buildingInfo.ReadyToHarvestContainers) { //Get the item stored in the container StardewValley.Item item = null; if (container.name.Equals("Crystalarium")) { item = (StardewValley.Item)container.heldObject.Value.getOne(); } else { item = (StardewValley.Item)container.heldObject.Value; } //Make sure player can collect item and inventory is not already full if (player.couldInventoryAcceptThisItem(item)) { //this.Monitor.Log($" Harvesting item {item.Name} from container {container.Name} and placing in {player.Name}'s inventory."); if (!player.addItemToInventoryBool(item, false)) { //Inventory was full - throw exception so we can show a message Utility.Log($" {player.Name} has run out of inventory space. Stopping harvest."); throw new InventoryFullException(); } numItemsHarvested++; //Remove this item permanently from the container (except Crystalarium). if (container.name.Equals("Crystalarium")) { container.MinutesUntilReady = this.getMinutesForCrystalarium(item.ParentSheetIndex); } else { container.heldObject.Value = (StardewValley.Object)null; } container.readyForHarvest.Value = false; container.showNextIndex.Value = false; } else { //Inventory was full - throw exception so we can show a message Utility.Log($" {player.Name} has run out of inventory space. Stopping harvest."); throw new InventoryFullException(); } } return(numItemsHarvested); }
//Add Item to Player private bool AddToPlayer(SObject @object, SFarmer Player) { if (this.AddItemsToInventory) { if (Player.couldInventoryAcceptThisItem(@object)) { Player.addItemToInventory(@object); return(true); } } //Need to add for chest. return(false); }