Page 1 of 1

Blueprint orientation when still in hand (not pasted).

Posted: Sat Mar 16, 2024 5:53 pm
by Asynchron
Hi,

How do you find the orientation of a blueprint that is to be pasted?

I was thinking on making a small mod that would deconstruct entities that matched entities in blueprint. I.e. say on "ALT + mouse click", the script would read blueprint in hand, and then look for matching entities on the surface at click position + entity position from blueprint, and if a matching entity on surface was found it would deconstruct it.

This unfortunately is not possible since, position of entities in blueprint don't reflect the orientation of it when pasted. I.e. if you pick a blueprint, that has two entites, A & B with positions [0, 0], and [1, 0], upon rotation of blueprint in hand, the positions read by script would be the same, when you'd expect for them to become [0, 0] and [0, 1]. Even if this update of positions is not done by factorio itself, you could do this manually if you knew the orientation of about to be pasted blueprint, which seems to elude me from the api docs.

Thank you,
Asynchron.

Re: Blueprint orientation when still in hand (not pasted).

Posted: Wed Mar 20, 2024 9:14 am
by Bilka
The on_pre_build event has position which is the center of the blueprint, and direction to tell you if the blueprint was rotated before placement. So you can do the calculations and order the deconstruction inside that event.

You may be interested in https://mods.factorio.com/mod/DestructiveBlueprints.

Re: Blueprint orientation when still in hand (not pasted).

Posted: Sun Mar 24, 2024 10:58 am
by SupplyDepoo
I have found a way to track the rotation of blueprints by defining two new shortcuts using linked_game_control and then listening to the CustomInputEvent for those shortcuts. It allows me to get the rotation without the blueprint needing to be placed in the world.

data.lua looks something like this:

Code: Select all

data:extend({
  {
    type = "custom-input",
    name = "rotate-blueprint",
    linked_game_control = "rotate",
    key_sequence = ""
  },
})
And in control.lua I have:

Code: Select all

local blueprint_rotation_states = {}                             -- it's necessary to store rotations in a local variable because blueprint rotation is remembered until the savegame unloaded

script.on_event("rotate-blueprint", function(event)
	local player = game.get_player(event.player_index)
	local bp = get_cursor_blueprint(player.index)            -- get_cursor_blueprint is a simple function I wrote to get the held blueprint whether it's in a blueprint book or not, and ignoring blank/unconfigured blueprints
	if bp then
		local previous = blueprint_rotation_states[bp.item_number]
		blueprint_rotation_states[bp.item_number] = ((previous or 0) + 1) % 4
	end
end)
Then when I need the rotation I look it up in blueprint_rotation_states using the item_number. I have shown only the code for clockwise rotation, but counterclockwise works basically the same.

Sadly it doesn't work with the blueprint library (but there is hope with 2.0 giving access to the library -- just need a reliable way of identifying library prints as they probably don't have an item_number).