structure-api: add check for solid ground

This commit is contained in:
cora 2022-06-22 16:47:43 +02:00
parent 8e976d9191
commit 0b3a4c18d7
2 changed files with 15 additions and 10 deletions

View file

@ -14,16 +14,8 @@ mcl_structures.register_structure("nether_outpost",{
}, },
flags = "all_floors", flags = "all_floors",
biomes = {"Nether","SoulsandValley","WarpedForest","CrimsonForest","BasaltDelta"}, biomes = {"Nether","SoulsandValley","WarpedForest","CrimsonForest","BasaltDelta"},
on_place = function(pos,def,pr) sidelen = 15,
local sidelen = 15 solid_ground = true,
local node = minetest.get_node(vector.offset(pos,1,1,0))
local solid = minetest.find_nodes_in_area(vector.offset(pos,-sidelen/2,-1,-sidelen/2),vector.offset(pos,sidelen/2,-1,sidelen/2),{"group:solid"})
local air = minetest.find_nodes_in_area(vector.offset(pos,-sidelen/2,1,-sidelen/2),vector.offset(pos,sidelen/2,4,sidelen/2),{"air"})
if #solid < ( sidelen * sidelen ) or
#air < (sidelen * sidelen ) then return false end
minetest.bulk_set_node(solid,node)
return true
end,
y_min = mcl_vars.mg_lava_nether_max, y_min = mcl_vars.mg_lava_nether_max,
y_max = mcl_vars.mg_nether_max - 30, y_max = mcl_vars.mg_nether_max - 30,
filenames = { modpath.."/schematics/nether_outpost.mts" }, filenames = { modpath.."/schematics/nether_outpost.mts" },

View file

@ -9,6 +9,19 @@ function mcl_structures.place_structure(pos, def, pr)
elseif def.y_offset then elseif def.y_offset then
y_offset = def.y_offset y_offset = def.y_offset
end end
if def.solid_ground and def.sidelen then
local node = minetest.get_node(vector.offset(pos,1,1,0))
local solid = minetest.find_nodes_in_area(vector.offset(pos,-def.sidelen/2,-1,-def.sidelen/2),vector.offset(pos,def.sidelen/2,-1,def.sidelen/2),{"group:solid"})
local air = minetest.find_nodes_in_area(vector.offset(pos,-def.sidelen/2,1,-def.sidelen/2),vector.offset(pos,def.sidelen/2,4,def.sidelen/2),{"air"})
if #solid < ( def.sidelen * def.sidelen ) or
#air < (def.sidelen * def.sidelen ) then
if logging then
minetest.log("warning","[mcl_structures] "..def.name.." at "..minetest.pos_to_string(pos).." not placed. No solid ground.")
end
return false
end
--minetest.bulk_set_node(solid,node)
end
if def.on_place and not def.on_place(pos,def,pr) then if def.on_place and not def.on_place(pos,def,pr) then
if logging then if logging then
minetest.log("warning","[mcl_structures] "..def.name.." at "..minetest.pos_to_string(pos).." not placed. Conditions not satisfied.") minetest.log("warning","[mcl_structures] "..def.name.." at "..minetest.pos_to_string(pos).." not placed. Conditions not satisfied.")