How to create tiles that prevents building

Place to get help with not working mods / modding interface.
Post Reply
evildogbot100
Fast Inserter
Fast Inserter
Posts: 152
Joined: Sun Dec 18, 2016 3:02 pm
Contact:

How to create tiles that prevents building

Post by evildogbot100 »

Hello, I want to create tile that prevents the player from building on it but biters can still put a base on it. I tried to reverse engineer the building-platform mod but can't find the property that I wanted. How do I do it.

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

Re: How to create tiles that prevents building

Post by darkfrei »

data-final-fixes.lua

Code: Select all

---- Block all selected building added by all mod during data-updates phase.

-- By adding non craftable tile and restricted building the same collision_mask, the game make building footprint red outside building platform
-- Can't do the same with placeable tile as when tile are  placed and collide with something they just remove it without compensation. So a script take take of placeable tile check (see controls.lua). We don't add the collision to platform to avoid blocking a building completly (if not placeable outside A and outside B, then it's not placeable anywhere)

--just add the given layer to the item's collision mask
local function addLayerToCollision(item,layer)
	if not item  then return end
	if item.collision_mask then
		table.insert(item.collision_mask, layer);
	else
		item.collision_mask = {layer,"water-tile","player-layer"} --Most building does not have collision_mask by default and use the game engine to simulate one, so we need to manually add collision with player and water. Moreover when setting a mask we need to have at least two collision layer in it or they don't use it (for performance reason said a dev, reported as not a bug (link to thread?)).
	end
end

Code: Select all

if (settings.startup[buildingplatform.constants.blockTileOnPlatformSetting].value) then
	--Use layer-11 collision layer to block tile placement on platforms
	for _,tile in pairs(tiles) do
		if platformNames[tile.name] then
			addLayerToCollision(tile,"layer-11");
		end
		if(tile.minable) then
			local item = data.raw.item[tile.minable.result]
			if item and item.place_as_tile then
				table.insert(item.place_as_tile.condition,"layer-11")
			end
		end
	end
end

PyroFire
Filter Inserter
Filter Inserter
Posts: 356
Joined: Tue Mar 08, 2016 8:18 am
Contact:

Re: How to create tiles that prevents building

Post by PyroFire »

Your code didn't seem to work, but i got it to work again with some tinkering.

Code: Select all

local function addCollisionItem(item,layer) if(item)then if(item.collision_mask)then table.insert(item.collision_mask,layer) else item.collision_mask={layer,"water-tile","player-layer"} end end end
local function addCollisionTile(tile,layer) addCollisionItem(tile,layer)
	if(tile.minable)then local item=data.raw.item[tile.minable.result] if(item and item.place_as_tile)then table.insert(item.place_as_tile.condition,layer) end end
end

for k,tile in pairs(data.raw.tile)do if(not tile.name:find("concrete"))then
	addCollisionTile(tile,"layer-11")
end end

for i,d in pairs(data.raw["assembling-machine"])do
	local item=data.raw.item[d.name]
	if(item)then addCollisionItem(item,"layer-11") end
	addCollisionItem(d,"layer-11")
end

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

Re: How to create tiles that prevents building

Post by darkfrei »

This code was from 2017, I cannot say if it was tested or not today.

Note that result

Code: Select all

local item=data.raw.item[tile.minable.result]
can be sometimes defined as results
local list_of_results = tile.minable.results

So you need to iterate through all items and search connection between entities and items with item_prototype.place_result = entity_name.

Post Reply

Return to “Modding help”