Page 1 of 1

How to change entity before blueprinting

Posted: Sun Jan 08, 2023 8:57 pm
by WildBraas
I want change some entity properties right before blueprinting, so this entity lay to blueprint with changes.
In event on_player_setup_blueprint I may access to entities, but its changing not stored in blueprint.
Has the way do something with it?

Re: How to change entity before blueprinting

Posted: Sun Jan 08, 2023 9:17 pm
by WildBraas
The only one solution I made right now:
- get event.mapping
- get player.cursor_stack.get_blueprint_entities
- iterate mapping entities and change blueprint entities in same index praying for indexes is exactly similar.
- set blueprints entities back to cursor

This is working but seems shitty imho

Re: How to change entity before blueprinting

Posted: Sun Jan 08, 2023 11:10 pm
by robot256
You have found that the blueprint API only allows getting or setting the entire list of entities at once. That's how it's supposed to work.

I do this all the time when I want to change the name of the entity in the blueprint. As long as you're modifying entity subtables and not adding/subtracting from the number of entities, it's fine.

Re: How to change entity before blueprinting

Posted: Sun Jan 08, 2023 11:14 pm
by WildBraas
Indexes and values in tables event.mapping and player.cursor_stack.get_blueprint_entities is similar?

Re: How to change entity before blueprinting

Posted: Mon Jan 09, 2023 12:43 am
by robot256
Yes, that's right: https://lua-api.factorio.com/latest/eve ... _blueprint
mapping :: LuaLazyLoadedValue(dictionary[uint → LuaEntity])

The blueprint entity index to source entity mapping. Note: if any mod changes the blueprint this will be incorrect.
It's not clear from the docs, but it seems to imply that if another mod's on_player_setup_blueprint code runs before yours, that the mapping might not be correct. I've never used the mapping table before, since I just read the entity name from the blueprint item entity list.