More adaptive foundation height

This commit is contained in:
cora 2022-08-10 15:14:51 +02:00
parent 0bcbea4ce3
commit 79ce9f89d3

@ -59,9 +59,24 @@ local function smooth_cube(nn,pos,plane,amnt)
return r return r
end end
local function get_foundation_nodes(ground_p1,ground_p2,pos,sidelen) local function find_ground(pos,nn,gn)
local replace = {"air","group:liquid","mcl_core:snow","group:tree","group:leaves","group:plant"} local r = 0
local nn = smooth_cube(minetest.find_nodes_in_area(vector.offset(ground_p1,0,-1,0),vector.offset(ground_p2,0,-30,0),replace),vector.offset(pos,0,-30,0),true,sidelen * 64) for _,v in pairs(nn) do
local p=vector.new(v)
repeat
local n = minetest.get_node(p).name
p = vector.offset(p,0,-1,0)
until not n or n == "mcl_core:bedrock" or n == "ignore" or n == gn
--minetest.log(tostring(pos.y - p.y))
if pos.y - p.y > r then r = pos.y - p.y end
end
return r
end
local function get_foundation_nodes(ground_p1,ground_p2,pos,sidelen,node_stone)
local replace = {"air","group:liquid","mcl_core:snow","group:tree","group:leaves","group:plant","grass_block","group:dirt"}
local depth = find_ground(pos,minetest.find_nodes_in_area(ground_p1,ground_p2,replace),node_stone)
local nn = smooth_cube(minetest.find_nodes_in_area(vector.offset(ground_p1,0,-1,0),vector.offset(ground_p2,0,-depth,0),replace),vector.offset(pos,0,-depth,0),true,sidelen * 64)
local stone = {} local stone = {}
local filler = {} local filler = {}
local top = {} local top = {}
@ -86,7 +101,6 @@ local function get_foundation_nodes(ground_p1,ground_p2,pos,sidelen)
end end
local function foundation(ground_p1,ground_p2,pos,sidelen) local function foundation(ground_p1,ground_p2,pos,sidelen)
local stone,filler,top,dust = get_foundation_nodes(ground_p1,ground_p2,pos,sidelen)
local node_stone = "mcl_core:stone" local node_stone = "mcl_core:stone"
local node_filler = "mcl_core:dirt" local node_filler = "mcl_core:dirt"
local node_top = "mcl_core:dirt_with_grass" or minetest.get_node(ground_p1).name local node_top = "mcl_core:dirt_with_grass" or minetest.get_node(ground_p1).name
@ -103,7 +117,8 @@ local function foundation(ground_p1,ground_p2,pos,sidelen)
end end
end end
minetest.bulk_set_node(top,{name=node_top}) local stone,filler,top,dust = get_foundation_nodes(ground_p1,ground_p2,pos,sidelen,node_stone)
minetest.bulk_set_node(top,{name=node_top},node_stone)
if node_dust then if node_dust then
minetest.bulk_set_node(dust,{name=node_dust}) minetest.bulk_set_node(dust,{name=node_dust})