[1.1.35] Incorrect grid-snapping of even-sized resources

Bugs that are actually features.
Post Reply
PFQNiet
Filter Inserter
Filter Inserter
Posts: 289
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

[1.1.35] Incorrect grid-snapping of even-sized resources

Post 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}.

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2241
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: [1.1.35] Incorrect grid-snapping of even-sized resources

Post by boskid »

For ResourceEntity, LuaSurface::create_entity has additional parameter snap_to_tile_center with default value of `true`. Not a bug

PFQNiet
Filter Inserter
Filter Inserter
Posts: 289
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: [1.1.35] Incorrect grid-snapping of even-sized resources

Post by PFQNiet »

Ah, missed that.

It seems weird though - why would ResourceEntity have such an option, and why does it default to true?

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2241
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: [1.1.35] Incorrect grid-snapping of even-sized resources

Post 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.

orzelek
Smart Inserter
Smart Inserter
Posts: 3911
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: [1.1.35] Incorrect grid-snapping of even-sized resources

Post 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.

Post Reply

Return to “Not a bug”