Is tile placeable at position

Place to get help with not working mods / modding interface.
Post Reply
User avatar
Perlin
Burner Inserter
Burner Inserter
Posts: 7
Joined: Sun Jan 13, 2019 5:27 am
Contact:

Is tile placeable at position

Post by Perlin »

Hello,

I want to place Concrete automatically, but only on placable tiles. There is a "can_place_entity" function in documentation, but I would like to achieve the same thing for tiles. For example I want to prevent my code to auto-build on water tiles.

I can do :

Code: Select all

if surface.get_tile(position).name ~= "water" then ...
but I would prefer to do something more portable, in case some other mods add non buildable tiles like water.

How can I achieve this?

Regards

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

Re: Is tile placeable at position

Post by darkfrei »

https://wiki.factorio.com/Types/CollisionMask

All concrete tiles cannot be placed near water while:

Code: Select all

data.raw.item.concrete.place_as_tile.result = "concrete" 
data.raw.item.concrete.place_as_tile.condition_size = 1 
data.raw.item.concrete.place_as_tile.condition[1] = "water-tile" 
All water tiles have this collision mask:

Code: Select all

data.raw.tile.water.collision_mask[1] = "water-tile" 
data.raw.tile.water.collision_mask[2] = "item-layer" 
data.raw.tile.water.collision_mask[3] = "resource-layer" 
data.raw.tile.water.collision_mask[4] = "player-layer" 
data.raw.tile.water.collision_mask[5] = "doodad-layer" 

User avatar
Perlin
Burner Inserter
Burner Inserter
Posts: 7
Joined: Sun Jan 13, 2019 5:27 am
Contact:

Re: Is tile placeable at position

Post by Perlin »

Yes but how can I test this programmatically ? How can I do something like :

Code: Select all

if allowed_to_build(concreteTile, position) then ...
Because I need to test if I'm allowed to build Concrete on a specific tile (E.g. true for ground, false for water) before I do a surface.set_tiles().

On the game we can see when we can and when we can't (see below), just need to do the same with code.

The collision mask is not enough because there is also the "condition_size" parameter (how close from water can I build, if I'm right).

Thank you
factorio-tile.png
factorio-tile.png (505.35 KiB) Viewed 1434 times

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

Re: Is tile placeable at position

Post by darkfrei »

I haven't tested it, but try #LuaSurface.get_tile_properties

You can always get tile with #LuaSurface.get_tile and then get prototype of this tile with #LuaTile.prototype or get bool with #LuaTile.collides_with

Now I see no way to get tile.place_as_tile.condition = {} on the control stage. :( It must be defined in LuaTilePrototype but it is not here.

Post Reply

Return to “Modding help”