I made this mod because the behave of inserter in vanilla does not match my favoured way to build my train network. So, I searched for mods to fulfill my goal but could not find any mod matching. Either there are much more functions included in the mod that I don’t want or the mod was not compatible with the current game version (0.17). I decided to try to write my own mod. I present the result here.
My first goal was to clean inserters at train stations. As there are other situations with stuck inserters, too, I tried to include these inserters also. As result Picklocks Inserters works as follows:
Items will be put back to where they were picked up.
You can enable to unlock locked chest slots to put items back even to chests that are normally stuffed.
You can also enable to destroy items in the hand of an inserter if the inserter is not able to put the items back. If you don’t enable this function and the inserter could not put the items back the inserter will stay stuck with items in hand.
With the inserter cleanup planner, you could select any inserter you want to be cleaned.
If enabled the selected inserters will be cleaned up permanently.
To visualize selected inserters, you can enable to mark them (this affects only inserters marked with the inserter cleanup planner).
If enabled inserters around cargo wagons at train stations will be cleaned when the train leaves the train station. Therefore, the train hast to enter and leave the train stop in "automatic" mode (do not change to "manual" mode in between). The check will be done for the areas on both sides of every cargo wagon connected to the train. Cargo wagons which are not aligned horizontally or vertically will be skipped even if loading / unloading is possible.
+++++++
Known Issues
There aren’t any open issues.
+++++++
When you find a problem, post it below and I will add it to the list of issues to be dealt with when possible. For more detailed discussions you can always send me a PM. As I’m not always online it may take a while till you get a response. I will consider the posts or issues I see, and do my best to work fixes into the mod, although I might not reply directly to every notice.
+++++++
Regarding bugs, hopefully there will be few crashes and loading failures. I have solved all of these that I found by my local testing. Interaction with other mods is almost wholly untested.
+++++++
Abbreviated changelog
Version: 2.1.0
Date: 27.11.2024
Features:
Belt added as a destination for returning items.
Graphics:
Updated shortcut icon and increased its size to 56px.
First, I want to thank the Factorio team for making such an amazing game. Its my favorite game at the moment.
Also, thanks to the various mods regarding inserters out there, for having interesting ideas.
+++++++
A Note:
In making this mod, I tried my best to work with the base assets and my own custom code. But it is possible that I missed something like a copied placeholder. If you find something that should not be there, please tell me explaining what it is, and I will try to rectify the matter as soon as possible.
Re: [MOD 0.17] Picklocks Inserter
Posted: Wed Dec 25, 2019 7:36 pm
by picklock
Added the following reportet issues to start post.
When crafting something it will cycle each item through your hand (cursor).
Anything you craft is automatically duplicated, producing 2 of the crafted item.
I will have a look at it and if possible will fix it as soon as possible.
Re: [MOD 0.17] Picklocks Inserter
Posted: Wed Dec 25, 2019 11:17 pm
by PyroFire
found a typo; "if debug then"... always returns true, debug is a special lua library / keyword.
This appears twice in your control.lua https://www.lua.org/pil/23.html
Also, why do you need to hook on_player_crafted_item at all?
It seems you are doing this just to be buggy for the sake of being buggy.
There is no apparent gain for hooking this event or taking any actions in it.
Though another typo, coincidentally in said on_player_crafted_item, is that you're checking if(cursor_stack.can_set_stack)then.
That is a function, and therefore your condition will always return true because you're just checking if the function exists.
Calling it without args also only returns true if you can clear the cursor stack.
You should be using cursor_stack.can_set_stack(event.item_stack).
Secondly, you're placing a copy of the crafted item in the cursor.. why?
Basically all of those problems can be avoided by .. not hooking on_player_crafted_item for literally no reason.
Aside from that (and the fact that there's probably a few more typos similar to above), seems like the only real way to fix the problem.
But damn that's expensive doing it 25 times per tick. 10 maybe better.... but some bases can have literal thousands of inserters.
This may be better of simply being fixed in a mod than being worked around in a mod. viewtopic.php?f=29&t=74900
Though... if you're looking for another thing to hotfix with a mod like this...
Did you know that you actually lose the ingredients of a recipe in a machine if you pick it up while it is crafting?
They vanish without a trace
Re: [MOD 0.17] Picklocks Inserter
Posted: Thu Dec 26, 2019 7:09 am
by Bilka
PyroFire wrote: Wed Dec 25, 2019 11:17 pm
Though... if you're looking for another thing to hotfix with a mod like this...
Did you know that you actually lose the ingredients of a recipe in a machine if you pick it up while it is crafting?
They vanish without a trace :(
Fixed the reported issues with V1.0.1. See start post for details.
@PyroFire :
Thanks for your Post.
You were right, I didn’t need the event on_player_crafted_item. I do not use it anymore. This was a part of fixing the reported issues and avoids other misbehaviours.
As well as I did not have any performance issues testing my mod with my big base, I agree with you, that cleaning 25 inserters per tick is expensive and might generate performance issues. Therefore, I followed your suggestion and reduced the default setting for cleaning per tick to 10.
In my opinion my mod is not intended to clean all inserters of a base permanently. You mark only the inserters you want to clean or you activate the cleaning at train stops. So, even if there are thousands of inserters in a base only a few will be cleaned.
Re: [MOD 0.17] Picklocks Inserter
Posted: Wed Jan 22, 2020 12:17 pm
by picklock
Updated mod for game version 0.18 with V1.18.0.
Re: [MOD 0.17 - 0.18] Picklocks Inserter
Posted: Mon Feb 17, 2020 6:31 pm
by picklock
Released V1.18.1:
Due to performance reasons added a delay of 120 ticks for inserters marked by cleanup planer before it will be cleared again after it was successful cleared.
Re: [MOD 0.17 - 1.0] Picklocks Inserter
Posted: Wed Aug 26, 2020 8:14 am
by picklock
Updated mod for game version 1.0 with V1.18.2.
Desync cause
Posted: Thu Oct 22, 2020 1:33 am
by Yuri
My server has been plagued by desyncs lately and this mod appears to be the primary suspect. The scripts.dat files have several instances of desynced values related to it. The desync logs will sometimes have other mods but almost always this one.
Capture.PNG (72.43 KiB) Viewed 7160 times
Edit: Did some more testing and confirmed that this mod is the culprit. Loaded from an autosave and player desynced at the same time every time until the mod was removed and then it stopped happening.
If there's any reports or anything you need me to provide to debug I'll gladly help
Re: [MOD 0.17 - 1.0] Picklocks Inserter
Posted: Thu Oct 22, 2020 5:57 am
by picklock
Hello Yuri,
Thank you for the report.
I will have a look at it. If I need any further information I will contact you.
Edit:
I was not able to reproduce the issue with my testing enviroment. I sent Yuri a PM.
My guess is your cleaning loop isn't happening in a predictable order.
I.e. you're using a local variable instead of a global to save/pause/resume the inserter scanner at different "positions" in the table, thus resulting in a desync when items are removed from different inserters for different people at different times.
I haven't checked it but this would be a common desync with this kind of code.
Re: [MOD 0.17 - 1.0] Picklocks Inserter
Posted: Thu Nov 05, 2020 11:54 am
by picklock
First of all, I want to thank PyroFire for the reply and the guess.
In the last days I did a lot of testing. The desync occurs only with the map from Yuri. I tested also with two more maps, also with several hundreds of hours played and one of them also heavy modded and with these maps there was no desync.
The desync in Yuris map happens with the following line of code:
The desync occurs also when the variable that stores the inserter information is set to global as mentioned by PyroFire.
As the desync only occurs with Yuris map I assume that there is one of the over 90 Mods from the map not compatible with my mod or there is a problem with the map itself. Why the issue occurs after more the 300 hours of playtime is a strange behavior for me.
Does anyone has an idea why there is a desync with the code line above other than my assumption?
[MOD 1.1] Picklocks Inserter
Posted: Mon Nov 23, 2020 10:22 pm
by picklock
Updated mod for game version 1.1 and made some minor internal changes with V1.110.0.
See start post for details.
[MOD 1.0 - 1.1] Picklocks Inserter
Posted: Mon Nov 30, 2020 2:39 pm
by picklock
Fixed mulitplayer desync related to imserters selected with the inserter cleanup planner.
See startpost for details.
Please be aware that there are different versions for Factorio V1.0 and Factorio V1.1.
For Factorio V 1.0 use mod version 1.100.1
For Factorio V 1.1 use mod version 1.110.1
[MOD 1.0 - 1.1] Picklocks Inserter
Posted: Sat Dec 05, 2020 8:21 pm
by picklock
Fixed a bug that after loading a game, a mark was not deleted if the associated inserter was destroyed.
See startpost for details.
Please be aware that there are different versions for Factorio V1.0 and Factorio V1.1.
For Factorio V 1.0 use mod version 1.100.2
For Factorio V 1.1 use mod version 1.110.2
Re: [MOD 0.17 - 1.1] Picklocks Inserter
Posted: Sun Dec 06, 2020 3:16 pm
by picklock
Fixed a non-recoverable error occouring in some circumstates when starting a new game or loading a savegame.
See startpost for details.
Please be aware that there are different versions for Factorio V1.0 and Factorio V1.1.
For Factorio V 1.0 use mod version 1.100.3
For Factorio V 1.1 use mod version 1.110.3
Re: [MOD 1.1] Picklocks Inserter
Posted: Wed Feb 03, 2021 10:39 am
by picklock
Update V1.110.4 for Factorio V1.1:
- Fixed a bug that prevented the cleaning of the inserters if the train was in the "destination_full" status after leaving the station.
- Fixed a bug that prevented the cleaning of the inserters if the train was in the "wait_signal" status after leaving the station.
See start post for details.
Re: [MOD 1.1] Picklocks Inserter
Posted: Tue Feb 07, 2023 2:34 pm
by picklock
Update V1.110.5 for Factorio V1.1:
- Added cargo-wagon as target for set back (applies only to inserter cleanup planner).
Added cargo-wagon as additional target for set back. This works only with the inserter cleanup planner an not with the setting clean up inserters at train stops
See start post for details.
Re: [MOD 1.1] Picklocks Inserter
Posted: Wed Mar 01, 2023 12:30 pm
by picklock
Update V1.110.6 for Factorio V1.1:
- Fixed a bug causing a non-recoverable error with the event on_runtime_mod_setting_changed.
See start post for details.
Re: [MOD 1.1] Picklocks Inserter
Posted: Thu Mar 07, 2024 6:04 pm
by picklock
Update V1.110.7 for Factorio V1.1:
Date: 07.03.2024
Bugfixes:
- Fixes a bug causing a non-recoverable error on the client and the server when a player joins a headless server.
Optimisations:
- For performance reasons, the maximum number of inserters that can be cleaned per tick has been reduced from 120 to 30.
Locale:
- Updated and tweaked language files.