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).