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?
Restrict entity to a 2x2 grid
Re: Restrict entity to a 2x2 grid
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.
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
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.
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.
- eradicator
- Smart Inserter
- Posts: 5206
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Restrict entity to a 2x2 grid
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.
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.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Re: Restrict entity to a 2x2 grid
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.
Re: Restrict entity to a 2x2 grid
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
Just on_place replace it with what you need.
- eradicator
- Smart Inserter
- Posts: 5206
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Restrict entity to a 2x2 grid
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.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Re: Restrict entity to a 2x2 grid
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?
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?