Metadata on Entities
Posted: Sun Aug 04, 2024 4:39 pm
Original post in "Modding Help": viewtopic.php?f=25&t=114167&p=615620#p615620 that I'm reposting here.
Similar request for Items: viewtopic.php?f=221&t=5851&p=45281&hili ... ata#p45281 that is in "Won't Implement".
Hi,
I'm developing a mod that stores additional metadata on some new entities. For example, I need to store the list of item requests associated with my custom chest entity.
I'm currently doing the "standard" approach used by many other mods like SE where I have a table in global that maps from unit_number to metadata. I also have some helper code that stores the metadata to and from blueprints.
While this approach works for copy/paste, it:
- Requires a lot of boilerplate code
- Doesn't work when pasting blueprints over existing entities
- Doesn't work with undo
I've been blown away by the high quality of modding docs and the lua APIs so this current workaround feels uncharacteristically difficult to implement.
Is there a better way to store custom metadata on entities?
If not, I can think of a few potential approaches that would make it a ton easier to build mods with custom entities.
One approach would be to add an optional "metadata" field to LuaEntity that is persisted across all copy/paste/undo actions. This field ideally would be able to store any custom Lua object that can be serialized in a blueprint.
Another approach I can think of is tags. While tags currently only seem to be supported on ghosts, it would be interesting to see if they could also be supported for normal entities. I'm not sure if there's any additional overhead associated with tags that need to be serialized to blueprints, but it would be amazing if this were possible.
I'm not familiar with the Factorio source code or appetite to make a change like this with all the work on the expansion, but this one change would both remove buggy boilerplate and fix annoying bugs with current implementations for a significant number of mods.
Thanks for your time!
Similar request for Items: viewtopic.php?f=221&t=5851&p=45281&hili ... ata#p45281 that is in "Won't Implement".
Hi,
I'm developing a mod that stores additional metadata on some new entities. For example, I need to store the list of item requests associated with my custom chest entity.
I'm currently doing the "standard" approach used by many other mods like SE where I have a table in global that maps from unit_number to metadata. I also have some helper code that stores the metadata to and from blueprints.
While this approach works for copy/paste, it:
- Requires a lot of boilerplate code
- Doesn't work when pasting blueprints over existing entities
- Doesn't work with undo
I've been blown away by the high quality of modding docs and the lua APIs so this current workaround feels uncharacteristically difficult to implement.
Is there a better way to store custom metadata on entities?
If not, I can think of a few potential approaches that would make it a ton easier to build mods with custom entities.
One approach would be to add an optional "metadata" field to LuaEntity that is persisted across all copy/paste/undo actions. This field ideally would be able to store any custom Lua object that can be serialized in a blueprint.
Another approach I can think of is tags. While tags currently only seem to be supported on ghosts, it would be interesting to see if they could also be supported for normal entities. I'm not sure if there's any additional overhead associated with tags that need to be serialized to blueprints, but it would be amazing if this were possible.
I'm not familiar with the Factorio source code or appetite to make a change like this with all the work on the expansion, but this one change would both remove buggy boilerplate and fix annoying bugs with current implementations for a significant number of mods.
Thanks for your time!