Add item_stack to on_mod_item_opened

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Honktown
Smart Inserter
Smart Inserter
Posts: 1068
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Add item_stack to on_mod_item_opened

Post by Honktown »

It seems like the event is far less useful without having a specific thing being clicked on. I can understand there being conflicts with fungible items and opening in the hotbar, but if you wanted an item-with-tags, or a specific selection concept, or an item-with-inventory, you can't know which from the event.

Blueprint-like objects in the library can just be discarded for this event or not even raise, it would probably be a mess.
I have mods! I guess!
Link
majoca
Burner Inserter
Burner Inserter
Posts: 10
Joined: Sun Dec 20, 2020 8:50 pm
Contact:

Re: Add item_stack to on_mod_item_opened

Post by majoca »

+1, I'd appreciate this to be able to create something akin to a custom deconstruction planner. The player could create multiple instances of a selection-tool, each with their own data/settings which can be edited via a custom GUI that's opened by on_mod_item_opened. I can manage the per-item data with item_number, but as far as I can tell there is no way to determine which specific item instance was opened in on_mod_item_opened--just the prototype of the item.
Rseding91
Factorio Staff
Factorio Staff
Posts: 16584
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Add item_stack to on_mod_item_opened

Post by Rseding91 »

I could add it, however it's not going to be guaranteed accurate since the event can originate from literally any item in any stack. It may happen that slot [3] was clicked and is a simple iron plate. In the event for mod A, it clears the entire inventory putting power armor in all slots. Then mod B runs and is just going to get "slot [3]" which is power armor at that point.
If you want to get ahold of me I'm almost always on Discord.
User avatar
PennyJim
Fast Inserter
Fast Inserter
Posts: 157
Joined: Wed Jan 18, 2023 3:49 am
Contact:

Re: Add item_stack to on_mod_item_opened

Post by PennyJim »

Wouldn't it make sense to pass the item_number, if one exists? It wouldn't perfectly get the item that was opened since not all have them, but wouldn't it cover most cases where people actually care about the item, since it's usually those that have data tied to them?
majoca
Burner Inserter
Burner Inserter
Posts: 10
Joined: Sun Dec 20, 2020 8:50 pm
Contact:

Re: Add item_stack to on_mod_item_opened

Post by majoca »

item_number should be able to work just as well for my use case, if that would make more sense in general!
Rseding91
Factorio Staff
Factorio Staff
Posts: 16584
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Add item_stack to on_mod_item_opened

Post by Rseding91 »

PennyJim wrote: Tue Feb 17, 2026 12:07 am Wouldn't it make sense to pass the item_number, if one exists? It wouldn't perfectly get the item that was opened since not all have them, but wouldn't it cover most cases where people actually care about the item, since it's usually those that have data tied to them?
Item number only exists for complex item types. The event can be triggered by any type (basic iron plate with no data, thus no item number).
If you want to get ahold of me I'm almost always on Discord.
majoca
Burner Inserter
Burner Inserter
Posts: 10
Joined: Sun Dec 20, 2020 8:50 pm
Contact:

Re: Add item_stack to on_mod_item_opened

Post by majoca »

Rseding91 wrote: Tue Feb 17, 2026 1:02 am Item number only exists for complex item types. The event can be triggered by any type (basic iron plate with no data, thus no item number).
If the event were to pass item number, wouldn't it be fair to just pass nil for the basic items which don't have item numbers? As PennyJim said, that should cover most use cases.
Rseding91 wrote: Tue Feb 17, 2026 12:01 am I could add it, however it's not going to be guaranteed accurate since the event can originate from literally any item in any stack. It may happen that slot [3] was clicked and is a simple iron plate. In the event for mod A, it clears the entire inventory putting power armor in all slots. Then mod B runs and is just going to get "slot [3]" which is power armor at that point.
Also, forgive my minimal understanding of how all this works internally, but couldn't the item stack passed to the event (supposing you do implement that) just be the item stack that originated the on_mod_item_opened event in the first place? And sure, if some other mod completely destroys the item stack, then it would be invalid. The event does pass LuaItemPrototype data currently, and in your example, surely mod B is not getting passed the LuaItemPrototype for power armor. (If it is, then fair enough. Can't test it myself at the present moment.) So I'd imagine there must be some way to tie the event data back to the item that originally caused the event to fire.
Post Reply

Return to “Modding interface requests”