Modding Help Tree Growth Chance - Where is it determined?

Discussion in 'Mods' started by atomR, Oct 10, 2017.

  1. atomR

    atomR Space Hobo

    I'm not trying to mod anything related to tree growth, exactly. I'm just trying to find out where is laid out in the game code so that I can see exactly how it is calculated. I've been poking around XNBs to no avail. Help?

    Also, I'm talking maple/pine/oak, not the fruit trees.
     
      HopeWasHere likes this.
    • Pathoschild

      Pathoschild Tiy's Beard

      Non-fruit tree growth is handled in the game code, specifically Tree::dayUpdate. (Fruit trees are separate.) Here's the relevant part:
      Code:
      public override void dayUpdate(GameLocation environment, Vector2 tileLocation)
      {
          [...]
          if (!Game1.currentSeason.Equals("winter") || this.treeType == Tree.palmTree || environment.Name.ToLower().Contains("greenhouse"))
          {
              [...]
              if (this.growthStage == Tree.treeStage - 1)
              {
                  foreach (var terrainFeature in environment.terrainFeatures)
                  {
                      if (terrainFeature.Value is Tree tree && tree != this && tree.growthStage >= 5 && tree.getBoundingBox(terrainFeature.Key).Intersects(rectangle))
                          return;
                  }
              }
              else if (this.growthStage == Tree.seedStage && environment.objects.ContainsKey(tileLocation))
                  return;
              if (Game1.random.NextDouble() < 0.2)
                  this.growthStage = this.growthStage + 1;
          }
          [...]
      }
      
      Which essentially means a tree grows if...
      1. it's not winter, or the tree is in the greenhouse;
      2. the tree's tile is clear (if seed stage);
      3. the surrounding tiles are clear (if almost-fully-grown stage);
      4. a 20% random check passes.
       
        atomR and anothersarah like this.
      • atomR

        atomR Space Hobo

        Ah, great! What file is that in?
         
        • Pathoschild

          Pathoschild Tiy's Beard

          It's in Stardew Valley.exe. You can decompile it to see an approximation of the original code; once you do, it'll be in TerrainFeatures\Tree.cs.
           
          • atomR

            atomR Space Hobo

            Great! Got what I need. Thanks!
             

            Share This Page