WIP BETA: FarmAutomation Mods (for SMAPI 0.39.6+)

Discussion in 'Mods' started by Oranisagu, Mar 28, 2016.

  1. Oranisagu

    Oranisagu Subatomic Cosmonaut

    Hey everyone

    I'm writing some mods to take over the more tedious work on your farm.
    The main goal is to automate collecting stuff from machines and refilling them. In addition the mod can collect items from your animal houses (Coop/Barn).
    There's also a separate mod for just opening and closing barn doors at specific times.

    The mods are both fairly stable by now and an official release will soon follow. But if your Farm is setup in a way that many machines are already connected, the mod will instantly start putting items in them.
    So before everything else: please backup your saves!

    You can find a description and a link to the latest releases under:

    Copied descriptions from my GitHub readme:

    This is the main mod of this project. it's purpose is to collect items from your barns, coops and machines (in various locations) and put them in nearby chests. if the chest contains appropriate raw materials, it will also immediately refill the machine. if, for example you have a keg farm somewhere, just put enough fruit into the chest and it should automatically create wine for you. this alleviates the tiresome running around refilling your machines.

    So how does it find the chests? Simply put: if a machine touches a chest, it will use it. if it touches another machine and that one touches a chest, it will use it. and so on. you can create as large rows (or fields, it works in all 4 directions) of machines as you want. in addition, it's now possible to use pathways like boardwalks or cobblestone paths as well by adding the appropriate number into your configuration file (the default configuration file contains a list of the various paths and their numbers).

    so you might want to shut off flooring tiles until you've setup your farm appropriately - otherwise it's possible everything connects to everything and uses the first available chest (don't worry if it's full, it won't deposit the items then, but it might take items for further processing you didn't want to process).

    A gif is worth a 1000 words, so I've added 2 simple gifs to the readme to show how it works:

    This mod simply opens and closes the barn doors at configurable times. there is already another mod doing this so unless you have problems with that one, this probably won't help you much.

    Future Plans and Issues:
    I've started an issue list on github to make it easier to keep track:
      Last edited: Apr 13, 2016
    • UltrosBoogie

      UltrosBoogie Space Spelunker

      Only did a little testing on it but so far it definitely had Kegs working, and it picked up the eggs in my coop, and maple syrup from my tappers. I think I'm going to love this! It looks like trees work on the diagonal, so it isn't perfect but you can get 4 tappers per chest.

      I really hope you stick with it
      • Alhifar

        Alhifar Void-Bound Voyager

        You really should be always caching your results and only updating when a chest or machine (or any item marked as a connector) is placed. There's currently no event for placing objects, but the following should give a good general idea on how to approximate that with watching inventory changes:
        namespace TestMod
            public class TestMod : Mod
                List<string> ArtisanMachines;
                public override void Entry(params object[] objects)
                    PlayerEvents.InventoryChanged += InventoryChangedCallback;
                    this.ArtisanMachines = new List<string>();
                    this.ArtisanMachines.Add("Mayonnaise Machine");
                public void InventoryChangedCallback(object sender, EventArgsInventoryChanged e)
                    foreach (ItemStackChange itemChanged in e.Removed)
                        if (itemChanged.StackChange > 0 && (itemChanged.Item is StardewValley.Objects.Chest || this.ArtisanMachines.Contains(itemChanged.Item.Name)))
                            //Update cache
        • Oranisagu

          Oranisagu Subatomic Cosmonaut

          thank you! and yes, as long as I have ideas for improvements I'll maintain it (and once the source is on github, anyone could pick it up if I ever grew bored with it.

          diagonal connections actually are unintended (now that I think about how I implemented it, I have no idea how I missed it). I think the next thing I'll look into is using flooring tiles (paths) as connectors, this way it should be easy to connect as many tappers as you'd like. then I can fix the connector search to only directly adjecant tiles instead of all 8 surrounding ones.

          hm, yes, good idea, this could work. any inventory change (add or remove though, if you pickaxe a machine or chest it can break connections as well) on any kind of connector item could invalidate the caches (so they'll be refreshed when the next time update occurs). this could be the new default behaviour and I'll keep the only once daily configuration option for people where it takes too long. in addition, I've been thinking about putting the whole search into a separate thread, but I have no idea how threadsafe the game currently is, so that could introduce more problems than it solves (or maybe just add a thread per location but block until all threads have returned). and if I get a place/remove event in the future it would become a lot easier and faster.
          • Alhifar

            Alhifar Void-Bound Voyager

            It looks like currently, the only things threaded are some copy/paste code and some of the unused netcode. Updated the cache in a separate thread SHOULD be safe as long as you make sure to lock the cache before working on it or using it. As long as your cache update code isn't taking too long, that shouldn't lead to any issues
            • SpringsSong

              SpringsSong Cosmic Narwhal

              For some reason, the automatically petting animals each morning is only working on my cows and not my chickens/ducks/rabbits (working towards checking goats/sheep/pigs).
              • Oranisagu

                Oranisagu Subatomic Cosmonaut

                so I've updated my initial post and uploaded a new version for the item collector. it should be faster and more reliable plus floor tiles can now be used as connectors as well. be careful though, if you have an uninterrupted path through your farm everything might connect to the same chest, that's why I initially only added the boardwalks, but you can add any kind of flooring in the configuration. the source is now also available at github if anyone wants to have a look (it's a mess. the whole connection stuff is fairly complicated and needs a serious cleanup)

                I have it a try, so far it doesn't seem to take too long, but I don't have too many connected tiles on my farm (since I added floorings it was about 500 or so which is not noticable)

                yes, I noticed that too today, it should be fixed now =)
                • BoffoBoy

                  BoffoBoy Existential Complex

                  Really nice idea! Hope any bugs are polite for you!
                  • Gantros

                    Gantros Pangalactic Porcupine

                    I think there is potential for the mechanics of this mod to be applied to actual items, like milk buckets can be upgraded into a milking machine that automatically connects to the cheese press, or a nest in the coop that automatically takes eggs and places them in the mayo machine.
                    • Oranisagu

                      Oranisagu Subatomic Cosmonaut

                      once it's possible to add custom crafting recipes and items, that's pretty much the way I'd like to go for animal stuff. until then I think my next step will be to connect cheese press etc to the appropriate buildings (i.e. any machine touching a building can automatically use the items from there).

                      right now the mod should already make giant keg farms and the like a lot more enjoyable to handle (unless there are nasty bugs ofc).

                      I want to rework some of the more convoluted code but unless there are bugs I'll probably focus on improving the current features first (especially Coop/Barn connection to outside machines).
                      • TerraMark

                        TerraMark Void-Bound Voyager

                        Hey, could you put a version number on these? so i know if there's an update to them.
                        • Oranisagu

                          Oranisagu Subatomic Cosmonaut

                          yeah, I'm still learning Git, but I think I mostly figured it out by now. you can head over to https://github.com/oranisagu/SDV-FarmAutomation , the readme links to the latest releases, this time including the version numbers =)
                            TerraMark likes this.
                          • Mysteana

                            Mysteana Scruffy Nerf-Herder

                            The seed maker is a machine that's not included
                            Nice work so far, it's certainly going to make me reconsider how I design my layout to maximise.
                            • Oranisagu

                              Oranisagu Subatomic Cosmonaut

                              so far I left that one out intentionally, as I was afraid it would start swallowing up peoples good crops (i.e. gold star stuff kept for the grange or so). but I agree, the mod should support it, but by default not refill it (so it has to be activated in the configuration by choice). I'll have a look into it this evening.
                              • Kazekitsune23

                                Kazekitsune23 Void-Bound Voyager

                                Been trying to figure this out but what is the boardwalk path? I'm guessing it's either weathered floor or wood path but not entirely sure if that's the in game name for it.
                                • Oranisagu

                                  Oranisagu Subatomic Cosmonaut

                                  sorry, that's the internal name, in the game it's called wood path, looks like 2 planks parallel to each other. costs 1 wood to craft. see http://stardewvalleywiki.com/Wood_Path

                                  it's pretty ugly and it seems few people use it (I mainly use it to surround my tapped trees to avoid getting acorns and stuff like that).

                                  in the config file there are other tiles where I have no idea what they mean, I just copied them straight from the games sources. i.e. I have no idea what the ghost tile is ;-)

                                  I'm thinking about finding a better way to configure these tiles, with names instead of numbers etc.
                                    Last edited: Mar 30, 2016
                                  • Mysteana

                                    Mysteana Scruffy Nerf-Herder

                                    Reporting a bug in regards to the Barn/Coop door automation mod:

                                    The configuration values [Open|Close]DoorsAfter appears to be flipped. OpenDoorsAfter regulates the time which the doors are closed, while CloseDoorsAfter regulates the time which the doors are opened.
                                      Oranisagu likes this.
                                    • Oranisagu

                                      Oranisagu Subatomic Cosmonaut

                                      oops =) I renamed that stuff to make it better readable but I guess I accidentally flipped the test then.

                                      fixed it (missed a ! somewhere) but can't rebuild until later today.
                                      • Mysteana

                                        Mysteana Scruffy Nerf-Herder

                                        No hurry with the fixes :) That problem can be easily worked around in the meantime (if not a little counter-intuitive for the moment)

                                        Getting another bug which is causing a Crash to Desktop (CTD)

                                        I've isolated it to the Recycling Machines and it occurs on the first update tick of the day (6:10) only. It appears that having a recycling machine connected to a chest either as a result of being adjacent to the chest or via a connecting tile (eg: wooden paths) causes a CTD regardless of whether or not the chest is empty, has valid items, does not have valid items etc...

                                        Any other update ticks aside from 6:10 will not cause a CTD hence, if you were able to freeze time at 6:00, remove the recycling machines from any sort of automation chain then resume time for the 6:10 tick, pause again and replace the machines for 6:20+ no CTD will occur.

                                        Isolation tests have been done.
                                        This CTD occurs regardless of the day or weather condition. Immediately sleeping and advancing to the next day will cause a CTD at 6:10
                                        No other automation can be in use, including barns/coops, and the CTD will still occur with a single recycling machine connected to a chest
                                        Recycling Machines need only be a connector. They can be removed from the MachinesToCollectFrom list and the CTD will still occur
                                        This CTD appears to be only with Recycling Machines at 6:10. All Recycling Machines need to be disconnected from an automation chain for the 6:10 update to prevent a CTD.

                                        I can provide a save file if you need one for test data.

                                        Apologies in advance, I know this is an alpha release but I guess my testing helps?
                                          Oranisagu likes this.
                                        • dsrules

                                          dsrules Subatomic Cosmonaut

                                          At what time of the day are the animals automatically pet? It seems like I am still petting them manually?

                                          Share This Page