copy-paste by blueprint should trigger an event

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
mami
Burner Inserter
Burner Inserter
Posts: 18
Joined: Fri Oct 21, 2022 12:27 am
Contact:

copy-paste by blueprint should trigger an event

Post 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

Code: Select all

entity.allow_copy_paste = false
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.
BinarySpike
Burner Inserter
Burner Inserter
Posts: 16
Joined: Tue Jun 28, 2016 2:15 am
Contact:

Re: copy-paste by blueprint should trigger an event

Post 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:
ILLISIS
Inserter
Inserter
Posts: 25
Joined: Wed Feb 09, 2022 10:49 am
Contact:

Re: copy-paste by blueprint should trigger an event

Post 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.
BinarySpike
Burner Inserter
Burner Inserter
Posts: 16
Joined: Tue Jun 28, 2016 2:15 am
Contact:

Re: copy-paste by blueprint should trigger an event

Post by BinarySpike »

Would benefit this mod as well:
Image
SWeini
Inserter
Inserter
Posts: 39
Joined: Mon Apr 04, 2022 6:43 am
Contact:

Re: copy-paste by blueprint should trigger an event

Post 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.
BlackOverlord
Manual Inserter
Manual Inserter
Posts: 3
Joined: Fri Aug 20, 2021 5:00 pm
Contact:

Re: copy-paste by blueprint should trigger an event

Post 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.
GlassBricks
Inserter
Inserter
Posts: 40
Joined: Fri Jun 11, 2021 5:20 pm
Contact:

Re: copy-paste by blueprint should trigger an event

Post by GlassBricks »

+1
y_e_a_r
Burner Inserter
Burner Inserter
Posts: 10
Joined: Wed Jun 07, 2023 10:38 pm
Contact:

Re: copy-paste by blueprint should trigger an event

Post 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.
User avatar
BraveCaperCat
Filter Inserter
Filter Inserter
Posts: 402
Joined: Mon Jan 15, 2024 10:10 pm
Contact:

Re: copy-paste by blueprint should trigger an event

Post by BraveCaperCat »

+1
Creator of multiple mods, including Quality Assurance - My most popular one.
Go check them out with the first and second links!
I'll probably be wanting or giving help with modding most of the time I spend here on the forum.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14735
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: copy-paste by blueprint should trigger an event

Post 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.
If you want to get ahold of me I'm almost always on Discord.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14735
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: copy-paste by blueprint should trigger an event

Post 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?
If you want to get ahold of me I'm almost always on Discord.
robot256
Smart Inserter
Smart Inserter
Posts: 1032
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: copy-paste by blueprint should trigger an event

Post 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?
curiosity
Filter Inserter
Filter Inserter
Posts: 542
Joined: Wed Sep 11, 2019 4:13 pm
Contact:

Re: copy-paste by blueprint should trigger an event

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

Return to “Modding interface requests”