[0.13.17] large objects aren't placed on the specified pos

Bugs that are actually features.
MrDoomah
Fast Inserter
Fast Inserter
Posts: 196
Joined: Mon Jun 01, 2015 1:11 pm
Contact:

[0.13.17] large objects aren't placed on the specified pos

Post by MrDoomah »

Large object created by

Code: Select all

 surface.create_entity{name="reactor-"..tostring(dx).."x"..tostring(dy), position={left_top.position.x + dx/2 -1/2, left_top.position.y + dy/2 -1/2}, force=force} 
aren't placed on the right position:

Code: Select all

local new_reactor = surface.create_entity{name="reactor-"..tostring(dx).."x"..tostring(dy), position={left_top.position.x + dx/2 -1/2, left_top.position.y + dy/2 -1/2}, force=force}
game.players[1].print("1: x: " .. left_top.position.x + dx/2 -1/2 .. ", y: " .. left_top.position.y + dy/2 -1/2)
game.players[1].print("2: x: " .. new_reactor.position.x .. ", y: " .. new_reactor.position.y)
ImageImage

Smaller objects are placed in the correct position:
ImageImage
posila
Former Staff
Former Staff
Posts: 5448
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: [0.13.17] large objects aren't placed on the specified pos

Post by posila »

MrDoomah wrote:Large object created by

Code: Select all

 surface.create_entity{name="reactor-"..tostring(dx).."x"..tostring(dy), position={left_top.position.x + dx/2 -1/2, left_top.position.y + dy/2 -1/2}, force=force} 
Why -1/2?
MrDoomah
Fast Inserter
Fast Inserter
Posts: 196
Joined: Mon Jun 01, 2015 1:11 pm
Contact:

Re: [0.13.17] large objects aren't placed on the specified pos

Post by MrDoomah »

Because the way I implemented 'left_top'. Left_top isn't part of an area, but the position of the left_top most entity underneath the entity you see in the pictures. Since these entities are 1x1 in size, the position is given in {x+0.5,y+0.5} as this is the centre of the tile the entity. To correct for this I need to subtract the 0.5 from this position. See image where I also print out the 4 corners.
Image


Does that make sense?


Edit: Adding a flag "placeable-off-grid" to the entity does seems to fix it, but I do want them to align to grid.
posila
Former Staff
Former Staff
Posts: 5448
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: [0.13.17] large objects aren't placed on the specified pos

Post by posila »

Ah, I see ... what bounding box has "reactor-5x5" entity defined in protoype?
MrDoomah
Fast Inserter
Fast Inserter
Posts: 196
Joined: Mon Jun 01, 2015 1:11 pm
Contact:

Re: [0.13.17] large objects aren't placed on the specified pos

Post by MrDoomah »

Ah whoops. I'm an idiot xD. The entities were generated by a script that made the bounding box {0.4*size,0.4*size}, so at size 5, the bounding box is 4x4 instead of 4.5x4.5-ish that I intended.
Post Reply

Return to “Not a bug”