LuaEntity::inserters (or some such to get all inserters and/or loaders targeting this entity)
- protocol_1903
- Filter Inserter
- Posts: 344
- Joined: Fri Sep 09, 2022 4:33 pm
- Contact:
LuaEntity::inserters (or some such to get all inserters and/or loaders targeting this entity)
As in title, I would like a way to get all of the inserters and/or loaders that target a specific entity, mainly inserters. It is already possible to do this by checking in an area around the entity, then checking if the pickup_target or drop_target match that entity. That's intensive, though, and rather hard to calculate a search area since mods can make inserters really long. I believe that the engine already has access to this information, or at least can do a lot more optimized search pattern than a mod could do in lua.
If you need to reach me, message me on discord.
I make qol mods. Check them out, maybe.
https://mods.factorio.com/user/protocol_1903
If you have a mod idea, I can look into it.
I make qol mods. Check them out, maybe.
https://mods.factorio.com/user/protocol_1903
If you have a mod idea, I can look into it.
Re: LuaEntity::inserters (or some such to get all inserters and/or loaders targeting this entity)
Considering my understanding is that an entity "wakes up" the inserters around it, I would assume this information is already available in some form.
Don't know how convertible to an api field that is though
Don't know how convertible to an api field that is though
- protocol_1903
- Filter Inserter
- Posts: 344
- Joined: Fri Sep 09, 2022 4:33 pm
- Contact:
Re: LuaEntity::inserters (or some such to get all inserters and/or loaders targeting this entity)
I assume it wouldn't be too difficult to wrap into a function that returns a table of LuaEntities
If you need to reach me, message me on discord.
I make qol mods. Check them out, maybe.
https://mods.factorio.com/user/protocol_1903
If you have a mod idea, I can look into it.
I make qol mods. Check them out, maybe.
https://mods.factorio.com/user/protocol_1903
If you have a mod idea, I can look into it.
Re: LuaEntity::inserters (or some such to get all inserters and/or loaders targeting this entity)
Closest data available would be a list of all entities for which LuaEntity::drop_target returns that specific entity, effectively a reverse lookup. This data is obtainable.
My main concern here is that modders may start reporting such reverse lookup as innacurate if they would create for example an inserter and expect that it will be immediately visible through such read when this would not be the case: inserter only looks for the drop target during update, so when it is not updated since entity was just created, or because it is unable to update (for example because entity is marked to be deconstructed or because it is a ghost) it would not be visible through this reverse lookup. Other entities would appear when different conditions are met (mining drill looks for drop target when it wants to drop an item, or when it is rotated, crafter will look for drop target during update when there are items in the output inventory, or when it is rotated). If this would be expected to work instantly (when script creates one entity, second entity would report it as being able to feed items) or to also work with ghosts, then this feature would be rejected just because this query would require to visit every entity in game because inserters with custom drop vector can have them set to be literally anything (at least when changing drop vectors at runtime).
My main concern here is that modders may start reporting such reverse lookup as innacurate if they would create for example an inserter and expect that it will be immediately visible through such read when this would not be the case: inserter only looks for the drop target during update, so when it is not updated since entity was just created, or because it is unable to update (for example because entity is marked to be deconstructed or because it is a ghost) it would not be visible through this reverse lookup. Other entities would appear when different conditions are met (mining drill looks for drop target when it wants to drop an item, or when it is rotated, crafter will look for drop target during update when there are items in the output inventory, or when it is rotated). If this would be expected to work instantly (when script creates one entity, second entity would report it as being able to feed items) or to also work with ghosts, then this feature would be rejected just because this query would require to visit every entity in game because inserters with custom drop vector can have them set to be literally anything (at least when changing drop vectors at runtime).
- protocol_1903
- Filter Inserter
- Posts: 344
- Joined: Fri Sep 09, 2022 4:33 pm
- Contact:
Re: LuaEntity::inserters (or some such to get all inserters and/or loaders targeting this entity)
Is the issue that inserters would not be immediately visible, or that entities that eventually are a target don't know this so they have no visible reverse lookups, or both?
I would be fine with just-created inserters not being valid reverse lookup targets, my main focus is having just-created entities having valid reverse lookup targets
I would be fine with just-created inserters not being valid reverse lookup targets, my main focus is having just-created entities having valid reverse lookup targets
If you need to reach me, message me on discord.
I make qol mods. Check them out, maybe.
https://mods.factorio.com/user/protocol_1903
If you have a mod idea, I can look into it.
I make qol mods. Check them out, maybe.
https://mods.factorio.com/user/protocol_1903
If you have a mod idea, I can look into it.
Re: LuaEntity::inserters (or some such to get all inserters and/or loaders targeting this entity)
A "just created" entity would report empty list of entities in the reverse lookup just because other entities were not updated yet and so this new entity would not be a drop target of any entity yet. You can verify this right now by creating an entity and then iterating over all entities on the surface and checking which of then are reporting your entity through LuaEntity::drop_target read - there will be a delay of when this is updated (if this is updated at all).