Where will build_from_cursor() build?
Where will build_from_cursor() build?
Is there a lua function that will tell you the coordinates where build_from_cursor() will try and build something? In the game, you can visually see the cursor snap to the possible placements. But via the API I don't see a way to do this. In my MCP code, a successful placement results in a callback and you can see where the entity ended up. But if the call fails, there's no feedback about why. And without knowing the coordinates that the build_from_cursor() was actually trying to place the entity, it's hard to figure out why it failed. In my case, it's usually something in the way but without knowing what coordinates the build was snapped to I can't just do a find_entity() of some fashion on the bounding box. Thanks in advance!
Re: Where will build_from_cursor() build?
Yes, the LuaPlayer->build_from_cursor() function. In the UI, as you move the cursor it's constantly refreshed showing the exact location the build will happen and whether it will succeed. In the API though there doesn't seem to be any way to get that information that I can find.
Re: Where will build_from_cursor() build?
Does LuaSurface::can_place_entity() work for you? https://lua-api.factorio.com/latest/cla ... ace_entity
My mods: Multiple Unit Train Control, RGB Pipes, Shipping Containers, Rocket Log, Smart Artillery Wagons.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
Re: Where will build_from_cursor() build?
I'm already using that but the issue is that the coordinates that are used to determine placement aren't necessarily the ones passed in. And if you don't know the coordinates actually being used to determine if placement is valid, it's hard to figure out why a given spot won't work.robot256 wrote: Thu Apr 23, 2026 2:49 pm Does LuaSurface::can_place_entity() work for you? https://lua-api.factorio.com/latest/cla ... ace_entity
Simple example, if you have a drill placed it will have a drop_position coordinate. A chest won't actually fit at that location because it's a bit off center, but you can build_from_cursor() at the drop position with a chest because it will snap to the right location. If you try to do the same thing and place a furnace at the drop_position for the drill it will fail because whatever coordinates the game snaps to result in the furnace overlapping with the drill. That would be easy enough to check if I knew what coordinates the build was actually trying to use but I can't figure out how to get that information.
In the common / simple case I could write my own code that would probably figure it out. Drills and chests and simple square entities I can figure out I'm sure. Some things like water pumps are rectangular and it's less obvious what the internal logic is. So it would be helpful to have an 'official' way to get the info.


