Page 1 of 1

Restrict entity to a 2x2 grid

Posted: Wed Oct 21, 2020 3:18 am
by PFQNiet
I have an entity that, when placed, will also spawn in some straight-rails to connect it to the railway.

Is it possible to restrict the placement of an entity to the same 2x2 grid that rails and train stops use?

Re: Restrict entity to a 2x2 grid

Posted: Wed Oct 21, 2020 3:23 am
by DaveMcW
The obvious solution is to make it a straight rail.

If that doesn't work, you need to check for a legal position in the build events and refund it if not allowed.

Re: Restrict entity to a 2x2 grid

Posted: Wed Oct 21, 2020 3:26 am
by PFQNiet
Unfortunately making it a straight-rail itself means the collision-box is hard-coded, and I need to ensure empty space around it. So I'd have to do checking and refunding in that case too.

I think in actual usage, the player can build rails and then clear out the gap needed for my entity before placing it, and if the entity has clear graphics to show where the rails are supposed to go, I imagine it'll be "good enough".

I was kind of hoping that tile_width and tile_height would work, since that's what train-stop seems to use, but it had no effect.

Re: Restrict entity to a 2x2 grid

Posted: Wed Oct 21, 2020 3:46 am
by eradicator
You could try making the item that places the entity a blueprint type item that is set up to align to the desired grid. If that's possible it has the benefit of being able to show whatever you want in the placement preview. Though you'd have to do some hacks to prevent the player from editing it. As i personally rate "refunding" as one of the most annoying modding problems (way too many edge-cases) i'd go with that if i could.

Or maybe now that the blueprint-grid-lock functionality is in the engine the devs are more open to interface requests to allow that for all entitites.

Re: Restrict entity to a 2x2 grid

Posted: Wed Oct 21, 2020 9:17 am
by Bilka
You can try using rail-remnants (https://wiki.factorio.com/Prototype/RailRemnants), from my experiments it looks like they conform to the rail grid.

Re: Restrict entity to a 2x2 grid

Posted: Thu Oct 22, 2020 11:59 pm
by PFQNiet
I can confirm it does indeed snap to 2x2 grid, however it also has the hardcoded collision/selection boxes that cannot be changed, unfortunately.

Re: Restrict entity to a 2x2 grid

Posted: Fri Oct 23, 2020 10:47 am
by darkfrei
PFQNiet wrote: Thu Oct 22, 2020 11:59 pm I can confirm it does indeed snap to 2x2 grid, however it also has the hardcoded collision/selection boxes that cannot be changed, unfortunately.
Just on_place replace it with what you need.

Re: Restrict entity to a 2x2 grid

Posted: Fri Oct 23, 2020 2:23 pm
by eradicator
darkfrei wrote: Fri Oct 23, 2020 10:47 am
PFQNiet wrote: Thu Oct 22, 2020 11:59 pm I can confirm it does indeed snap to 2x2 grid, however it also has the hardcoded collision/selection boxes that cannot be changed, unfortunately.
Just on_place replace it with what you need.
That doesn't solve the problem of 2x2-grid-locking an entity that is larger than 2x2. Doing the collision check *after* placement will always look ugly and have horrible user experience because the green/red of the cursor becomes unreliable.

Re: Restrict entity to a 2x2 grid

Posted: Tue Feb 15, 2022 9:37 am
by serieznyi
I have the same problem with rails.
I try create building that has input/output `straight-rail` for connecting to rail network.
I also can`t use any rail as main entity because I want change collision/selection box for entity.

Has anyone new solutions for this problem?