1. This forum is obsolete and read-only. Feel free to contact us at support.keenswh.com

Automated Inventory Sorting - No more dirty cargo holds

Discussion in 'Released and WIP Mods' started by tyrsis, Oct 4, 2014.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. tyrsis

    tyrsis Junior Engineer

    Messages:
    862
    Are your cargo holds completely disorganized and a mess? Wife upset that you're too busy sorting your building components instead of playing with the kids? Worry no more!

    I've completely automated sorting of cargo holds on all your ships and stations. This will be expanded to allow customized pull and eventually push logic for all blocks on a grid including assemblers and refineries. Currently only cargo holds are supported, but this will change quickly. This should work for single player, multiplayer and dedicated server. (Tested on all)

    Right now it supports pulls, and eventually it will support pushing components. In order to setup a pull on a block, it's very easy, just update it's name with the component you want in that cargo hold. You can specify multiple components by comma separating them. You must enclose the components in square brackets as well. So the name of a cargo hold that holds steel plates and computers would look like:

    CleanCargo: [SteelPlate,Computer]

    Once the cargo hold has that name it will pull steel plates and computers from any other cargo hold on the grid that doesn't have those components in their pull list.

    Pulls also support shortened names,for example:

    OreCargo: [Ore]

    Will pull _all_ ore. And:

    IgnotCargo: [Ingot]

    will pull _all_ ingots. (btw the text before the text inside the []s doesn't matter, I'm just naming them).

    Right now all pull requests are treated the same, and are sorted by first come first serve in the grid list. Priority will be added later, and is planned.

    Anyway, you can find the mod in the workshop: https://steamcommunity.com/sharedfiles/filedetails/?id=321588701

    Please leave bug reports here and I will address them as they come.
     
    Last edited by a moderator: Oct 4, 2014
  2. Semaphorism

    Semaphorism Apprentice Engineer

    Messages:
    186
    Nice job, about time we start seeing more scripted mods!
     
  3. eobando

    eobando Trainee Engineer

    Messages:
    96
    Tyrsis is a beast! This is fantastic!
     
  4. demonocolips

    demonocolips Apprentice Engineer

    Messages:
    176
    kewl.

    is it possible to also add rankings as in itll go here before going here.

    cleancargo1:

    cleancargo2:

    or something like that to set rankings for storage

    also setting an amount for said storage. steelplate 10000, interiorplate 50000
     
    Last edited by a moderator: Oct 4, 2014
  5. tyrsis

    tyrsis Junior Engineer

    Messages:
    862
    Yup, set amounts and priority are on the todo list. I just wanted to get something out small first and then throw in extra features as they get tested. It's hard testing across single, multi and dedicated, as they all behave differently.
     
  6. TheDeinonychus

    TheDeinonychus Trainee Engineer

    Messages:
    89
    This makes me eager for a filter ability on connectors and ejectors. For instance, having them set to dump out all stone while mining to save on cargo space.
     
  7. entspeak

    entspeak Senior Engineer

    Messages:
    1,744
    This is amazing! Thanks!
     
  8. Spamasaurus

    Spamasaurus Trainee Engineer

    Messages:
    16
    This is one of those mods that will make it into vanilla after a while. Nice work.
     
  9. tyrsis

    tyrsis Junior Engineer

    Messages:
    862
    Updated

    - Fixed issue with sorting not following conveyor system. Now blocks must be attached for their inventory to move between one another. This makes sorting completely legitimate now. (No more magical sorting between unconnected blocks)
    - Added [Exempt] tag which means the block will be exempt from having it's inventory pulled
    - Added refineries, assemblers and connectors as valid targets for pulling inventory from. You can not pull inventory INTO assemblers, refineries or connectors YET, but I did this to try to curb push / pull situations. (Where inventory bounces back and forth). So that means you can only pull OUT OF them for now. You can now pull items out of assemblers and refineries after they are created (good for moving ore that's been refined, or items that are building at assemblers).
    - Fixed issues with case sensivity
     
  10. Coreinsanity

    Coreinsanity Apprentice Engineer

    Messages:
    188
    I was honestly contemplating starting a mod like this, but I am glad to see some one has already started!

    Thanks for the mod, will really be keeping an eye on this.

    And please this, lol.

    Right now I have to use a valve-based system using connectors to section off the whole assembly line(refineries, assemblers, uranium refineries & reactors) from the stone ejection system so that the ejection system doesn't just pull everything. It's really tedious.
     
    Last edited by a moderator: Oct 5, 2014
  11. Morcam

    Morcam Trainee Engineer

    Messages:
    1
    Heya mate,

    I just downloaded this mod from the workshop page. It's really awesome - should save me tons of time.

    The one problem I was noticing was when there were two assemblers creating multiple different components simultaneously, and one of my cargo containers was trying to pull from both.

    It wasn't stacking with the items already in there, so if I had one assembler on construction components and one on interior plates, it was just making the inventory something like

    9x Interior Plates
    1x Construction Component
    9x Interior Plates
    1x Construction Component
    9x Interior Plates
    1x Construction Component
    12000x Interior Plates
    13000x Construction Component

    So I made a quick update to your FindAndTakeInventoryItem function in the inventory.cs source file.

    In the section where you actually add the items, mine now looks like

    if (inventory.CanItemsBeAdded(amount, sDef))
    {
    inventorySource.RemoveItemsOfType(amount, foundItem.Content);

    // ========== MODIFICATION ==========
    // Find the inventory item in our inventory

    IMyInventoryItem alreadyInInventory = FindItemInInventory(inventory, def);

    if (alreadyInInventory != null)
    {
    MyFixedPoint amountAlreadyIn = alreadyInInventory.Amount;

    //if it's already in the inventory, remove it wherever it is and re-add it
    inventory.RemoveItemsOfType(alreadyInInventory.Amount, foundItem.Content);

    inventory.AddItems(amount + alreadyInInventory.Amount, foundItem.Content, 0);
    }
    else
    {
    // Otherwise if there's nothing in there, just add it
    inventory.AddItems(amount, foundItem.Content, 0);
    }
    // ========== END MODIFICATION ==========

    Logging.Instance.WriteLine(String.Format("Moving {0} {1} from '{2}' ({4}) to '{3}' ({5})", amount.RawValue / 1000000, sDef.SubtypeName, terminalSource.CustomName, ((MyObjectBuilder_TerminalBlock)slimBlock.FatBlock.GetObjectBuilderCubeBlock()).CustomName, terminalSource.EntityId, slimBlock.FatBlock.EntityId));
    }

    This seems to make them stack correctly with the forward-most instance of their component type.

    Note that I haven't spent a ton of time testing with this, but I've been running it for a couple hours now and haven't noticed any weird issues, other than some problems with splitting stacks (since the rightclick/drag thing doesn't work if the stack has been "removed"). I always use shift-click / ctrl-click though, so it's not an issue for me.

    Thanks for the mod!
     
    Last edited by a moderator: Oct 5, 2014
  12. Hexicube

    Hexicube Apprentice Engineer

    Messages:
    283
    Here's some sort strings I would like to see possible to do:
    Code:
    [-Ingot/Iron,Ingot]
    All ingots except iron ingots, the iron ingot negative request is first as the multiple item scan would pick the first match.
    If ingot was first, that would match for iron ingot and would try to pull iron ingots.
    
    [#Ore/Iron]
    Evenly split # modifier items with other containers that have the # modifier, and still try to pull from other sources.
    Good for a row of multiple refineries to keep everything balanced, such as multiple arc furnaces in this case, as it would block one from hogging all the ore.
    
    [Dump]
    Any item not requested by another container on the conveyor network will be stored here, useful for checking if you need more sorted conveyors or just want a misc items container.
    Additionally I would also like refineries to be able to pull items. That way, the first two make sense to include as they're intended to be for refineries to allow for proper ore management between them.
     
    Last edited by a moderator: Oct 6, 2014
  13. tyrsis

    tyrsis Junior Engineer

    Messages:
    862
    Splitting and not operators are planned and will be coming soon.

    I'm being cautious about having assemblers and refining pull because I can't override the in game sorting, and you end up with weird situations of inventory bounce. I will experiment with it some more when I come to implementing it to see what I can get away with, and what works.
     
  14. tyrsis

    tyrsis Junior Engineer

    Messages:
    862
    Thanks for pointing out the not stacking issue. I implemented a fix. The issue with the way you're doing it is you're adding, removing and adding again, which is an issue for dedicated and multiplayer. I have fixed it though, as it just actually required inserting at the index of existing item. Workshop was updated.
     
  15. Killili

    Killili Trainee Engineer

    Messages:
    15
    Nice i did not see that the API had the storage interface added.
    So i took a good look at parts of youre code to find out how it works.
    I found a couple of things that i found usefull, thx for that.

    I found a potanial Problem, too. In the way you build youre item list.

    Code:
    // taken from inventory.cs
    foreach (MyDefinitionBase def in MyDefinitionManager.Static.GetAllDefinitions()){
       if (def.Id.ToString().ToLower().Contains(componentName.ToLower())){
          components.Add(def);
       }
    }
    
    def.Id.ToString() will give something like "MyBaseDefinition_Ingot\Iron" this does contain "Ingot" and "Iron" but it will be a match for "Base", too.

    So if the list made from the CustomName contains "my" every item in the game will be matched.
    I am searching for a way to get the name of items you get when you MouseOver them in the Inventory, but so far no luck.

    My approch is a bit more on the Minecraft side of storage managment. Pulling stuff out of any inventory in front of a block and let the conveyors handle the transport.
    https://github.com/Killili/SimplexFilter

    But nice work, keep it up. So us lazy modders dont have to work so hard ;)
     
  16. tyrsis

    tyrsis Junior Engineer

    Messages:
    862
    Doing a contains on a string that way was a simple way of doing it. Yes if someone does "Base" they will return things they don't expect, but realistically most users won't enter something they don't know about. I can fix this with GUI access, but this way for now will work for 99% of the users :)
     
    Last edited by a moderator: Oct 7, 2014
  17. tyrsis

    tyrsis Junior Engineer

    Messages:
    862
    New version:

    v0.1.0.4
    - Added the ability to pull INTO assemblers and refineries. In order for inventory to not bounce around, please remove them from the conveyor system by clicking on the button in the GUI that says, "Use Conveyor System" "Off". The mod will ignore conveyor disable on refinery and assemblers because of this, so that it can override the default sort.
    - Added the ability to set a max amount of items on a sort. The format is Item:MaxAmount, for example [SteelPlate:10000] will only pull 10000 steel plates. Please note this works for wildcard items, and gives a max amount for each item in the wildcard, not total.
    - Added the ability to ignore certain items. The format is Item:Ignore. For example [Component,SteelPlate:Ignore] will pull every building component EXCEPT SteelPlate.
    - Fixed some performance issues, found some bugs.
     
  18. demonocolips

    demonocolips Apprentice Engineer

    Messages:
    176
    im sorry but i would love this mod but I have to be missing something about the function of the mod
    i'm using this as a name for a ingot containtainer but it doesn't seem to be working

    IngotCargo: [Ingot]

    i've tried different factions different conveyor hookups and disassembling and reassembling the machines but it doesn't seem to work. the mod is loaded because i can toggle it on and off

    i know it works for other people so what am i doing wrong?

    it may be that the game is using too much ram im floating around 3.5 gb of ram usage on the program so that may be it so ill try a less crowded world before i check back it.

    yeah brand new vanilla world only this mod every in game indication that its loaded but wont work. i have to be doing something wrong.
     
    Last edited by a moderator: Oct 9, 2014
  19. tyrsis

    tyrsis Junior Engineer

    Messages:
    862
    All blocks you want to sort from must be owned by you, not set to Nobody.

    Make sure ownership is set to yourself. Pretty much the biggest thing people miss right now.
     
  20. gimmilfactory

    gimmilfactory Junior Engineer

    Messages:
    523
    This is a consistent problem in creative mode. It shouldn't be however, in survival.

    I can tell you're using brackets and not parentheses, I made that mistake several times.
    Have you tried simple, Large/Small:[Ingot]? I don't know if he has the brackets wildcard-ing through the "get.by.displayname" attribute attached to the script handler, however I don't know if it is an unnoticed bug that was fixed ~22 hours ago, but I couldn't get it to work on dedicated server the last time I tried a few days ago. Worksing fine Private SP.
     
  21. Fingersniffer

    Fingersniffer Apprentice Engineer

    Messages:
    411
    Can you add in support for faction owned items? IE Ship X has cargo containers owned by several faction members but the sorting mod only works between items an individual owns
     
  22. Uzul

    Uzul Apprentice Engineer

    Messages:
    127
    Thi one is the absolutely best mod in SE History.

    Thousand thanks to relieve me from the pain of endlessly sorting the **** containers!!!!!!

    My main wish:
    - Please add Faction support to make sure it works for bigger player-groups.

    My main wish to the Devs:
    - Get it into the main game :-D

    Thank you man, you are my new hero ^^
     
  23. tyrsis

    tyrsis Junior Engineer

    Messages:
    862
    Not quite yet. Here is the problem, as a few people are asking for this.

    When I started making this mod, I decided I wanted it to work across all connection methods, including dedicated (because I run a dedicated server). What I ran into was the following:

    Dedicated Servers do not run scripts. The clients on the server do run them, but the server itself does not. That means I couldn't have server side sorting, only clients can do the actual sorting, that's fine but:

    Clients can't easily communicate with each other.

    It's difficult to see when a user logs in and out, and know their actual state. (Connected does not mean in game)

    These problems lead to this issue: In a situation when 4 faction members are online, which one sorts? The solution is to just choose someone and have them be the "faction sorter" and the rest sort their own. But what happens when you're sorting in and out of other players cargo? I can tell you what happens because I tested it. You end up with clients sorting one another's stuff, and inventory bouncing all over the place. Throw in inventory desync bug, and you basically have a recipe for inventory to go missing and it very hard to debug, because logs are now disjointed. I can do other very strange things like having one client sort EVERYTHING. It's an interesting idea, but what happens when they toggle? Also it puts a lot of strain on one machine. Then I have to find someone else to sort. And without good inter-client communication, syncing this becomes difficult at best.

    This can all be solved with server side sorting (server sorts clients do not), or much better intercommunication between clients. Once I get all the features I want out of the way I will look into faction sorting more and see if I can easily find a solution that doesn't require a lot of weirdness.
     
    Last edited by a moderator: Oct 9, 2014
  24. demonocolips

    demonocolips Apprentice Engineer

    Messages:
    176
    so i have to use parenthesis "" these? not [] square brackets? well tested it works weird.
     
  25. Uzul

    Uzul Apprentice Engineer

    Messages:
    127
    Regarding the sorting for faction:

    If, instead of doing a huge instant-sorting, you do like one "sorting-event" at a time, like once per minute one transaction, the risk of clients messung up each other should be very limited - then make the order in which the client does the actions random, so its unlikely that for example every client tries to sort "iron" at the same time.

    And in case something goes wrong, you'll loose like one stack instead of huge amounts

    The stuff that belongs to the sorting player can be instantly placed.

    This idea is just a workaround, but a slowly sorting station is far better then a not-sorting one
     
    Last edited by a moderator: Oct 9, 2014
  26. tyrsis

    tyrsis Junior Engineer

    Messages:
    862
    New version is out v0.1.0.5:
    - Added the ability to use the Split operator. This allows you to split items between other blocks that are also marked with the Split operator.
    - Added the ability to use the Priority operator. This allows you to set priority of blocks to be higher than other blocks. Higher priority blocks will pull from any block with lower priority than itself, even if that block is marked to pull the same items. Blocks with no priority are considered to have the lowest priority. 1 is the highest priority.
    - Added the ability to combine multiple operators and use them at the same time. So you can use Split, Priority and MaxCount all together. For example: [Component:Split:p10:10000] will split components with other priority 10 blocks, and only pull until it has 10000 of each component.
    - Implemented some performance fixes that should basically hide or mask any sort intermittent lag that people are experiencing as a result of a sort pass. Please report if this is causing issues though.
     
  27. TheDeinonychus

    TheDeinonychus Trainee Engineer

    Messages:
    89
    still hoping this will work for ejectors and connectors soon. I'd love to be able to filter stone out of my mining ship as I mine to save on cargo space for more useful materials.
     
  28. gladi099

    gladi099 Apprentice Engineer

    Messages:
    183
    you should be able to do that just fine with a little work around.

    cargo container dont count as conveyors, so if you put a cargo container, then the connector, you can fill up the cargo container with just stone and have the connector set to collect all and throw out.
    that way it should only pull from the connecto cargo container containing only stone.
     
  29. tyrsis

    tyrsis Junior Engineer

    Messages:
    862
    New version v0.1.0.6:
    - Connectors can now pull inventory. Eject your garbage! You can't sort through connectors to other ships quite yet though.
    - Another small performance improvement.
    - Ability to sort even if you're not the majority owner of a ship/station.
     
  30. sectoid

    sectoid Trainee Engineer

    Messages:
    60
    This makes me feel all warm and fuzzy inside :comp:
     
Thread Status:
This last post in this thread was made more than 31 days old.