Vintagestory.GameContent.BEBehaviorFruiting.CheckForGrowth C# (CSharp) Method

CheckForGrowth() private method

private CheckForGrowth ( float dt ) : void
dt float
return void
        private void CheckForGrowth(float dt)
        {
            double timeFactor = GameMath.Clamp(Api.World.Calendar.SpeedOfTime / 60, 0.1, 5);
            double now = Api.World.Calendar.TotalDays;
            bool fastForwarded = now > dateLastChecked + 0.5;
            dateLastChecked = now;
            if (Api.World.Rand.NextDouble() > 0.2 * timeFactor && !fastForwarded) return;

            int count = 0;
            bool dirty = false;
            foreach (var val in fruitPoints)
            {
                if (val.variant >= 0)
                {
                    if (val.transitionDate == 0)
                    {
                        val.transitionDate = GetGerminationDate();  // probably this code path is never reached, but just in case something went wrong reading a BlockEntity from a save etc.
                        dirty = true;
                    }

                    if (val.currentStage > 0) count++;
                }
            }

            bool finalStagePlant = false;
            if (this.Blockentity.Block is BlockCrop crop)
            {
                finalStagePlant = (crop.CurrentCropStage == crop.CropProps.GrowthStages);
            }
            foreach (var val in fruitPoints)
            {
                if (val.variant >= 0)
                {
                    if (now > val.transitionDate)
                    {
                        if (val.currentStage == 0 && count >= maxFruit) continue;     // Suppress growth for now - too many fruits already on this plant - but try again soon

                        if (finalStagePlant && val.currentStage < fruitStages - 3) continue;    // No small green fruit growth on final stage crop, except ripe fruit can become overripe

                        if (++val.currentStage > fruitStages)
                        {
                            // reached final stage
                            val.transitionDate = Double.MaxValue;
                            val.currentStage = fruitStages;
                        }
                        else
                        {
                            // set up next transition - take 2.5 times as long for the final stage
                            val.transitionDate = now + transitionDays * (1 + Api.World.Rand.NextDouble()) / 1.5 / PlantHealth() * (val.currentStage == fruitStages - 1 ? 2.5 : 1);
                        }
                        dirty = true;
                    }
                }
            }

            if (dirty) Blockentity.MarkDirty();
        }