Page 1 of 1

[.15.10] Blueprint positions are off by 1

Posted: Tue May 16, 2017 2:40 am
by Nexela
Start a new map

Make a train circle around your character so that the center of the circle is 0.0

The top left track should be x=-10, y=-4

Blueprint the circle and remove it and hold the blueprint in your hands

if you check the blueprint_entities all of the x,y coords will be off by 1

This builds correctly

Code: Select all

game.player.cursor_stack.build_blueprint({surface=game.player.surface, position = {0, 0}, force=game.player.force, force_build=true}) 


This fails misserably

Code: Select all

for _, track in pairs(game.player.cursor_stack.get_blueprint_entities()) do
    local pos = {track.position.x, track.position.y}
    game.player.surface.create_entity{name=track.name, position=pos, direction=track.direction, force=game.player.force}
end
This builds correctly

Code: Select all

for _, track in pairs(game.player.cursor_stack.get_blueprint_entities()) do
    local pos = {track.position.x +1 , track.position.y +1}
    game.player.surface.create_entity{name=track.name, position=pos, direction=track.direction, force=game.player.force}
end

Re: [.15.10] Blueprint positions are off by 1

Posted: Tue May 16, 2017 2:55 am
by Rseding91
Entities in blueprints are grid-aligned to the entity that uses the largest grid shift (rails most of the time) and then centered on 0,0. That means any blueprint you create with rails will almost never be the same if you build it directly on 0,0.

You have to account for the shifted position of everything in the blueprint if you want to know where it's actually going to be placed when built in the world.

Re: [.15.10] Blueprint positions are off by 1

Posted: Tue May 16, 2017 6:37 am
by Rseding91
I've added support to read the tile shift from LuaEntityPrototype for 0.15.11 so you can calculate the positions entities will end up when building them in the world.

Re: [.15.10] Blueprint positions are off by 1

Posted: Tue May 16, 2017 7:01 am
by Nexela
Thanks! Will make it a lot easier than trial and error