RELEASED [SMAPI 0.40.0] Regeneration

Discussion in 'Gameplay Mechanics' started by Hammurabi, May 17, 2016.

  1. Hammurabi

    Hammurabi Big Damn Hero

    Note: A new version of this mod has been released.

    Inspired by "Stamina regen when idle" (and the SMAPI 0.39.6 update for it).

    This mod allows configurable regeneration rates for health and stamina. In addition to being able to set the rate, you are able to set an idle "cooldown" time before the regen can start (time since last injury for health, and time since last stamina usage for stamina), and a boolean to determine whether the regen can take place while you are running (walking is always fine, riding a horse is always fine, and standing still with autorun enabled is always fine; this is just for actually moving at a running pace), with all values being individually configurable for health and stamina.

    I implemented this a bit differently from MiZiPex, so there's a few noteworthy differences:
    • Pausing the game by opening a menu will pause the regen, including the cooldown periods. They resume from where they were as soon as the game is unpaused.
    • Stamina regeneration is spread out to every tenth of a second, so high regeneration rates will see a smoother increase instead of sudden jumps.

    To install, just place the .zip in your Mods folder and extract.

    using System;
    using StardewModdingAPI;
    using StardewValley;
    namespace Regeneration {
       public class RegenerationBaseClass : Mod {
         public static RegenConfig ModConfig { get; private set; }
         private static double healthRegenInterval;
         private static int lastHealth;
         private static float lastStamina;
         private static double lastTickTime;
         private static double healthCooldown;
         private static double staminaCooldown;
         public override void Entry(params object[] objects) {
           ModConfig = new RegenConfig().InitializeConfig(BaseConfigPath);
           healthRegenInterval = 1 / ModConfig.healthRegenPerSecond;
           lastHealth = 9999;
           lastStamina = 9999f;
           lastTickTime = 0;
           healthCooldown = 0;
           staminaCooldown = 0;
           StardewModdingAPI.Events.GameEvents.UpdateTick += OnUpdate;
           Log.Info("Regeneration mod by Hammurabi => Initialized");
         private void OnUpdate(object sender, EventArgs e) {
           if (Game1.hasLoadedGame && Game1.activeClickableMenu == null) {
             Farmer Player = Game1.player;
             double currentTime = Game1.currentGameTime.TotalGameTime.TotalSeconds;
             double timeElapsed = currentTime - lastTickTime;
             lastTickTime = currentTime;
             // Check for player injury. If player has been injured since last tick, adjust last injury time.
             if ( < lastHealth) {
               healthCooldown = ModConfig.healthIdleSeconds;
             else if (healthCooldown > 0) {
               healthCooldown -= timeElapsed;
             // Check for player exertion. If player has used stamina since last tick, adjust last exertion time.
             if (Player.stamina < lastStamina) {
               staminaCooldown = ModConfig.staminaIdleSeconds;
             else if (staminaCooldown > 0) {
               staminaCooldown -= timeElapsed;
             // Process health regeneration.
             if (ModConfig.healthRegenPerSecond > 0 &&
     < Player.maxHealth &&
              (ModConfig.regenHealthWhileRunning || !Player.running || !Player.movedDuringLastTick() || Player.isRidingHorse()) &&
              healthCooldown <= 0) {
      += 1;
               healthCooldown = healthRegenInterval;
             // Process stamina regeneration.
             if (ModConfig.staminaRegenPerSecond > 0 &&
              Player.stamina < Player.maxStamina &&
              (ModConfig.regenStaminaWhileRunning || !Player.running || !Player.movedDuringLastTick() || Player.isRidingHorse()) &&
              staminaCooldown <= 0) {
               Player.stamina += ModConfig.staminaRegenPerSecond / 10;
               staminaCooldown = 0.1;
             // Updated stored health/stamina values.
             lastHealth =;
             lastStamina = Player.stamina;
      public class RegenConfig : Config {
         public float healthRegenPerSecond;
         public float staminaRegenPerSecond;
         public int healthIdleSeconds;
         public int staminaIdleSeconds;
         public bool regenHealthWhileRunning;
         public bool regenStaminaWhileRunning;
         public override T GenerateDefaultConfig<T>() {
           this.healthRegenPerSecond = 0.1f;
           this.staminaRegenPerSecond = 1.0f;
           this.healthIdleSeconds = 15;
           this.staminaIdleSeconds = 10;
           this.regenHealthWhileRunning = false;
           this.regenStaminaWhileRunning = false;
           return this as T;

      Attached Files:

      Last edited: Mar 10, 2017
    • Inccubus

      Inccubus Star Wrangler

      Cool! I was hoping someone would do something like this. Thanks!
      • giminfarm

        giminfarm Void-Bound Voyager

        really like your work, thanks :D
        • Halvaard

          Halvaard Void-Bound Voyager

          Hmm, this sounds perfect for adding along side TimeSpeed.
          I prefer a longer day but run out of energy very fast, this just my be a viable solution.
          • tilyene

            tilyene Aquatic Astronaut

            How do I configure this?
            • ShyOnCamera

              ShyOnCamera Void-Bound Voyager

              Open config.json in notepad and you can change the settings there. Hope it helps. :)
              • littleraskol

                littleraskol Subatomic Cosmonaut

                I've noticed that regeneration will still work when in a cutscene or when a menu is open (edit: apparently I imagined this, see below!). This is possibly unwanted behavior because it violates the time-for-energy economy of the mod. It should be possible to prevent this by checking the following before processing regeneration:

                Game1.activeClickableMenu == null

                The first is (I think?) whether there is a lock on movement during cutscenes, the second checks that no menu is open.

                Edit: Actually, looking into it, I'm wrong about the menu, there is a check in place for this. But I know that I've seen my stamina end up higher than it was before a cutscene! Adding to the first check in OnUpdate should prevent this:

                if (Game1.hasLoadedGame && Game1.activeClickableMenu == null && Game1.player.canMove)

                Difficult to test for sure, though, since I'd need a save on a day where one will happen.
                  Last edited: Sep 25, 2016
                • foghorn

                  foghorn Pangalactic Porcupine

                  @littleraskol Start a new game, drain most of your energy, and go inside Pierre's Store for a cutscene. Or, use the Trainer mod to skip to the day of a festival that has a cutscene.
                  • Kashii49829

                    Kashii49829 Void-Bound Voyager

                    It'd be nice to have someone to have referral stuff on each of the older posts where this mod is posted like Kyler's and Natfoth, to say 'hey, we have a updated version of this mod for those who want it. I can possibly do that, I just want to make sure I don't step on anyone's toes giving the wrong mod.
                    • Kashii49829

                      Kashii49829 Void-Bound Voyager

                      Also would someone be able to share this on Nexus mods or something?
                      • Degas

                        Degas Intergalactic Tourist

                        I've been struggling for a quite a while with this, probably because all of the youtube videos I've searched for and played direct me to old versions that simply don't work (not updated for vsn. 1.1 of the game, I presume). I hope this one works, especially with TimeSpeed. I have questions, though. If someone could help, it would be very appreciated!

                        When you say "place in the Mods folder", which one do you mean? SMAPI creates a mod folder in user/appdata/roaming/stardewvalley folder. There is also one in the main game folder (mine is in Steamapps).

                        Re: SDVMM.exe. I'm just starting to mod SDV, and a lot of videos/tutorials are basically telling me that the SDV mod manager is required. I downloaded that and I intensely dislike it. The thing shoves all kinds of junk into various obscure places when you first run it. Is it really necessary? Isn't SMAPI enough on it's own? An example of the behavior I dislike is that "Delete local content" from your Steam Library leaves a *ton* of stuff on your C:\ drive that persists with a new install. I have had to go in and manually search for and delete a bunch of folders that both SMAPI and SDVMM have installedin order to actually completely uninstall and do a fresh reinstall of SDV. Another issue is that SDVMM crashes and corrupts files and folders every time I try to delete a mod from it's interface. I have to manually go dig out and delete all the junk it has installed.

                        Any answers and advice would be appreciated :)

                        EDIT: Editing with answers I've found on my own:

                        Extraction: Extract this mod's folder into your game directory's "Mods" folder that is created by the SMAPI installation. Once I did that, stamina regen worked in a fresh install of SDV vsn. 1.11. I created a new Spring Day 1 save after I reinstalled. I also had a backup save from my original game. I loaded both up and the regen is working in both of them. /SALUTE! Now, I'll start installing the other mods I want. First is TimeSpeed.

                        SDVMM: I have installed this Regeneration mod, TimeSpeed, and Get Dressed. I extracted the folders into the Mods folder in the game directory. All are working properly... *\o/* Woot! Thanks SO much for making this updated mod!
                          Last edited: Oct 25, 2016
                        • littleraskol

                          littleraskol Subatomic Cosmonaut

                          For what it's worth, I went ahead and released an updated/expanded version of this mod:

                          Sorry if this breaks some protocol, but Hammurabi was last online in July so i don't think anyone's going to get an answer any time soon about whether it's OK to update this. I've kept the same open source paradigm Hammurabi and prior authors of similar mods used.
                          • tomkrizan

                            tomkrizan Tentacle Wrangler

                            It definitely violates Hammurabi's copyright to modify and release the source. I tried getting a hold of Hammurabi but as you stated they haven't been on the forums since July :(.

                            Edit: Actually I'm quite sure someone with the steam username is the same person. I've sent a friend request but we'll see if that's accepted.
                              Last edited: Feb 14, 2017
                            • littleraskol

                              littleraskol Subatomic Cosmonaut

                              I mean, if we're talking about "copyright violations," if have to ask whether you're speaking from a place of legal expertise here? Video game mods are often in an odd and ambiguous place for that. I'd settle for a forum mod making a ruling about the protocol for this sort of thing but no one's said anything in the thread I started. Personally I don't know why anyone would make their source code public if they don't want the project to be considered open-source, but whatever.
                              • tomkrizan

                                tomkrizan Tentacle Wrangler

                                This is a well established topic and not at all in an "odd and ambiguous place for that." You can learn more at this website ran by GitHub:

                                I'm not Hammurabi and only Hammurabi can exercise his or her copyright, so don't think I'm coming here trying to say you need to bring down ReRegeneration. But you are definitely entering a copyright violation here and I was only answering your question posted above.

                                I tried to get a hold of Hammurabi on Steam (at least who I think is Hammurabi) but that didn't work and I don't plan on harassing Hammurabi further. I'm sure if someone could get Hammurabi to come here and approve a license for the code then Hammurabi would do so. Until then any derivative works using the code as a base is a copyright violation.
                                  Last edited: Feb 24, 2017
                                • littleraskol

                                  littleraskol Subatomic Cosmonaut

                                  Then what is the purpose of your comment? I'll comply with anything the moderators of this site tell me, but as far as I can tell you're just asserting on the basis no apparent expertise in the law that I am engaged in a clear copyright violation. Nothing about this compels me to act so I'm just a bit confused here.
                                  • The | Suit

                                    The | Suit Agent S. Forum Moderator

                                    He essentially answered his own statement.
                                    Only Haramb can make a claim whether to take it down or not.
                                    If Haramb - wants it taken down - I am sure little will comply without any issue, if he doesn't we can take action.

                                    Little so far has acted in good faith by giving accreditation to the original creator and not trying to profit from it. No point trying to make a mountain out of a mole hill.
                                      littleraskol likes this.
                                    • Hammurabi

                                      Hammurabi Big Damn Hero

                                      Just logged back in for the first time in forever, and saw the discussion about copyright stuff.

                                      First of all: Feel free to use anything I post here in any mod pack, compilation, etc. to update the source code for anything I release, you get the picture. The stuff I release here is purely done as a hobby, so treat it all as open source.

                                      Second of all: I'm not Hammurabi on Steam. Friend him if you want, but I'm sure he'll be confused if you ask him about these mods. ;)
                                        littleraskol likes this.
                                      • littleraskol

                                        littleraskol Subatomic Cosmonaut

                                        Thanks for the update, and for the work you've done.

                                        Share This Page