mirror of
https://github.com/mt-mods/biome_lib.git
synced 2025-01-09 17:40:34 +01:00
Enable generating objects on sides or bottom of nodes at mapgen time (#2)
* biome_lib.register_on_generate now supports spawn_on_sides and spawn_on_bottom flags * biome_lib.register_on_generate now passes node position and face direction to node placement function * Replacing spaces with tabs * Fixing API to ensure it behaves same way it used to, when not passing spawn_on_sides or spawn_on_bottom flags.
This commit is contained in:
parent
4e3493a981
commit
823db77217
36
api.lua
36
api.lua
@ -309,12 +309,34 @@ function biome_lib.populate_surfaces(b, nodes_or_function_or_model, snodes, chec
|
|||||||
local spawned = false
|
local spawned = false
|
||||||
while tries < 2 and not spawned do
|
while tries < 2 and not spawned do
|
||||||
local pos = in_biome_nodes[math.random(1, num_in_biome_nodes)]
|
local pos = in_biome_nodes[math.random(1, num_in_biome_nodes)]
|
||||||
if biome.spawn_replace_node then
|
|
||||||
|
local will_place = true
|
||||||
|
local fdir = nil
|
||||||
|
if biome.random_facedir then
|
||||||
|
fdir = math.random(biome.random_facedir[1], biome.random_facedir[2])
|
||||||
|
end
|
||||||
|
|
||||||
|
if biome.spawn_on_side then
|
||||||
|
local onside = biome_lib.find_open_side(pos)
|
||||||
|
if onside then
|
||||||
|
pos = onside.newpos
|
||||||
|
fdir = onside.facedir
|
||||||
|
else
|
||||||
|
will_place = false
|
||||||
|
end
|
||||||
|
elseif biome.spawn_on_bottom then
|
||||||
|
if minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name == "air" then
|
||||||
|
pos.y = pos.y - 1
|
||||||
|
else
|
||||||
|
will_place = false
|
||||||
|
end
|
||||||
|
elseif biome.spawn_replace_node then
|
||||||
pos.y = pos.y-1
|
pos.y = pos.y-1
|
||||||
end
|
end
|
||||||
|
|
||||||
local p_top = { x = pos.x, y = pos.y + 1, z = pos.z }
|
local p_top = { x = pos.x, y = pos.y + 1, z = pos.z }
|
||||||
|
|
||||||
if not (biome.avoid_nodes and biome.avoid_radius
|
if will_place and not (biome.avoid_nodes and biome.avoid_radius
|
||||||
and minetest.find_node_near(p_top, biome.avoid_radius
|
and minetest.find_node_near(p_top, biome.avoid_radius
|
||||||
+ math.random(-1.5,2), biome.avoid_nodes)) then
|
+ math.random(-1.5,2), biome.avoid_nodes)) then
|
||||||
if biome.delete_above then
|
if biome.delete_above then
|
||||||
@ -346,10 +368,6 @@ function biome_lib.populate_surfaces(b, nodes_or_function_or_model, snodes, chec
|
|||||||
biome_lib.dbg("An L-tree was spawned at "..minetest.pos_to_string(p_top), 4)
|
biome_lib.dbg("An L-tree was spawned at "..minetest.pos_to_string(p_top), 4)
|
||||||
spawned = true
|
spawned = true
|
||||||
else
|
else
|
||||||
local fdir = nil
|
|
||||||
if biome.random_facedir then
|
|
||||||
fdir = math.random(biome.random_facedir[1], biome.random_facedir[2])
|
|
||||||
end
|
|
||||||
local n=nodes_or_function_or_model[math.random(#nodes_or_function_or_model)]
|
local n=nodes_or_function_or_model[math.random(#nodes_or_function_or_model)]
|
||||||
minetest.swap_node(p_top, { name = n, param2 = fdir })
|
minetest.swap_node(p_top, { name = n, param2 = fdir })
|
||||||
biome_lib.dbg("Node \""..n.."\" was randomly picked from a list and placed at "..minetest.pos_to_string(p_top), 4)
|
biome_lib.dbg("Node \""..n.."\" was randomly picked from a list and placed at "..minetest.pos_to_string(p_top), 4)
|
||||||
@ -357,15 +375,11 @@ function biome_lib.populate_surfaces(b, nodes_or_function_or_model, snodes, chec
|
|||||||
end
|
end
|
||||||
elseif objtype == "string" and
|
elseif objtype == "string" and
|
||||||
minetest.registered_nodes[nodes_or_function_or_model] then
|
minetest.registered_nodes[nodes_or_function_or_model] then
|
||||||
local fdir = nil
|
|
||||||
if biome.random_facedir then
|
|
||||||
fdir = math.random(biome.random_facedir[1], biome.random_facedir[2])
|
|
||||||
end
|
|
||||||
minetest.swap_node(p_top, { name = nodes_or_function_or_model, param2 = fdir })
|
minetest.swap_node(p_top, { name = nodes_or_function_or_model, param2 = fdir })
|
||||||
biome_lib.dbg("Node \""..nodes_or_function_or_model.."\" was placed at "..minetest.pos_to_string(p_top), 4)
|
biome_lib.dbg("Node \""..nodes_or_function_or_model.."\" was placed at "..minetest.pos_to_string(p_top), 4)
|
||||||
spawned = true
|
spawned = true
|
||||||
elseif objtype == "function" then
|
elseif objtype == "function" then
|
||||||
nodes_or_function_or_model(pos)
|
nodes_or_function_or_model(pos, fdir)
|
||||||
biome_lib.dbg("A function was run on surface node at "..minetest.pos_to_string(pos), 4)
|
biome_lib.dbg("A function was run on surface node at "..minetest.pos_to_string(pos), 4)
|
||||||
spawned = true
|
spawned = true
|
||||||
elseif objtype == "string" and pcall(loadstring(("return %s(...)"):
|
elseif objtype == "string" and pcall(loadstring(("return %s(...)"):
|
||||||
|
Loading…
Reference in New Issue
Block a user