How to change entity before blueprinting

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
WildBraas
Inserter
Inserter
Posts: 44
Joined: Sat Feb 16, 2019 6:25 am
Contact:

How to change entity before blueprinting

Post 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?

WildBraas
Inserter
Inserter
Posts: 44
Joined: Sat Feb 16, 2019 6:25 am
Contact:

Re: How to change entity before blueprinting

Post 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

robot256
Filter Inserter
Filter Inserter
Posts: 596
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: How to change entity before blueprinting

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

WildBraas
Inserter
Inserter
Posts: 44
Joined: Sat Feb 16, 2019 6:25 am
Contact:

Re: How to change entity before blueprinting

Post by WildBraas »

Indexes and values in tables event.mapping and player.cursor_stack.get_blueprint_entities is similar?

robot256
Filter Inserter
Filter Inserter
Posts: 596
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: How to change entity before blueprinting

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

Post Reply

Return to “Modding discussion”