item.set_blueprint_entities() clears the mapping even when nothing changes

Place to report issues and suggest improvements to the API documentation.
User avatar
Quezler
Fast Inserter
Fast Inserter
Posts: 160
Joined: Fri Mar 25, 2016 6:37 pm
Contact:

item.set_blueprint_entities() clears the mapping even when nothing changes

Post by Quezler »

The on_player_setup_blueprint has a mapping, in the description it warns that it can become "incorrect":
Note: if any mod changes the blueprint this will be incorrect.
However this seems to suggest that if a mod adds/removes an entity to the blueprint that the numbers will simply not line up anymore / references entities that aren't in the blueprint anymore / lacks references to existing entities when they get added / etc

But it seems that even writing the same mapping back to the blueprint causes the mapping to become not just "incorrect", but outright completely empty:

Code: Select all

/c script.on_event(defines.events.on_player_setup_blueprint, function(event)
  local blueprint = event.stack
  if blueprint == nil then return end

  game.print("before: " .. serpent.block(event.mapping.get()))
  blueprint.set_blueprint_entities(blueprint.get_blueprint_entities())
  game.print("after: " .. serpent.block(event.mapping.get()))
end)
- start new world
- run command
- place your starting furnace
- ctrl c / blueprint it
- notice the second mapping being empty

It would be nice if it could be mentioned on this event that `set_blueprint_entities` will wipe the mapping and not just make it "incorrect", and on the set_blueprint_entities method a warning to only call if it you have modified the entities since "it can break stuff elsewhere if you write to it needlessly"
Attachments
Screenshot 2025-02-20 at 18.43.15.png
Screenshot 2025-02-20 at 18.43.15.png (84.33 KiB) Viewed 278 times
User avatar
Quezler
Fast Inserter
Fast Inserter
Posts: 160
Joined: Fri Mar 25, 2016 6:37 pm
Contact:

Re: item.set_blueprint_entities() clears the mapping even when nothing changes

Post by Quezler »

an extra remark:

i resorted to reading and writing the blueprint entities as a whole because "hey, its convenient and nothing warns me against it" even when all i did was edit blueprint entity tag since there was no apparent harm, if anything set_blueprint_entity_tag seemed like the "older/deprecated" method at the time whilst it is in fact the one you should be using when you only modify the tags, so a note that you should only use set_blueprint_entities when you add or remove entities would be nice.

https://github.com/Quezler/glutenfree/c ... 1a3924a4f4
curiosity
Filter Inserter
Filter Inserter
Posts: 607
Joined: Wed Sep 11, 2019 4:13 pm
Contact:

Re: item.set_blueprint_entities() clears the mapping even when nothing changes

Post by curiosity »

Note: if any mod changes the blueprint this will be incorrect.
This seems to need a clarification. Apparently set_blueprint_entity_tag doesn't count as changing the blueprint. What else doesn't? What does?
Post Reply

Return to “Documentation Improvement Requests”