[.15.10] Blueprint positions are off by 1

Bugs that are actually features.
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

[.15.10] Blueprint positions are off by 1

Post 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
Rseding91
Factorio Staff
Factorio Staff
Posts: 15985
Joined: Wed Jun 11, 2014 5:23 am
Contact:

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

Post 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.
If you want to get ahold of me I'm almost always on Discord.
Rseding91
Factorio Staff
Factorio Staff
Posts: 15985
Joined: Wed Jun 11, 2014 5:23 am
Contact:

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

Post 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.
If you want to get ahold of me I'm almost always on Discord.
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

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

Post by Nexela »

Thanks! Will make it a lot easier than trial and error
Post Reply

Return to “Not a bug”