Page 1 of 1
[1.1.35] Incorrect grid-snapping of even-sized resources
Posted: Fri Jul 09, 2021 12:05 pm
by PFQNiet
I have a modded resource entity that has a collision box of {{-4.9,-4.9},{4.9,4.9}} and a selection box of {{-3,-3},{3,3}} - both of these indicate an even-sized entity (10x10 collision, 6x6 selection).
However, if I attempt to spawn this entity, it gets snapped to the middle of a tile:
Code: Select all
local entity = game.surfaces[1].create_entity{
name = "even-sized-resource",
position = {0,0},
amount = 60
}
game.print(serpent.line(entity.position)) -- {0.5,0.5}
Placing this entity via the /editor works as expected, placing the resource entity at {0,0}.
Re: [1.1.35] Incorrect grid-snapping of even-sized resources
Posted: Fri Jul 09, 2021 12:09 pm
by boskid
For ResourceEntity, LuaSurface::create_entity has additional parameter snap_to_tile_center with default value of `true`. Not a bug
Re: [1.1.35] Incorrect grid-snapping of even-sized resources
Posted: Fri Jul 09, 2021 2:56 pm
by PFQNiet
Ah, missed that.
It seems weird though - why would ResourceEntity have such an option, and why does it default to true?
Re: [1.1.35] Incorrect grid-snapping of even-sized resources
Posted: Fri Jul 09, 2021 3:54 pm
by boskid
Changelog (0.18.23) wrote:Changed LuaSurface::create_entity so it places resource entities to center of a tile as map generator would. This can be overridden by optional snap_to_tile_center parameter. (
83891)
Topic linked in this changelog entry may contain answers to your questions. It looks to be for consistency with how map generator works.
Re: [1.1.35] Incorrect grid-snapping of even-sized resources
Posted: Fri Jul 09, 2021 8:02 pm
by orzelek
boskid wrote: Fri Jul 09, 2021 3:54 pm
Changelog (0.18.23) wrote:Changed LuaSurface::create_entity so it places resource entities to center of a tile as map generator would. This can be overridden by optional snap_to_tile_center parameter. (
83891)
Topic linked in this changelog entry may contain answers to your questions. It looks to be for consistency with how map generator works.
It was a fix for a bug that made mods unable to spawn odd sized resources of similar type to oil patches properly.
Without this center to tile if you had resource that required specialized building over it it would not function correctly when placed by mod.