Custom entity lua state handling in blueprints.
Custom entity lua state handling in blueprints.
It is easy to come up with a modded entity, that may have some lua information assotiated to it, the recently discussed inserter with filters defined by network.
Sometimes, a certain state of such associated data may be required for the layout to work, for example a table of conditions of the above mentioned network inserter.
Thus it would be nice to have a set of events on_blueprint_created, on_blueprint_placed, on_blueprint_cleared which should provide the unique identifier of blueprint layout and the ability to inspect the entities used in layout creation, so that modders could handle the templating of their entities themselves. Or maybe other mechanism of storing the associated data in blueprints, so that it would be accessible in a special field of a ghost entity.
Sometimes, a certain state of such associated data may be required for the layout to work, for example a table of conditions of the above mentioned network inserter.
Thus it would be nice to have a set of events on_blueprint_created, on_blueprint_placed, on_blueprint_cleared which should provide the unique identifier of blueprint layout and the ability to inspect the entities used in layout creation, so that modders could handle the templating of their entities themselves. Or maybe other mechanism of storing the associated data in blueprints, so that it would be accessible in a special field of a ghost entity.
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
I also update mods, some of them even work.
Recently I did a mod tutorial.
Re: Custom entity lua state handling in blueprints.
Really great idea, and necessary if we want mods to be able to provide "first-class entities" in Factorio.
Maybe when a blueprint is created, on_blueprint_created could be called for each entitity in the blueprint, and the return value of that function should be a table (or nil, if nothing needs to be saved), which would be associated to that entity in the created blueprint. Then when the blueprint is placed, on_blueprint_placed would be called for each entity, with the stored table (if any) passed back as a parameter.
Actually this isn't exactly right because we place ghosts with the blueprint and we want to restore the data to the actual constructed entity, but the main idea is that each entity can decide for itself what data it wants to store in the blueprint and how to restore it upon construction.
Maybe when a blueprint is created, on_blueprint_created could be called for each entitity in the blueprint, and the return value of that function should be a table (or nil, if nothing needs to be saved), which would be associated to that entity in the created blueprint. Then when the blueprint is placed, on_blueprint_placed would be called for each entity, with the stored table (if any) passed back as a parameter.
Actually this isn't exactly right because we place ghosts with the blueprint and we want to restore the data to the actual constructed entity, but the main idea is that each entity can decide for itself what data it wants to store in the blueprint and how to restore it upon construction.
Re: Custom entity lua state handling in blueprints.
just the events, with a read/write copy of the entities table of the blueprint, so it metadata can be added (in create), or applied to the ghosts (in place).
For on_robot_built events, you could add a field to the event containing the ghost, assuming this isn't already the case (don't remember the wiki saying anything about it but haven't actually checked, either)
Definitely a good idea, would provide a capability we will ultimately need one way or the other (copying custom settings and states on mod entities via blueprints) and my gut says it wouldn't be too much work on the dev's end.
For on_robot_built events, you could add a field to the event containing the ghost, assuming this isn't already the case (don't remember the wiki saying anything about it but haven't actually checked, either)
Definitely a good idea, would provide a capability we will ultimately need one way or the other (copying custom settings and states on mod entities via blueprints) and my gut says it wouldn't be too much work on the dev's end.
My Mods:
Nixie Tubes - numeric displays for your circuit networks!
Logistic Combinators - use logistics values in circuit logic! -
Autowire - automate red/green wire connections
Nixie Tubes - numeric displays for your circuit networks!
Logistic Combinators - use logistics values in circuit logic! -
Autowire - automate red/green wire connections
-
- Manual Inserter
- Posts: 3
- Joined: Fri Jul 22, 2016 7:27 am
- Contact:
Re: Custom entity lua state handling in blueprints.
My proposal for the addition of blueprint custom data would be like so:
- Ghost entities have two new fields and
Code: Select all
blueprint_id
Code: Select all
blueprint_entity_id
- Blueprint data can not only be accessed via the item, but created blueprints can be accessed through a This is a table mapping blueprint_ids to blueprint data (name, entities, etc) - see the LuaItemStack section of the Factorio Lua APIl
Code: Select all
game.blueprint_data
-
3 new events, all with blueprint_id field:
- Blueprint creation event: Called when a blueprint is created, this contains a field blueprint_entity_id_map, mapping blueprint_entity_ids to entities in the real world.
- Blueprint placement event: Called when a blueprint is placed.
- Blueprint destruction event: Called when a blueprint is deleted or modified.
- When a blueprint is placed, the ghost images get blueprint_id assigned to the bluprint_id of the blueprint they were created from, and blueprint_entity_id is assigned to the blueprint_entity_id of the entity that it was based on when the blueprint was created.
-
- Fast Inserter
- Posts: 153
- Joined: Fri Jan 06, 2017 1:54 am
- Contact:
-
- Fast Inserter
- Posts: 153
- Joined: Fri Jan 06, 2017 1:54 am
- Contact:
Re: Custom entity lua state handling in blueprints.
Will this ever be implemented?
Re: Custom entity lua state handling in blueprints.
I don't know what's really being asked for. There are several things here that conflict with each other in utility and some that just aren't feasible.thelordodin wrote:Will this ever be implemented?
If you want to get ahold of me I'm almost always on Discord.
-
- Fast Inserter
- Posts: 153
- Joined: Fri Jan 06, 2017 1:54 am
- Contact:
Re: Custom entity lua state handling in blueprints.
It's all aboutRseding91 wrote:I don't know what's really being asked for. There are several things here that conflict with each other in utility and some that just aren't feasible.thelordodin wrote:Will this ever be implemented?
A lua value field is needed on entities. This field must be preserved with the entity if it in blueprint or a ghost.It is easy to come up with a modded entity, that may have some lua information assotiated to it
Literally I mean:
constant_combinator1.custom_data['mod1'] = ...
And custom_data is a lua table on every entity.
Re: Custom entity lua state handling in blueprints.
I see. Unfortunately something like that isn't feasible as the performance and memory usage trade off would be too large.
If you want to get ahold of me I'm almost always on Discord.
-
- Fast Inserter
- Posts: 153
- Joined: Fri Jan 06, 2017 1:54 am
- Contact:
Re: Custom entity lua state handling in blueprints.
Lackily we now have an ability to save value in programmable speaker's alert message.
I just got this idea and tested if it's able to store 1 Mb string: yes It is!
And it's preserved in blueprints.
So now mods can really store any info in it.
I hope it wouldn't be limited in short while?
I just got this idea and tested if it's able to store 1 Mb string: yes It is!
And it's preserved in blueprints.
So now mods can really store any info in it.
I hope it wouldn't be limited in short while?
- eradicator
- Smart Inserter
- Posts: 5207
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Custom entity lua state handling in blueprints.
How feasible would it be to have a callback when an entity is blueprinted, something like:Rseding91 wrote:I see. Unfortunately something like that isn't feasible as the performance and memory usage trade off would be too large.
- An entity is added to a blueprint and the game raises on_entity_blueprinted, containing event.entity = (the entity blueprinted)
- A modder can register a function to on_entity_blueprinted like to any other event. But for this event the function can return a table (most likely something copied from the mods lua instance global table) that the modder wants to be saved to the blueprint for that entity.
- ???
- The player places a blueprint in the world.
- The game raises on_entity_built with an additional element event.mod_data which contains the table that was originally returned by the handler function and stored in the blueprint.
- The modder can do whatever he needs to the newly created ghost using the data from the table.
[feasible/unfeasible] [might eventually happen/ain't gonna happen]?
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
-
- Filter Inserter
- Posts: 587
- Joined: Sun Jun 09, 2019 10:40 pm
- Contact:
Re: Custom entity lua state handling in blueprints.
I got annoyed by my AttachNotes data not carrying over, so I point you to this post with a library to save arbitrary and unlimited data in blueprints. It uses the msgpack binary format to encode (a limited subset of) data compactly with bit swizzling, and then stores it 32 bits at a time in a constant combinator with signals.
This allows a reasonably unlimited amount of data storage - it defines a 500 slot combinator, or 2000 bytes of data. msgpack overhead is pretty close to zero - 1-2 bytes for a single string - and this allows arbitrary tables, not just strings. Trivially extensible to unlimited data with the addition of a "sequence" and/or "entity" label in signals.
If you wanted to make regrettable life choices you could apply the same thing to simply encode a string in one-or-more combinators.
Also potentially applicable is the fact you can export an item stack entity (eg: blueprint, item-with-tags) as a blueprint string (ie: zlib compressed, base64 encoded) so you could use that to pack your arbitrary (or string) data prior to injecting it into the signal fields.
This allows a reasonably unlimited amount of data storage - it defines a 500 slot combinator, or 2000 bytes of data. msgpack overhead is pretty close to zero - 1-2 bytes for a single string - and this allows arbitrary tables, not just strings. Trivially extensible to unlimited data with the addition of a "sequence" and/or "entity" label in signals.
If you wanted to make regrettable life choices you could apply the same thing to simply encode a string in one-or-more combinators.
Also potentially applicable is the fact you can export an item stack entity (eg: blueprint, item-with-tags) as a blueprint string (ie: zlib compressed, base64 encoded) so you could use that to pack your arbitrary (or string) data prior to injecting it into the signal fields.