Any chance "export_stack" API will handle any LuaItemStack?

Place to get help with not working mods / modding interface.
User avatar
freeafrica
Long Handed Inserter
Long Handed Inserter
Posts: 65
Joined: Mon Aug 19, 2019 2:33 pm
Contact:

Any chance "export_stack" API will handle any LuaItemStack?

Post by freeafrica »

I would love to use `LuaItemStack:export_stack` call in my mod, to move around items from a massive amount of belts keeping stacks unchanged with same position, however it only covers items that have the ingame "export" functionality.

Currently I am using `get_detailed_contents` on the belt, to keep stacks unchanged, I use `transfer_stack` call. However, that makes all previous stacks (returned by the `get_detailed_contents` method) invalid... so I need to recall it for each stacks left on the belt. This scales up quite badly w/ many belts and items on them...

If there would be some serialize call on `LuaItemStack` I could just save that together with stack-belt-positions, hitting the game-API only once for the `get_detailed_contents`, then empty the whole belt and reimport.

Inserting happens one-by-one too (using the game-API), so I guess it would still not change the order-of-magnitude, just the `get_detailed_contents` feels like a more expensive method, not sure though.
- nerf landmines, bots
- change infinite resources (solar, space-mining, etc...)
Rseding91
Factorio Staff
Factorio Staff
Posts: 17498
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Any chance "export_stack" API will handle any LuaItemStack?

Post by Rseding91 »

What are you actually trying to do? “Get detailed contents” can be used backwards to move entire lines. Or if you just want a copy then clone the belt. If you want a new belt at the same position then fast replace it.
If you want to get ahold of me I'm almost always on Discord.
User avatar
freeafrica
Long Handed Inserter
Long Handed Inserter
Posts: 65
Joined: Mon Aug 19, 2019 2:33 pm
Contact:

Re: Any chance "export_stack" API will handle any LuaItemStack?

Post by freeafrica »

Rseding91 wrote: Wed Aug 26, 2026 11:01 pm “Get detailed contents” can be used backwards to move entire lines. Or if you just want a copy then clone the belt.
Thanks for your suggestion <3, iterating from the back helped for me. I am surprised, cause I've read the following on LuaItemStack:
In the instance this references an item on a LuaTransportLine the reference is only guaranteed to stay valid (and refer to the same item) as long as nothing changes the transport line.
And I've received this error when naively iterating over the result and calling `transfer_stack` on the given item, so I would've never guessed it helps to "do it from the back", because I've "changed" the transport-line.
Rseding91 wrote: Wed Aug 26, 2026 11:01 pm If you want a new belt at the same position then fast replace it.
I've tried that too, but I need the "old" underground entrances to disappear, so I need to use `spill = false`, however in case of undergrounds if there are items in transit between the entrances, they disappear, so I cache-transfer them (see below).
Rseding91 wrote: Wed Aug 26, 2026 11:01 pm What are you actually trying to do?
My mod replaces undergrounds with a different prototype and I use `spill = false` on `create_entity` because I don't want to deal with the underground-entrances leftover, so before the replace, I am moving the full belt into a "virtual" inventory and after the replace, I `insert_at` from it one-by-one on the new belt. Any suggestions are welcome :)
- nerf landmines, bots
- change infinite resources (solar, space-mining, etc...)
Post Reply

Return to “Modding help”