Event on_entity_logistic_slot_changed not always triggered

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
binaryDiv
Burner Inserter
Burner Inserter
Posts: 6
Joined: Mon Jan 27, 2025 12:44 pm
Contact:

Event on_entity_logistic_slot_changed not always triggered

Post by binaryDiv »

Hi!

For my mod Find Unfiltered Storage Chest I need to know when the filter of a Storage Chest has changed, so that I can update whether a warning should be shown for the chest.

When the filter is changed by a player via the entity GUI, this triggers the event `on_entity_logistic_slot_changed`. However, there are several other cases where the filter is changed but the event is not triggered.

1. Copy-pasting the entity settings via shift-clicking. In that case I can work around it by listening for `on_entity_settings_pasted`, but it feels inconsistent that it doesn't trigger `on_entity_logistic_slot_changed` as well.

2. Overwriting the entity settings using a blueprint: Place a storage chest without filter. Then, create a blueprint of a storage chest WITH a filter, and place it on top of the first storage chest. The game will overwrite the entity settings and set the filter, but no event is triggered that indicates this change.
For this one I haven't found a workaround yet. The only event I can see in that case is `on_pre_build`, which doesn't contain any information apart from the position the player clicked at (which might not even correspond to the chest if the blueprint contains more entities).

3. Undo/redo of a "copy-entity-settings" action. The event data here is a bit more helpful, it contains the entity prototype and the entity position. However, it doesn't contain the *surface* of the entity, so my current workaround is to find every storage chest at the given position on every existing surface and update it. Works, but it's quite hacky. :/

4. (Another edge case that came to my mind might be when the filter is changed by a mod by writing to the `storage_filter` property. I haven't tested if this triggers the event, but my guess would be that it doesn't.)

So my request: Would it be possible to trigger the `on_entity_logistic_slot_changed` event in these cases (most importantly the 2. case)? Or is there some specific reason why this can't be reasonably done?

Thanks a lot in advance!
Rseding91
Factorio Staff
Factorio Staff
Posts: 14993
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Event on_entity_logistic_slot_changed not always triggered

Post by Rseding91 »

The main reason why this isn't done is the same reason most events don't exist: mods can break things during events and we have no way to verify they didn't, or the code/burden to verify they didn't is too large and we choose to not have the event.

An example:

Lets say I want to add an event when an item is added or removed from some inventory. Naively, I go to the item being added/removed code and add the event. Mod A subscribes to the event and during an inserter putting an item into an assembling machine it is run. In the event mod A decides that it wants to change the recipe on the assembling machine. The event returns and the inserter code trying to put the item into the assembling machine is now iterating an inventory that doesn't exist and the game crashes to desktop.
If you want to get ahold of me I'm almost always on Discord.
binaryDiv
Burner Inserter
Burner Inserter
Posts: 6
Joined: Mon Jan 27, 2025 12:44 pm
Contact:

Re: Event on_entity_logistic_slot_changed not always triggered

Post by binaryDiv »

Thanks for the quick reply and the explanation.

I understand that with this in mind it's not reasonable to implement every event that someone requests for a relatively specific use case.

I'm wondering if a more generic event would be a good idea, which is raised *after* the settings of an entity have been modified by a blueprint (not during, but after). I can imagine that this could be helpful to many other mods as well.

My naive assumption would be that when the settings of an entity are overwritten by placing a blueprint of the same entity type on it, that this only changes the entity settings, and therefore shouldn't be too different from the player changing it manually (which does raise an event in the case of storage chest filters). But of course I (sadly) don't have any insight on the technical details of how this is implemented, so I can imagine there's a lot of potential edge cases that make it more difficult than it sounds. 😅
Muche
Filter Inserter
Filter Inserter
Posts: 911
Joined: Fri Jun 02, 2017 6:20 pm
Contact:

Re: Event on_entity_logistic_slot_changed not always triggered

Post by Muche »

A "solution" could be to make all API calls read-only during those critical events.
But then I am not sure how useful it would be to get notified of an event and not able to do anything (apart from taking a note of it in some local storage).
Post Reply

Return to “Modding interface requests”