copy-paste by blueprint should trigger an event

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
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
Burner Inserter
Burner Inserter
Posts: 19
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: 33
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: 25
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
Manual Inserter
Manual Inserter
Posts: 2
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.

Post Reply

Return to “Modding interface requests”