[kovarex] [1.1.39] Shift+Copy+Paste ignores on_player_configured_blueprint

This subforum contains all the issues which we already resolved.
Post Reply
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

[kovarex] [1.1.39] Shift+Copy+Paste ignores on_player_configured_blueprint

Post by DaveMcW »

There is a loophole in the modding API that allows a player to bypass blueprint editing mods. This example is a rather hostile mod, but it also affects mods that add helpful tags to blueprints.

Steps to reproduce:
1. Create a simple mod that deletes all transport belts from new blueprints.

Code: Select all

/c function delete_belts(event)
  local bp = game.get_player(event.player_index).cursor_stack
  if not bp or not bp.valid_for_read or not bp.is_blueprint or not bp.is_blueprint_setup() then return end
  local entities = bp.get_blueprint_entities()
  if not entities then return end
  for key, entity in pairs(entities) do
    if entity.name:find("transport-belt", 1, true) then
      entities[key] = nil
    end
  end
  bp.set_blueprint_entities(entities)
end
script.on_event(defines.events.on_player_configured_blueprint, delete_belts)
script.on_event(defines.events.on_player_setup_blueprint, delete_belts)
2. Select the copy tool.
3. Hold down shift while creating a blueprint that includes transport belts.
4. Click "Create blueprint".
5. Select the paste tool.

Expected result: Paste tool is missing transport belts.

Actual result: Paste tool has transport belts.


The other ways of creating blueprints all work as expected, the belts are gone:
  • Copy tool without shift
  • Blueprint tool with shift
  • Blueprint tool without shift

Honktown
Smart Inserter
Smart Inserter
Posts: 1025
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: [1.1.39] Shift+Copy+Paste ignores on_player_configured_blueprint

Post by Honktown »

You need to also check player.blueprint_to_setup (sorry for the change in spacing) :

Code: Select all

/c
function delete_belts(event)
	local player = game.get_player(event.player_index)
	local bp1 = player.blueprint_to_setup
	local tick = event.tick
	if not bp1.valid_for_read then
		game.print(tick.." player blueprint_to_setup is invalid to read")
		bp1 = nil
	else
		game.print(tick.." player blueprint_to_setup is valid to read")
	end

	local bp2 = player.cursor_stack
	if not bp2 or not bp2.valid_for_read or not bp2.is_blueprint or not bp2.is_blueprint_setup() then
		game.print(tick.." player cursor blueprint is invalid")
		bp2 = nil
	else
		game.print(tick.." player cursor blueprint is valid")
	end

	local bp = bp1 or bp2
	if not bp then
		return
	end
	local entities = bp.get_blueprint_entities()
	if not entities then return end
	for key, entity in pairs(entities) do
		if entity.name:find("transport-belt", 1, true) then
			entities[key] = nil
		end
	end
	bp.set_blueprint_entities(entities)
end

script.on_event(defines.events.on_player_configured_blueprint, delete_belts)
script.on_event(defines.events.on_player_setup_blueprint, delete_belts)
I have mods! I guess!
Link

Honktown
Smart Inserter
Smart Inserter
Posts: 1025
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: [1.1.39] Shift+Copy+Paste ignores on_player_configured_blueprint

Post by Honktown »

Going back-and-forth, it is interesting that *configuring* copy-paste causes paste to be loaded with an unconfigured blueprint. (editing the setup entities is different than paste not being filled OR being filled with the post-event configured blueprint)
I have mods! I guess!
Link

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: [1.1.39] Shift+Copy+Paste ignores on_player_configured_blueprint

Post by DaveMcW »

Honktown wrote:
Tue Sep 07, 2021 6:35 am
You need to also check player.blueprint_to_setup
Thanks! Using player.blueprint_to_setup with the on_player_setup_blueprint event is enough to make my mod work. on_player_configured_blueprint is still buggy but I don't need it anymore.

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: [kovarex] [1.1.39] Shift+Copy+Paste ignores on_player_configured_blueprint

Post by DaveMcW »

This bug still exists in 1.1.40.

Post Reply

Return to “Resolved Problems and Bugs”