Growing plants
This page uses Vector3 from Unity. The glossary says what each one is.
Plants lists the plants that grow in the scene you are in and tells your mod when they are harvested or picked. Each plant is a PlantInfo.
Plants the plant list and pick events
Use it to list the plants in the scene, read the fruit slots of one plant, and hear when a plant is harvested or a fruit is picked.
public static class Plants
{
public static event Action<PlantHarvestArgs> Harvested;
public static event Action<PlantPickArgs> Picked;
public static List<PlantInfo> All();
public static List<PlantFruitInfo> Fruits(string plantId);
public static bool IsAvailable { get; }
}
| Method | Returns | What it does |
|---|---|---|
All() | List<PlantInfo> | Every plant in the active scene. |
Fruits(plantId) | List<PlantFruitInfo> | The fruit slots of one plant. |
| Property | Type | What it means |
|---|---|---|
IsAvailable | bool | false when the plant events could not be set up. |
| Event | Gives you | When it fires |
|---|---|---|
Harvested | PlantHarvestArgs | A plant’s harvest was handed out. |
Picked | PlantPickArgs | One fruit was picked. |
PlantHarvestArgs what Harvested gives you
Plants.Harvested hands you one of these when a plant’s harvest is handed out. Items lists what the harvest gave.
public sealed class PlantHarvestArgs
{
public string PlantId { get; }
public List<ItemCount> Items { get; }
}
| Property | Type | What it means |
|---|---|---|
PlantId | string | The plant that was harvested. |
Items | List<ItemCount> | What the harvest gave. |
PlantPickArgs what Picked gives you
Plants.Picked hands you one of these for each fruit that is picked, with the fruit’s item number and how many.
public sealed class PlantPickArgs
{
public string PlantId { get; }
public int ItemId { get; }
public int Amount { get; }
}
| Property | Type | What it means |
|---|---|---|
PlantId | string | The plant the fruit came from. |
ItemId | int | The fruit’s item number. |
Amount | int | How many. It is the amount the game rolled for the fruit. |
PlantInfo a snapshot of one plant
Plants.All() gives you one of these for each plant in the scene. Pass its Id to Plants.Fruits or to the calls on the Plant actions page.
public sealed class PlantInfo
{
public string Id { get; }
public Vector3 Position { get; }
public int Age { get; }
public int FullGrownAge { get; }
public float Progress { get; }
public bool FullyGrown { get; }
public bool Paused { get; }
public bool Rotting { get; }
public int ReadyFruit { get; }
}
| Property | Type | What it means |
|---|---|---|
Id | string | The plant’s id. It can be null on a plant that was just planted. |
Position | Vector3 | Where the plant is, in world coordinates. |
Age | int | How old it is, as the game counts. |
FullGrownAge | int | The age at which it is fully grown. |
Progress | float | How far it has come. It is 0 to 1 while growing, and then it counts up through spoiling. |
FullyGrown | bool | true when Age has reached FullGrownAge. |
Paused | bool | true when its growth is paused. |
Rotting | bool | true when it is rotting. |
ReadyFruit | int | How many visible fruits are ready to pick. |
PlantFruitInfo a snapshot of one fruit slot on a plant
Plants.Fruits(plantId) gives you one of these for each fruit slot. Check Visible first, because hidden slots are listed too.
public sealed class PlantFruitInfo
{
public int ItemId { get; }
public int Amount { get; }
public bool Visible { get; }
public bool Ready { get; }
public bool Spoiled { get; }
public float GrowProgress { get; }
public float SpoilProgress { get; }
}
| Property | Type | What it means |
|---|---|---|
ItemId | int | The fruit’s item number. It is 0 when the fruit has no item. |
Amount | int | How many the game rolled for this fruit. |
Visible | bool | true when the fruit’s object is switched on. |
Ready | bool | true when it is ready to pick. |
Spoiled | bool | true when it has spoiled. |
GrowProgress | float | 0 to 1. How far it has grown. It is 0 when its full age is 0. |
SpoilProgress | float | 0 to 1. How far it has spoiled. It is 0 when the value is not a number. |
Things to know
All()lists every growing plant in the scene you are in. That is the plants in growing spots and any others. (It returns everygrowobject in the active scene.Idisgrow.GUID.Progressisgrow.GetCurrentStageProcess().ReadyFruitcounts active fruits withreadyToPick; hidden animal-meta fruits are not counted.)Harvestedfires when the game hands out a plant’s harvest. That covers the player harvesting a ripe plant and a growing station harvesting its spots. It also fires when a dead plant is pulled up, with the plant’s leftover items. (It fires ongrow.HarvestExternal.)Pickedfires when one fruit is picked. That is a player picking a ripe fruit. It also fires for each ripe fruit that a harvest of a multi-fruit plant picks, so that harvest raises onePickedfor each ripe fruit and noHarvested. (It fires whenGrowItem.GetItemhands out a fruit: it returned 0 and the fruit is not spoiled. The harvest case is the loop inside the plant’sHarvestExternal.)- A spoiled fruit raises nothing, and seeds are not reported.
Amountis the number the game rolled for the fruit. It is not checked against free space in the inventory. (It is the rolledGrowItem.itemAmount.) Fruits(plantId)lists the fruit slots of one plant, including hidden ones. CheckVisible. It returns an empty list for anull, empty or unknown id. It does not read the growth through the game’s stage call, because that call can throw an error. (The stage call isGetCurrentStageProcess.GrowProgressis age divided byfullGrownAgeFinal, andSpoilProgressiscurrentSpoilTimedivided byrandomSpoilTime.)IsAvailabletells you whetherHarvestedandPickedwork. It isfalsewhen the framework could not set up the events, or when its feature group was turned off.All()andFruits()keep working.
Limits
Harvesteddoes not fire for a multi-fruit plant picked fruit by fruit. Picking ripe fruit off such a plant hands the items out another way, so the harvest comes back empty and the event is not raised. UsePickedfor those.Harvesteddoes not cover plants that are single collectable items, which a growing station picks up another way. It also does not cover pulling up a plant that has not grown up, which destroys the plant without giving any items. (The first isCollectibleItemplants. The second is the immature-plant harvest.)