[kovarex] [1.0.0] Updated blueprint has no entities during on_player_setup_blueprint

Bugs that are actually features.
Post Reply
User avatar
Therax
Filter Inserter
Filter Inserter
Posts: 454
Joined: Sun May 21, 2017 6:28 pm
Contact:

[kovarex] [1.0.0] Updated blueprint has no entities during on_player_setup_blueprint

Post by Therax »

Observed behavior:

1. Add event handler for on_player_setup_blueprint.

2. Create a blueprint of an entity.

3. In the event handler, observe the following:
player.blueprint_to_setup.valid_for_read is true
player.cursor_stack.valid_for_read is false
player.blueprint_to_setup.is_blueprint is true
player.blueprint_to_setup.is_blueprint_setup() returns true
player.blueprint_to_setup.get_blueprint_entities() returns a table of 1 LuaEntity

4. In the BP GUI, click the "Select new contents for this blueprint" button, and select the same (or different) entity.

5. In the handler for on_player_setup_blueprint, observe the following are true:
player.blueprint_to_setup.valid_for_read is false
player.cursor_stack.valid_for_read is true
player.cursor_stack.is_blueprint is true
player.cursor_stack.is_blueprint_setup() returns false
player.cursor_stack.get_blueprint_entities() returns nil

Expected behavior:

In general, selecting new contents for a blueprint should have the same behavior during event handlers as when creating a brand-new blueprint.
In specific, there should be a way during the event handler to query the entities & tiles in the blueprint, and modify them.

Motivating use case:

https://github.com/mspielberg/factorio- ... #L299-L364
Miniloader — UPS-friendly 1x1 loaders
Bulk Rail Loaders — Rapid train loading and unloading
Beltlayer & Pipelayer — Route items and fluids freely underground

Honktown
Filter Inserter
Filter Inserter
Posts: 747
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: [1.0.0] Updated blueprint has no entities during on_player_setup_blueprint

Post by Honktown »

Unless I'm mistaken, you should be using on_player_configured_blueprint. I might call it a bug that creating a new blueprint immediately sets the blueprint (the player did not confirm anything)*. Following behavior from an event like on_entity_died where the entity is (should be) valid while the event is raised, during on_player_setup_blueprint, I'd expect nothing would be stored about the new blueprint setup, while on_player_configured_blueprint is the event which lets one modify the blueprint data stored somewhere, which is about to be put into the blueprint.

When on_player_configured_blueprint is raised, the blueprint has stuff in it. Related to your code, direction and bar exist as values among bp.get_blueprint_entities()

For an unset blueprint, if you really wanted to set things yourself before the player configures anything (which sounds unsafe), use event.mapping.get() instead. No need to find entities. Tiles aren't as easily accessible during setup.

*The cursor immediately being set seems like it should be restricted to copying... the player never confirms but a blueprint is created and filled. It is a bit conflicting behavior versus setting up a blueprint, but it is what it is.
testing stuff
I have mods! I guess!
Link

User avatar
Therax
Filter Inserter
Filter Inserter
Posts: 454
Joined: Sun May 21, 2017 6:28 pm
Contact:

Re: [1.0.0] Updated blueprint has no entities during on_player_setup_blueprint

Post by Therax »

Honktown wrote:
Sat Sep 26, 2020 8:27 pm
Unless I'm mistaken, you should be using on_player_configured_blueprint. I might call it a bug that creating a new blueprint immediately sets the blueprint (the player did not confirm anything)*.
I believe you are mistaken. on_player_configured_blueprint fires when the player selects Confirm in the blueprint dialog. There are many use cases where the blueprint dialog never appears, such as when using the built-in cut/copy tools.

For my use case, compound entities, it is quite frequent that there are half a dozen entities in the same map tile that are conceptually to the user a single entity, and built with a single entity. It is valuable to be able to maintain that illusion in the blueprint confirmation dialog, which means having some way to affect what is seen in that dialog between the time the user selects an area with a blueprinting tool and the dialog appearing. This is exactly what on_player_setup_blueprint does. The conceptual model is:

a) player selects area with a blank blueprint tool
b) Factorio creates a blueprint of the selected area (on_player_setup_blueprint)
c) Factorio immediately opens the configuration dialog for that brand new blueprint
d) player adjusts blueprint settings (on_player_configured_blueprint)
e) Factorio places the blueprint in the player inventory
Miniloader — UPS-friendly 1x1 loaders
Bulk Rail Loaders — Rapid train loading and unloading
Beltlayer & Pipelayer — Route items and fluids freely underground

Honktown
Filter Inserter
Filter Inserter
Posts: 747
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: [1.0.0] Updated blueprint has no entities during on_player_setup_blueprint

Post by Honktown »

Therax wrote:
Sun Sep 27, 2020 7:44 pm
Honktown wrote:
Sat Sep 26, 2020 8:27 pm
Unless I'm mistaken, you should be using on_player_configured_blueprint. I might call it a bug that creating a new blueprint immediately sets the blueprint (the player did not confirm anything)*.
I believe you are mistaken. on_player_configured_blueprint fires when the player selects Confirm in the blueprint dialog. There are many use cases where the blueprint dialog never appears, such as when using the built-in cut/copy tools.

For my use case, compound entities, it is quite frequent that there are half a dozen entities in the same map tile that are conceptually to the user a single entity, and built with a single entity. It is valuable to be able to maintain that illusion in the blueprint confirmation dialog, which means having some way to affect what is seen in that dialog between the time the user selects an area with a blueprinting tool and the dialog appearing. This is exactly what on_player_setup_blueprint does. The conceptual model is:

a) player selects area with a blank blueprint tool
b) Factorio creates a blueprint of the selected area (on_player_setup_blueprint)
c) Factorio immediately opens the configuration dialog for that brand new blueprint
d) player adjusts blueprint settings (on_player_configured_blueprint)
e) Factorio places the blueprint in the player inventory
I think I better understand now, however, if an entity is not blueprintable (player-creation flag is not set), it won't be transferred for any blueprint or copy. In this example, what the player sees in a dialog is the real entity, but then we should be able to manipulate the data afterwards for the proxy placement.

Testing:
On setup:
Case 1. Copy produces false for player.blueprint_to_setup.valid_for_read, and the cursor is populated.
Case 2. An empty blueprint area selection produces true for player.blueprint_to_setup.valid_for_read.
Case 3. Select new contents produces false for player.blueprint_to_setup.valid for read and the cursor blueprint is empty, but exists.

On config:
Case 1. Copy raises no event.
Case 2. blueprint_to_setup is invalid for read. Cursor is immediately filled, and can be edited.
Case 3. blueprint_to_setup is invalid for read. Cursor has no blueprint.

This produces three weird cases, but each logically distinguishable. In addition, on setup has event.item = "blueprint", which doesn't exist on configuration (implying a single function could handle different cases).

In the bug sense, Case 3 should be the same as Case 2, for consistency sake. In Case 1 (copy) the blueprint can be edited in cursor on setup. In Case 2 we can have blueprint_to_setup edited on setup, or in cursor on configuration. In Case 3 the data can be manually assigned on setup, but we could expect the information to be overwritten once the blueprint is confirmed... there is no way to cause any desired changes during on setup to survive on configuration, nor is there a mapping of which blueprint was the source of selecting new contents. Crux of the bug yes/no? A problem is the blueprint for which we want to add new contents could have been one from the library, and as far as I am aware, there isn't a way to access nor modify a blueprint stored there. That is a significant difference from Case 1 and 2.

Edit: we want to add new contents -> we want to select new contents
I have mods! I guess!
Link

Rseding91
Factorio Staff
Factorio Staff
Posts: 11363
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [1.0.0] Updated blueprint has no entities during on_player_setup_blueprint

Post by Rseding91 »

Ok; I looked into this and figured out what's happening.

The blueprint in the cursor is a red-herring. It's purely used to do rendering and is just temporary garbage. The actual blueprint that gets re-assigned is somewhere in the players inventory.

The re-assign process requires you open the blueprint GUI which means it has to have already been created fully and put into your inventory.

I don't have any nice answer beyond that. The way it was implemented is kind of a giant hack in my opinion and I don't see it getting re-worked any time soon.
If you want to get ahold of me I'm almost always on Discord.

User avatar
Muppet9010
Fast Inserter
Fast Inserter
Posts: 211
Joined: Sat Dec 09, 2017 6:01 pm
Contact:

Re: [kovarex] [1.0.0] Updated blueprint has no entities during on_player_setup_blueprint

Post by Muppet9010 »

This may be a silly question, but why doesn't the player.blueprint_to_setup object get reset to a readable state on the reselection of an area?
As an area of the map has been selected to load the blueprint from, is it not just some blueprint data like name, icons, includes(?) are pre-populated compared to a new blueprint?

Rseding91
Factorio Staff
Factorio Staff
Posts: 11363
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [kovarex] [1.0.0] Updated blueprint has no entities during on_player_setup_blueprint

Post by Rseding91 »

Muppet9010 wrote:
Sat Oct 24, 2020 3:28 pm
This may be a silly question, but why doesn't the player.blueprint_to_setup object get reset to a readable state on the reselection of an area?
As an area of the map has been selected to load the blueprint from, is it not just some blueprint data like name, icons, includes(?) are pre-populated compared to a new blueprint?
The original blueprint that had the "select new contents" button clicked has the new contents.
If you want to get ahold of me I'm almost always on Discord.

kovarex
Factorio Staff
Factorio Staff
Posts: 7646
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: [kovarex] [1.0.0] Updated blueprint has no entities during on_player_setup_blueprint

Post by kovarex »

I looked in the code, and I believe that you should use the BlueprintSelectArea event.

User avatar
Muppet9010
Fast Inserter
Fast Inserter
Posts: 211
Joined: Sat Dec 09, 2017 6:01 pm
Contact:

Re: [kovarex] [1.0.0] Updated blueprint has no entities during on_player_setup_blueprint

Post by Muppet9010 »

The issue is the difference between a new BP being made and an existing BP having its contents re-selected.

On a new BP being selected the on_player_setup_blueprint event can be traced through to the player.blueprint_to_setup.get_blueprint_entities() correctly. With player.blueprint_to_setup.valid_for_read being true.

However, when the an existing BP has its contents reselected the on_player_setup_blueprint event can't be followed through as the player.blueprint_to_setup.valid_for_read is false. Also reading the player cursor stack doesn't work as Therax listed in his original post.

Therax's original post has the full breakdown of states for the 2 scenarios when the event is triggered.

Post Reply

Return to “Not a bug”

Who is online

Users browsing this forum: No registered users