Cancellable OnGrowableChangeState hookSolved
I'd like to prevent plants from moving into the dying stage.

See this function: public void ChangeState(PlantProperties.State state, bool resetAge, bool loading = false)

For my personal situation, I'd only need a reference to the growable and the new state information.

Thanks for the awesome API.  :)
I use this for eternal plants:

object OnGrowableGather(GrowableEntity plant, BasePlayer player) 
{ 
	plant.GiveFruit(player, plant.CurrentPickAmount);
	plant.ResetSeason();
	plant.stageAge = 0;
	if (plant.Properties.pickEffect.isValid)
		Effect.server.Run(plant.Properties.pickEffect.resourcePath, plant.transform.position, Vector3.up, (Network.Connection) null, false);
	plant.ChangeState(PlantProperties.State.Seedling, true, false);
	return false; 
}		

private void OnEntitySpawned(GrowableEntity entity)
{		
	entity.Properties.MaxSeasons = 42000;
	entity.Properties.maxHarvests = 69000;
}​
I still want them to disappear when harvested, but I don't want them to die of old age.  Is that what adding to MaxSeasons as you've done above will accomplish?

Merged post

Experimented to get the answer to my question - setting MaxSeasons higher than 1 causes the plant to go back to "mature" from "ripe" instead of into the "dying" stage.  Instead of dying, the plant continues to add more and more yield with each season.
Change the OnGrowableGather part to kill the plant, should make it do what you want it to.

Would you be willing to turn this into a (paid) plugin?

Assuming that state refers to whether the plant is in mature, ripe or dying stages. There seems to be no hook for when the plant changes states so the only way to reset state from completing the dying stage would be to test in interval if the state has enter dying and reset it back to the ripe state then, but this sounds like a big performance hit given it has to check all plants.

There is apparently a way to make plants last for more seasons, with the side effect of increasing their yield each "season", which means when harvested after a long time the amount of items dropped is excessive.

An OnGrowableState or Stage Change hook would be nice, but it too might suffer from performance impact.

I want to create a plugin to prevent plants from dying and simply stay in the ripe state until harvested, but I cannot see from the docs on how I could test for "plant is in dying stage".

A hook is planned for this in the next update.

It's such a tiny amount of code, that it would be immoral for anyone to charge money for it.

I'd do it myself, but the hour or two that would take I'd rather just give someone ten bucks and spend the time on projects I'm already stuck into. That's seems a more effective use of either ones time. Evidently a hook to make this an even simpler method of just resetting the plant stage one down is coming next update, but until I read the docs and got everything thrown together... well up to you, have no issue with compensating for ones time it's what is fair after all.

I saw in the changelog the hook was added, but appears still not inserted into the docs. Thanks for adding, this should make what I want to do a lot easier 👍

With the new hook added the state change into dying should trigger and from there can be reset. I don't know what this might to do the fruits or whatever, nor do I know how Rust tends to handle things or write much C myself, but this is what I came up with. I have not tested it yet though.

        object OnGrowableStateChange(GrowableEntity growableEntity, PlantProperties.State state)
        {
            if (state == PlantProperties.State.Dying)
            {
                growableEntity.ChangeState(PlantProperties.State.Ripe, true, false);
            }
        }

It should be fairly simple to either reverse the dying state or stop plants from aging once entering the ripe state, not sure what works better. Feel free to correct me with better code, I'd love to learn :D

Locked automatically