Page 1 of 1
copy-paste by blueprint should trigger an event
Posted: Sat Oct 29, 2022 8:19 pm
by mami
I would like blueprinting over an existing entity to trigger the "defines.event.on_entity_settings_pasted" event
https://lua-api.factorio.com/latest/eve ... ngs_pasted or otherwise it's own unique event. So for example, if I have two constant combinators with different settings, and I make a blueprint of one, and then I place the blueprint overtop the other, I've copy-pasted the settings from one combinator to the other. This operates the same as if I had used the entity copy-paste feature by shift-clicking, yet there is no event associated with it.
In this forum post on modding help we discuss how there isn't really a way to catch copy-paste by blueprint easily:
viewtopic.php?f=25&t=102702
The best method currently is to poll all of the relevant entities which isn't particularly UPS friendly.
Bizarrely enough
does prevent copy-paste by blueprint as well as normal copy-paste. This inconsistency makes me guess this is just an oversight and I hope a way to catch copy-paste by blueprint can be added.
Ideally the event lets us see what the settings of the LuaEntity are before and after pasting, but just having an event with the LuaEntity attached to it at all will open up a lot of previously UPS expensive possibilities.
My specific use case is in the creation of a "logistics-combinator" similar to a logistics-train-stop from the Logistics Train Network Mod. It needs to be registered on one of a series of global table based on its current settings for my logistics algorithm to work correctly. There is no work around that I can think of that does not either remove features from my mod, involve polling all logistics-combinators periodically, or cause unexpected and glitchy behavior.
Re: copy-paste by blueprint should trigger an event
Posted: Sun Jan 22, 2023 11:20 pm
by BinarySpike
I'm making a mod with signals that are treated as variables in a blueprint. Once the player updates the variables, they get resolved on the entities placed by the blueprint.
If the player uses "shift" and places the blueprint, there is currently no easy way to detect what buildings were updated.
My solution is, in
`defines.events.on_pre_build` to call
`surface.find_entities(area?)` on each blueprint entity's position—translated into real-world coordinate. Then, check them a tick later to see if they have my custom variables in them. Unfortunately, I'm still struggling with how to convert blueprint coordinates into real-world coordinates.
A
`defines.events.on_entity_settings_pasted` for each entity would work easily enough as I'm tracking bot, player, and revive builds between blueprint placement and GUI confirmation.
Ultimately, I'd love to see a
`defines.events.on_blueprint_placed` that has properties like
`placed_entities`,
`updated_entities`, and possibly even
`failed_entities`. (*edit
not likely to happen per-Rseding91 in multiple posts)
* Edit
Related/Similar posts:
Re: copy-paste by blueprint should trigger an event
Posted: Mon Jan 23, 2023 11:12 am
by ILLISIS
+1 for defines.events.on_blueprint_placed significant benefits could be gained using this in Constructron-Continued instead of using on_built_entity and processing every entity!
I would need a way to see the area and position of the blueprint and required items to place the entities. I do not need positions of the entities within the blueprint however.
Re: copy-paste by blueprint should trigger an event
Posted: Thu Jan 26, 2023 1:19 am
by BinarySpike
Would benefit this mod as well:

Re: copy-paste by blueprint should trigger an event
Posted: Sat Feb 18, 2023 12:10 pm
by SWeini
+1 for any kind of event after pasting over an existing entity (blueprint or copy&paste)
Also don't forget to include item tag data when pasting.
I'm playing around with an idea that involves adding tags to the blueprint entity when copying a specific building. Upon placement the item tags are moved to the ghost and upon ghost revival my script can act according to the tag data.
Unfortunately there is no way to react to the tag data when pasting over existing buildings.
Re: copy-paste by blueprint should trigger an event
Posted: Wed Apr 19, 2023 10:08 pm
by BlackOverlord
+1
I have some settings associated with entities which I store in the global table and in blueprint tags. Unfortunately, blueprint pasting is not working as there is no event fired when it happens.
Would be great to have such an event so mods could properly support regaular game features.
Re: copy-paste by blueprint should trigger an event
Posted: Wed Apr 26, 2023 5:50 pm
by GlassBricks
+1
Re: copy-paste by blueprint should trigger an event
Posted: Tue Jul 04, 2023 4:08 pm
by y_e_a_r
+1 to this, but would be even better to have a good solution to adding metadata to entities that plays nicely with blueprints.
Re: copy-paste by blueprint should trigger an event
Posted: Wed Jan 01, 2025 1:21 am
by BraveCaperCat
+1
Re: copy-paste by blueprint should trigger an event
Posted: Fri Jan 03, 2025 3:02 pm
by Rseding91
I would add this, but due to how blueprints are built I can't send Lua events in the middle of placing the blueprint because mods may invalidate the blueprint which will crash the game.
If anyone ever figures out a way to make it work without mods being able to crash the game then we'll add it.
Re: copy-paste by blueprint should trigger an event
Posted: Fri Jan 03, 2025 3:14 pm
by Rseding91
Additionally: I can't fire the normal "pre-pasted" and "settings_pasted" events because I can't push the blueprint entity as the source in those events. The entity is not in the map (it exists just in the blueprint) and would not be valid to have a LuaEntity reference to.
So if I did manage to make this work, it would be a new event and would only contain "this entity had its settings pasted while blueprint building". There would be no "pre" event because again, I can't guarantee a mod wouldn't mess with the blueprint during the event and thus mess with the blueprint entity that will be pasting the settings from.
Would that even be useful?
Re: copy-paste by blueprint should trigger an event
Posted: Fri Jan 03, 2025 3:23 pm
by robot256
Rseding91 wrote: Fri Jan 03, 2025 3:14 pm
So if I did manage to make this work, it would be a new event and would only contain "this entity had its settings pasted while blueprint building" - would that even be useful?
Yes, this would be extremely useful. For example, the Shortwave mod uses a dummy constant combinator to hold the channel selection. This makes it easy to store in blueprints. The mod only changes the script wires when events trigger, indicating the value in the dummy combinator changed. The new event would allow triggering when a blueprint modified the channels of an existing entity.
I'm aware that if I were to rewrite thos particular mod, I would probably use a custom GUI. storage table, and blueprint tags to store channel selection. That brings up another question for blueprints -- would I be able to tell that the blueprint included a tag on an entity that it pasted over top of? Is the solution to look at the blueprint record data itself and infer which parts overlap with already-built entities?
Re: copy-paste by blueprint should trigger an event
Posted: Fri Jan 03, 2025 4:03 pm
by curiosity
Rseding91 wrote: Fri Jan 03, 2025 3:14 pm
Would that even be useful?
Right now there isn't any indication that something happened at all. Anything will be useful at this point. Even if the event is not immediate, it would still be better than nothing.
If you can't pass a LuaEntity, pass what you can. Especially things that get lost in the process, like the aforementioned entity tags. Or maybe make a new LuaEntityOutsideMap type that allows for limited (even if just read-only) access (recipe, control behavior, other entity settings).
Re: copy-paste by blueprint should trigger an event
Posted: Mon Feb 03, 2025 6:07 pm
by hgschmie
Rseding91 wrote: Fri Jan 03, 2025 3:02 pm
I would add this, but due to how blueprints are built I can't send Lua events in the middle of placing the blueprint because mods may invalidate the blueprint which will crash the game.
If anyone ever figures out a way to make it work without mods being able to crash the game then we'll add it.
(feeling weird trying to explain to a developer about their own code...

)
The way I see it, a Blueprint is an ItemStack which in turn can provide a list of BlueprintEntity objects (get_blueprint_entities()). When it is "stamped down", each of those entities (or their equivalent from the ItemStack) is scheduled for construction by placing a ghost (which in turn receives the tags from the blueprint entity).
If in a place where a ghost is 'stamped down', a matching entity exists, then the current code already applies pieces from the Blueprint entity to the entity that exists (most likely the control behavior because e.g. an arithmetic combinator gets reconfigured when a blueprint is placed on top of it.
At this moment, fire an event (most likely a new event) that contains
- the BlueprintEntity that is about to be placed down
- the LuaEntity that exists in that spot
That way, a mod can receive that event. For my mods, I could now inspect the BlueprintEntity, pull out the tags (they represent the configuration of my custom entities) and apply that to the existing LuaEntity. So the "reconfigure when a blueprint is stamped down" would work for me.
I very much appreciate the concern that you voice about "blueprint modes may invalidate the blueprint". I am not sure how that would apply here, given that the process of "stamping down" currently fires no events. And even if firing during the "stamping down" is not possible, it should be doable to "collect" the information about BlueprintEntity / LuaEntity pairs and then fire those after the blueprint placement is complete.
(note that all of this comes from a very naive understanding on how blueprinting works as seen from the outside).
Re: copy-paste by blueprint should trigger an event
Posted: Tue Feb 04, 2025 4:27 pm
by protocol_1903
Seems weird that the only stopping point for implementation is mods being able to crash the game. If i understand correctly, then the only way a blueprint could be invalidated is if it's changed, right? So why not make the blueprint read-only, call it a LuaTemporaryBlueprint, so that players can get info from it but not override it.
Also, would it be crashing the game to desktop? Or just a crash to menu? If it's the latter, it should be up to the developer to not crash the game, but I presume that's not the case.
Re: copy-paste by blueprint should trigger an event
Posted: Tue Feb 04, 2025 4:32 pm
by Rseding91
Mods can access anything during a given event - regardless of what is passed in the event parameters.
During the event, a mod could go to the character and call player.character.cursor_stack.clear() which would instantly delete and invalidate the entire blueprint and all entities within it.
Re: copy-paste by blueprint should trigger an event
Posted: Tue Feb 04, 2025 4:40 pm
by protocol_1903
Then save the blueprint item to memory before calling pre_placed_blueprint and use that item regardless when actually placing the blueprint, which would keep it in line with most other events pre_ and on_ running regardless of script actions. Or add a nil check when placing the blueprint and crash to menu.
Re: copy-paste by blueprint should trigger an event
Posted: Tue Feb 04, 2025 5:36 pm
by curiosity
protocol_1903 wrote: Tue Feb 04, 2025 4:27 pm
Also, would it be crashing the game to desktop? Or just a crash to menu? If it's the latter, it should be up to the developer to not crash the game, but I presume that's not the case.
The latter is not a crash, just a script error. That would not have been a problem.
protocol_1903 wrote: Tue Feb 04, 2025 4:40 pm
Then save the blueprint item to memory before calling pre_placed_blueprint and use that item regardless when actually placing the blueprint, which would keep it in line with most other events pre_ and on_ running regardless of script actions. Or add a nil check when placing the blueprint and crash to menu.
Would it? Entity events stop if you delete the entity, for example. And a script could change blueprint contents too, it doesn't have to delete the blueprint outright.
Re: copy-paste by blueprint should trigger an event
Posted: Wed Mar 19, 2025 4:35 am
by jagoly
To add on to this, even the workaround of just setting
is broken. While it does prevent pasting normal entity settings, tags on ghost entities are still overwritten. I'm pretty sure this is a bug, it makes no sense for tags to get pasted without all of the other entity settings.