Added feature to API to allow for limits on spawning altitude also. None of

the included plants use this, it's mainly for the conifers mod.
This commit is contained in:
Vanessa Ezekowitz 2012-12-29 17:24:47 -05:00
parent f9df1b5965
commit e2794f71f4
2 changed files with 30 additions and 22 deletions

View File

@ -14,11 +14,12 @@ dbg()
----- -----
The first of these, spawn_on_surfaces() is defined with quite a large number The first of these, spawn_on_surfaces() is defined with quite a large number
of variables: of variables. All of the variables below, if specified at all, must be
specified exactly in the order given here.
spawn_on_surfaces = function(sdelay, splant, sradius, schance, ssurface, spawn_on_surfaces = function(sdelay, splant, sradius, schance, ssurface,
savoid, seed_diff, lightmin, lightmax, nneighbors, savoid, seed_diff, lightmin, lightmax, nneighbors,
ocount, facedir) ocount, facedir, depthmax, altitudemin, altitudemax)
The first several of these are all required, and are from the last version of The first several of these are all required, and are from the last version of
the flowers mod, so this part of the API should be the same as before. the flowers mod, so this part of the API should be the same as before.
@ -68,6 +69,9 @@ facedir: The value passed to the param2 variable when adding the plant node
to the map. Defaults to 0. to the map. Defaults to 0.
depthmax: If a node spawns on top of a water source, the water must be at depthmax: If a node spawns on top of a water source, the water must be at
most this deep. Defaults to 1 node. most this deep. Defaults to 1 node.
altitudemin: Items must be at this altitude or higher to spawn at all.
Defaults to -31000.
altitudemax: But no higher than this altitude. Defaults to +31000.
----- -----
The second function, grow_plants() is defined like so: The second function, grow_plants() is defined like so:

View File

@ -12,7 +12,7 @@
-- Various settings - most of these probably won't need to be changed -- Various settings - most of these probably won't need to be changed
local plantlife_debug = false -- ...unless you want the modpack to spam the console ;-) local plantlife_debug = true -- ...unless you want the modpack to spam the console ;-)
local plantlife_seed_diff = 123 local plantlife_seed_diff = 123
local perlin_octaves = 3 local perlin_octaves = 3
@ -45,13 +45,15 @@ end
-- The spawning ABM -- The spawning ABM
spawn_on_surfaces = function(sdelay, splant, sradius, schance, ssurface, savoid, seed_diff, lightmin, lightmax, nneighbors, ocount, facedir, depthmax) spawn_on_surfaces = function(sdelay, splant, sradius, schance, ssurface, savoid, seed_diff, lightmin, lightmax, nneighbors, ocount, facedir, depthmax, altmin, altmax)
if seed_diff == nil then seed_diff = 0 end if seed_diff == nil then seed_diff = 0 end
if lightmin == nil then lightmin = 0 end if lightmin == nil then lightmin = 0 end
if lightmax == nil then lightmax = LIGHT_MAX end if lightmax == nil then lightmax = LIGHT_MAX end
if nneighbors == nil then nneighbors = ssurface end if nneighbors == nil then nneighbors = ssurface end
if ocount == nil then ocount = 0 end if ocount == nil then ocount = 0 end
if depthmax == nil then depthmax = 1 end if depthmax == nil then depthmax = 1 end
if altmin == nil then altmin = -31000 end
if altmax == nil then altmax = 31000 end
minetest.register_abm({ minetest.register_abm({
nodenames = { ssurface }, nodenames = { ssurface },
interval = sdelay, interval = sdelay,
@ -62,26 +64,28 @@ spawn_on_surfaces = function(sdelay, splant, sradius, schance, ssurface, savoid,
local n_top = minetest.env:get_node(p_top) local n_top = minetest.env:get_node(p_top)
local perlin = minetest.env:get_perlin(seed_diff, perlin_octaves, perlin_persistence, perlin_scale ) local perlin = minetest.env:get_perlin(seed_diff, perlin_octaves, perlin_persistence, perlin_scale )
local noise = perlin:get2d({x=p_top.x, y=p_top.z}) local noise = perlin:get2d({x=p_top.x, y=p_top.z})
if ( noise > plantlife_limit ) and (n_top.name == "air") and is_node_loaded(p_top) then if noise > plantlife_limit and n_top.name == "air" and is_node_loaded(p_top) then
local n_light = minetest.env:get_node_light(p_top, nil) local n_light = minetest.env:get_node_light(p_top, nil)
if (minetest.env:find_node_near(p_top, sradius + math.random(-1.5,2), savoid) == nil ) if minetest.env:find_node_near(p_top, sradius + math.random(-1.5,2), savoid) == nil
and (n_light >= lightmin) and n_light >= lightmin
and (n_light <= lightmax) and n_light <= lightmax
and table.getn(minetest.env:find_nodes_in_area({x=pos.x-1, y=pos.y, z=pos.z-1}, {x=pos.x+1, y=pos.y, z=pos.z+1}, nneighbors)) > ocount and table.getn(minetest.env:find_nodes_in_area({x=pos.x-1, y=pos.y, z=pos.z-1}, {x=pos.x+1, y=pos.y, z=pos.z+1}, nneighbors)) > ocount
then and pos.y >= altmin
local walldir = plant_valid_wall(p_top) and pos.y <= altmax
if splant == "poisonivy:seedling" and walldir ~= nil then then
dbg("Spawn: poisonivy:climbing at "..dump(p_top).." on "..ssurface) local walldir = plant_valid_wall(p_top)
minetest.env:add_node(p_top, { name = "poisonivy:climbing", param2 = walldir }) if splant == "poisonivy:seedling" and walldir ~= nil then
else dbg("Spawn: poisonivy:climbing at "..dump(p_top).." on "..ssurface)
local deepnode = minetest.env:get_node({ x = pos.x, y = pos.y-depthmax-1, z = pos.z }).name minetest.env:add_node(p_top, { name = "poisonivy:climbing", param2 = walldir })
if (ssurface ~= "default:water_source") else
or (ssurface == "default:water_source" local deepnode = minetest.env:get_node({ x = pos.x, y = pos.y-depthmax-1, z = pos.z }).name
and deepnode ~= "default:water_source") then if (ssurface ~= "default:water_source")
dbg("Spawn: "..splant.." at "..dump(p_top).." on "..ssurface) or (ssurface == "default:water_source"
minetest.env:add_node(p_top, { name = splant, param2 = facedir }) and deepnode ~= "default:water_source") then
dbg("Spawn: "..splant.." at "..dump(p_top).." on "..ssurface)
minetest.env:add_node(p_top, { name = splant, param2 = facedir })
end
end end
end
end end
end end
end end