Restrict entity to a 2x2 grid

Place to get help with not working mods / modding interface.
Post Reply
PFQNiet
Filter Inserter
Filter Inserter
Posts: 289
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Restrict entity to a 2x2 grid

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

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Restrict entity to a 2x2 grid

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

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

Re: Restrict entity to a 2x2 grid

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

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Restrict entity to a 2x2 grid

Post 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.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Bilka
Factorio Staff
Factorio Staff
Posts: 3158
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Restrict entity to a 2x2 grid

Post 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.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

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

Re: Restrict entity to a 2x2 grid

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

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2904
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Restrict entity to a 2x2 grid

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

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Restrict entity to a 2x2 grid

Post 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.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

serieznyi
Manual Inserter
Manual Inserter
Posts: 1
Joined: Tue Feb 15, 2022 8:56 am
Contact:

Re: Restrict entity to a 2x2 grid

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

Post Reply

Return to “Modding help”