[SOLVED] Make an entity unplaceable on stone path/concrete/refined concrete/etc?

Place to get help with not working mods / modding interface.
Post Reply
FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2485
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

[SOLVED] Make an entity unplaceable on stone path/concrete/refined concrete/etc?

Post by FuryoftheStars »

Anyone know if there's a collision_mask or other method (ie, do I need to make checks in control while placing?) that prevents an entity from being placed on path tiles, both vanilla and mod added? Basically, I want to make it so you can't plant a tree on anything but bare, regular ground. :)
Last edited by FuryoftheStars on Wed May 18, 2022 1:04 am, edited 1 time in total.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

Xorimuth
Filter Inserter
Filter Inserter
Posts: 623
Joined: Sat Mar 02, 2019 9:39 pm
Contact:

Re: Make an entity unplaceable on stone path/concrete/refined concrete/etc?

Post by Xorimuth »

Yes, see Klonan’s transport drones for a path tile that you can’t place any other entity on, just using collision masks.
My mods
Content: Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Remote Configuration | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2485
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Make an entity unplaceable on stone path/concrete/refined concrete/etc?

Post by FuryoftheStars »

Ahh, I forgot about that thing! Thanks!!
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2485
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Make an entity unplaceable on stone path/concrete/refined concrete/etc?

Post by FuryoftheStars »

Hmm, ok, looks like Klonan used the collision-mask-util file to get an unused layer and then purposed it for what he needed. Guess I'll have to do the same.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2485
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Make an entity unplaceable on stone path/concrete/refined concrete/etc?

Post by FuryoftheStars »

I'm obviously not getting this. :/ Can anyone see anything obvious with this code? This is located in data-final-fixes.lua (and does fire).

Code: Select all

local collision_mask_util = require("collision-mask-util")

-- Make it so saplings (and all trees, really) cannot be planted directly onto artificial tiles and these tiles cannot be placed where the saplings/trees are
local tree_collision_layer = collision_mask_util.get_first_unused_layer()

for _, tree in pairs(data.raw.tree) do
    collision_mask_util.add_layer(collision_mask_util.get_mask(tree), tree_collision_layer)
end

local tiles = data.raw.tile
for _, item in pairs (data.raw.item) do
    if item.place_as_tile then
        collision_mask_util.add_layer(item.place_as_tile.condition, tree_collision_layer)
        tiles[item.place_as_tile.result].check_collision_with_entities =  true
    end
end
Edit: Bug 1: Apparently collision_mask_util.add_layer() cannot add the layer if the prototype doesn't already have it defined. But even changing the code to below doesn't allow me what I want:

Code: Select all

local collision_mask_util = require("collision-mask-util")

-- Make it so saplings (and all trees, really) cannot be planted directly onto artificial tiles and these tiles cannot be placed where the saplings/trees are
local tree_collision_layer = collision_mask_util.get_first_unused_layer()

for _, tree in pairs(data.raw.tree) do
    local collisions = collision_mask_util.get_mask(tree)
    table.insert(collisions, tree_collision_layer)
    tree.collision_mask = collisions
end

local tiles = data.raw.tile
for _, item in pairs (data.raw.item) do
    if item.place_as_tile then
        local condition = item.place_as_tile.condition or {}
        table.insert(condition, tree_collision_layer)
        item.place_as_tile.condition = condition
        tiles[item.place_as_tile.result].check_collision_with_entities =  true
    end
end
Edit 2: Ah, finally got it. Apparently I was missing adding the collision layer to the tile itself somehow. I was trying to follow Klonan's example and didn't see him doing it there, but maybe I just missed it....
And I should probably use collision_mask_util.add_layer() in place of table.insert. I still need to get the mask, then add_layer(), then assign the new mask back to the prototype, but add_layer() also makes sure that the layer is only in there once.

Code: Select all

local collision_mask_util = require("collision-mask-util")

-- Make it so saplings (and all trees, really) cannot be planted directly onto artificial tiles and these tiles cannot be placed where the saplings/trees are
local tree_collision_layer = collision_mask_util.get_first_unused_layer()

for _, tree in pairs(data.raw.tree) do
    local collisions = collision_mask_util.get_mask(tree)
    collision_mask_util.add_layer(collisions, tree_collision_layer)
    tree.collision_mask = collisions
end

local tiles = data.raw.tile
for _, item in pairs (data.raw.item) do
    if item.place_as_tile and item.name ~= "landfill" then
        local condition = item.place_as_tile.condition or {}
        collision_mask_util.add_layer(condition, tree_collision_layer)
        item.place_as_tile.condition = condition
        local tile = tiles[item.place_as_tile.result]
        tile.check_collision_with_entities = true
        local collisions = collision_mask_util.get_mask(tile)
        collision_mask_util.add_layer(collisions, tree_collision_layer)
        tile.collision_mask = collisions
    end
end
Edit 3: Now I just have to account for mods like Dectorio that make regular ground tiles craftable.... :lol:
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

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

Re: [SOLVED] Make an entity unplaceable on stone path/concrete/refined concrete/etc?

Post by darkfrei »

FuryoftheStars wrote:
Sat May 14, 2022 11:53 pm
Anyone know if there's a collision_mask or other method (ie, do I need to make checks in control while placing?) that prevents an entity from being placed on path tiles, both vanilla and mod added? Basically, I want to make it so you can't plant a tree on anything but bare, regular ground. :)
See also
Don't build on ores
https://mods.factorio.com/mod/dont-build-on-ores

Biter Hates Concrete
https://mods.factorio.com/mod/Biter_Hates_Concrete

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2485
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: [SOLVED] Make an entity unplaceable on stone path/concrete/refined concrete/etc?

Post by FuryoftheStars »

darkfrei wrote:
Mon May 30, 2022 1:39 pm
FuryoftheStars wrote:
Sat May 14, 2022 11:53 pm
Anyone know if there's a collision_mask or other method (ie, do I need to make checks in control while placing?) that prevents an entity from being placed on path tiles, both vanilla and mod added? Basically, I want to make it so you can't plant a tree on anything but bare, regular ground. :)
See also
Don't build on ores
https://mods.factorio.com/mod/dont-build-on-ores

Biter Hates Concrete
https://mods.factorio.com/mod/Biter_Hates_Concrete
Thanks. I’ll take a look at those, too, next opportunity I get to see if there’s a different approach.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

Post Reply

Return to “Modding help”