[new method req] LuaSurface.can_place_tile

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
CapnCrinklepants
Manual Inserter
Manual Inserter
Posts: 3
Joined: Thu May 04, 2017 4:44 pm
Contact:

[new method req] LuaSurface.can_place_tile

Post by CapnCrinklepants »

surface.can_place_entity works really nicely in that you just have to pass it an entity name and a position and it'll spit back whether you can place the thing according to its various bounding boxes and collision masks etc.

There doesn't seem to be the same for tiles in the API right now.

I can emulate something similar using:
(please note this is mostly pseudocode)

1) surface.get_tile

Code: Select all

newTile --table filled with the tile's place_result name and collision_mask data etc
oldTile = surface.get_tile(x, y)
canPlace = true
for layer, _ in pairs(newTile.collision_mask) do
	if oldTile.collides_with(layer) then
		canPlace = false
		break
	end
end
or 2) surface.find_tiles_filtered --perhaps slightly less messy, but it feels more wrong somehow?

Code: Select all

if surface.find_tiles_filtered{position=newTile.position, radius=0, collision_mask=newTile.collision_mask} == nil then
	canPlace = true
end
compare that to just: surface.can_place_tile("concrete", newTile.position)

I think that #1 is probably the better way to approach this currently, since I think #2 would have a lot of unnecessary checking for the existence of empty arguments, and checking place-ability isn't what it was for. But it would be nice to have a concrete (lol) method in for it in the API


anyway i'm new to all of this; i hope this comes across ok :) happy modding, happy holidays to all, and Thanks for coming to my TED talk.


EDIT:
Honktown on the discord server came up with a new idea that will work for this, which based on how the tile items have a place_result data which then sets the tile, maybe this is as intended. Tiles can always be placed afterall... It would still be nice to have a "shortcut" but this is probably the closest solution as the API is now :)

Code: Select all

if surface.can_place_entity{name="tile-ghost", position=newTile.position, inner_name=newTile.name} then
	surface.set_tile(<etc>)
end

Post Reply

Return to “Modding interface requests”