Modding Help One crop, different kinds of produce?

Discussion in 'Mods' started by Ciriun, May 10, 2017.

  1. Ciriun

    Ciriun Big Damn Hero

    Sorry if the title is confusing, I have been trying to think of how to word this. What I'm trying to ask is if it is possible to have one crop that produces something different for each season? Or a chance of getting two or more different things growing from the same plant?
     
    • Entoarox

      Entoarox Oxygen Tank

      This is doable, but *difficult*, but SDV has a build-in mechanic for dynamic crops, it just is not exposed as such, so you'd need a SMAPI mod and deal with the serializer.
       
      • Ciriun

        Ciriun Big Damn Hero

        I'm sure this question will not be at all reassuring, but what would I need the serializer for exactly?
         
        • Entoarox

          Entoarox Oxygen Tank

          You dont need it, you need to *deal* with it, in order to create a crop that can have dynamic produce like that, you need to override the Crop behaviour, and SDV's serializer doesnt like when there are unknown objects in the world, so you need to have 2 versions of your crop, one that is serializable but doesnt actually work, and one that isnt serializable but does work.
           
          • Ciriun

            Ciriun Big Damn Hero

            That is very probably beyond my limited coding ability, but I might try playing with it to see what I can get. It'll be my first time attempting anything for SMAPI so I'm not super optimistic. But we won't know for sure until I try, right?
             
            • Entoarox

              Entoarox Oxygen Tank

              I've actually had a look, you just need to set Crop::indexOfHarvest to the item you want to be harvested, and voila, it works, I originally thought you would need to create a custom Crop that replaced the whole harvesting logic, but that doesnt seem to be the case! :D
               
                Ciriun likes this.
              • Ciriun

                Ciriun Big Damn Hero

                Would it be asking for too much of a handout to see what you've done?
                 
                • Entoarox

                  Entoarox Oxygen Tank

                  I just had a look at the StardewValley.Crop::harvest method and how it handled what the harvested item is, there I found that it uses, at the time of harvesting, StardewValley.Crop::indexOfHarvest to create a new object to add to the players inventory.
                  This means that if during DayUpdate, you iterate all crops on the farm, find any instance of your "MultiProduce" crop that is fully grown, then set the `indexOfHarvest` on each to one of the allowed outputs, you have yourself a working crop that can produce multiple things.
                  (Although, still only 1 kind per crop, but multiples of the same crop can all produce something else)
                   
                  • Ciriun

                    Ciriun Big Damn Hero

                    Okay, so if I'm understanding correctly, what will happen is that if I plant, say 5 of the MultiProduce crop, and there are 3 possible items that could come from it, each of the 5 I planted have a chance of growing 1 out of the 3 items?
                     
                    • Entoarox

                      Entoarox Oxygen Tank

                      Correct, your code would assign each crop a random output from the list of possible outputs, so while a single crop will produce a single output (although it may be multiple of that output, say, 3x item A, or 2x item B, or 3x item C, depending on how you configure the crop to produce), it will be a random one from the list of *possible* outputs.
                       
                      • Ciriun

                        Ciriun Big Damn Hero

                        Do you think it would be possible to tie that to the season change instead of the day and have a fixed one for each season instead of random? Or failing that, is it possible to tweak the odds of certain items occurring?
                         
                        • Entoarox

                          Entoarox Oxygen Tank

                          How you handle the produce all depends on your own code, not CA's, so it can be any situation you want.
                           
                            Ciriun likes this.
                          • Ciriun

                            Ciriun Big Damn Hero

                            Thank you so much! I'll start playing with it as soon as I can wrestle Visual Studio 2017 into submission.
                             

                            Share This Page