How to most-UPS-friendly check how much of a stack would be insertable into an inventory
Posted: Sat Dec 07, 2019 3:29 am
I know about can_insert but it only tells me whether at least one item could be inserted. I need to know how much items of a stack could be inserted.
I don't actually want to insert the stack into the target inventory at the time i want to know how much could be inserted (need it for controlling the pickup of a scripted inserter that never gets clogged when used as only inserter feeding a target).
My ideas so far:
- Perform an insert, store the returned amount and immediately remove the inserterted items (insert and remove are probably heavily optimized, but does not feel right somehow).
- Iterate over the content of the target inventory and count for each stack how much of the potential stack could be added (sounds slow, but there is a high probability, that all the target inventories will only have 1 to 3 slots, so the O(N) looks a lot like O(1) to me).
I don't actually want to insert the stack into the target inventory at the time i want to know how much could be inserted (need it for controlling the pickup of a scripted inserter that never gets clogged when used as only inserter feeding a target).
My ideas so far:
- Perform an insert, store the returned amount and immediately remove the inserterted items (insert and remove are probably heavily optimized, but does not feel right somehow).
- Iterate over the content of the target inventory and count for each stack how much of the potential stack could be added (sounds slow, but there is a high probability, that all the target inventories will only have 1 to 3 slots, so the O(N) looks a lot like O(1) to me).