forked from mtcontrib/plantlife_modpack
fixed bugs in use of debugging function from having class-ified it.
This commit is contained in:
parent
e327630ea5
commit
592d0df84f
@ -11,7 +11,7 @@
|
||||
|
||||
plantslib = {}
|
||||
|
||||
local DEBUG = false --... except if you want to spam the console with debugging info :-)
|
||||
local DEBUG = true --... except if you want to spam the console with debugging info :-)
|
||||
|
||||
plantslib.plantlife_seed_diff = 329 -- needs to be global so other mods can see it
|
||||
|
||||
@ -38,8 +38,11 @@ function plantslib:is_node_loaded(node_pos)
|
||||
return true
|
||||
end
|
||||
|
||||
function dbg(msg)
|
||||
if DEBUG then minetest.log("verbose", msg) end
|
||||
function plantslib:dbg(msg)
|
||||
if DEBUG then
|
||||
print("[Plantlife] "..msg)
|
||||
minetest.log("verbose", "[Plantlife] "..msg)
|
||||
end
|
||||
end
|
||||
|
||||
-- Spawn plants using the map generator
|
||||
@ -61,7 +64,7 @@ function plantslib:search_for_surfaces(minp, maxp, biome, funct_or_model)
|
||||
if biome.temp_max == nil then biome.temp_max = -1 end
|
||||
if biome.rarity == nil then biome.rarity = 50 end
|
||||
|
||||
dbg("Started checking generated mapblock volume...")
|
||||
plantslib:dbg("Started checking generated mapblock volume...")
|
||||
local searchnodes = minetest.env:find_nodes_in_area(minp, maxp, biome.surface)
|
||||
local in_biome_nodes = {}
|
||||
local num_in_biome_nodes = 0
|
||||
@ -88,18 +91,18 @@ function plantslib:search_for_surfaces(minp, maxp, biome, funct_or_model)
|
||||
end
|
||||
end
|
||||
|
||||
dbg("Found "..num_in_biome_nodes.." surface nodes of type "..biome.surface.." in 5x5x5 mapblock volume at {"..dump(minp)..":"..dump(maxp).."} to check.")
|
||||
plantslib:dbg("Found "..num_in_biome_nodes.." surface nodes of type "..biome.surface.." in 5x5x5 mapblock volume at {"..dump(minp)..":"..dump(maxp).."} to check.")
|
||||
|
||||
for i in ipairs(in_biome_nodes) do
|
||||
local pos = in_biome_nodes[i]
|
||||
local p_top = { x = pos.x, y = pos.y + 1, z = pos.z }
|
||||
if minetest.env:find_node_near(p_top, biome.avoid_radius + math.random(-1.5,1.5), biome.avoid_nodes) == nil then
|
||||
if type(funct_or_model) == "table" then
|
||||
dbg("Spawn tree at {"..dump(pos).."}")
|
||||
plantslib:dbg("Spawn tree at {"..dump(pos).."}")
|
||||
minetest.env:spawn_tree(pos, funct_or_model)
|
||||
else
|
||||
dbg("Call function: "..funct_or_model.."("..dump(pos)..")")
|
||||
dbg("Call function: "..funct_or_model.."("..dump(pos)..")")
|
||||
plantslib:dbg("Call function: "..funct_or_model.."("..dump(pos)..")")
|
||||
plantslib:dbg("Call function: "..funct_or_model.."("..dump(pos)..")")
|
||||
assert(loadstring(funct_or_model.."("..dump(pos)..")"))()
|
||||
end
|
||||
end
|
||||
@ -177,14 +180,14 @@ function plantslib:spawn_on_surfaces(
|
||||
then
|
||||
local walldir = plantslib:plant_valid_wall(p_top)
|
||||
if splant == "poisonivy:seedling" and walldir ~= nil then
|
||||
dbg("Spawn: poisonivy:climbing at "..dump(p_top).." on "..ssurface)
|
||||
plantslib:dbg("Spawn: poisonivy:climbing at "..dump(p_top).." on "..ssurface)
|
||||
minetest.env:add_node(p_top, { name = "poisonivy:climbing", param2 = walldir })
|
||||
else
|
||||
local deepnode = minetest.env:get_node({ x = pos.x, y = pos.y-depthmax-1, z = pos.z }).name
|
||||
if (ssurface ~= "default:water_source")
|
||||
or (ssurface == "default:water_source"
|
||||
and deepnode ~= "default:water_source") then
|
||||
dbg("Spawn: "..splant.." at "..dump(p_top).." on "..ssurface)
|
||||
plantslib:dbg("Spawn: "..splant.." at "..dump(p_top).." on "..ssurface)
|
||||
minetest.env:add_node(p_top, { name = splant, param2 = facedir })
|
||||
end
|
||||
end
|
||||
@ -214,6 +217,7 @@ function plantslib:grow_plants(
|
||||
if grow_vertically ~= true then grow_vertically = false end
|
||||
if height_limit == nil then height_limit = 62000 end
|
||||
if ground_nodes == nil then ground_nodes = { "default:dirt_with_grass" } end
|
||||
if grow_nodes == nil then grow_nodes = { "default:dirt_with_grass" } end
|
||||
minetest.register_abm({
|
||||
nodenames = { gplant },
|
||||
interval = gdelay,
|
||||
@ -231,26 +235,26 @@ function plantslib:grow_plants(
|
||||
if need_wall then
|
||||
local walldir=plantslib:plant_valid_wall(p_top)
|
||||
if walldir ~= nil then
|
||||
dbg("Grow: "..gplant.." upwards to ("..dump(p_top)..") on wall "..walldir)
|
||||
plantslib:dbg("Grow: "..gplant.." upwards to ("..dump(p_top)..") on wall "..walldir)
|
||||
minetest.env:add_node(p_top, { name = gplant, param2 = walldir })
|
||||
end
|
||||
else
|
||||
dbg("Grow: "..gplant.." upwards to ("..dump(p_top)..")")
|
||||
plantslib:dbg("Grow: "..gplant.." upwards to ("..dump(p_top)..")")
|
||||
minetest.env:add_node(p_top, { name = gplant })
|
||||
end
|
||||
end
|
||||
|
||||
-- corner case for changing short junglegrass to dry shrub in desert
|
||||
elseif n_bot.name == dry_early_node and gplant == "junglegrass:short" then
|
||||
dbg("Die: "..gplant.." becomes default:dry_shrub at ("..dump(pos)..")")
|
||||
plantslib:dbg("Die: "..gplant.." becomes default:dry_shrub at ("..dump(pos)..")")
|
||||
minetest.env:add_node(pos, { name = "default:dry_shrub" })
|
||||
|
||||
elseif gresult == nil then
|
||||
dbg("Die: "..gplant.." at ("..dump(pos)..")")
|
||||
plantslib:dbg("Die: "..gplant.." at ("..dump(pos)..")")
|
||||
minetest.env:remove_node(pos)
|
||||
|
||||
elseif gresult ~= nil then
|
||||
dbg("Grow: "..gplant.." becomes "..gresult.." at ("..dump(pos)..")")
|
||||
plantslib:dbg("Grow: "..gplant.." becomes "..gresult.." at ("..dump(pos)..")")
|
||||
if facedir == nil then
|
||||
minetest.env:add_node(pos, { name = gresult })
|
||||
else
|
||||
@ -264,11 +268,11 @@ function plantslib:grow_plants(
|
||||
local noise1 = perlin1:get2d({x=p_top.x, y=p_top.z})
|
||||
local noise2 = perlin2:get2d({x=p_top.x, y=p_top.z})
|
||||
if type(grow_function) == "table" then
|
||||
dbg("Grow sapling into tree at "..dump(pos))
|
||||
plantslib:dbg("Grow sapling into tree at "..dump(pos))
|
||||
minetest.env:remove_node(pos)
|
||||
minetest.env:spawn_tree(pos, grow_function)
|
||||
else
|
||||
dbg("Call function: "..grow_function.."("..dump(pos)..","..noise1..","..noise2..")")
|
||||
plantslib:dbg("Call function: "..grow_function.."("..dump(pos)..","..noise1..","..noise2..")")
|
||||
assert(loadstring(grow_function.."("..dump(pos)..","..noise1..","..noise2..")"))()
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user