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.
Blueprint orientation when still in hand (not pasted).
Re: Blueprint orientation when still in hand (not pasted).
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.
You may be interested in https://mods.factorio.com/mod/DestructiveBlueprints.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
- SupplyDepoo
- Filter Inserter
- Posts: 298
- Joined: Sat Oct 29, 2016 8:42 pm
- Contact:
Re: Blueprint orientation when still in hand (not pasted).
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:
And in control.lua I have:
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).
data.lua looks something like this:
Code: Select all
data:extend({
{
type = "custom-input",
name = "rotate-blueprint",
linked_game_control = "rotate",
key_sequence = ""
},
})
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)
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).