From 94770d713bcedd40ede30b77ab202db052e72d01 Mon Sep 17 00:00:00 2001 From: Vanessa Ezekowitz Date: Fri, 11 Jan 2013 11:52:34 -0500 Subject: [PATCH] extended the API again - this time adding a function to allow a custom check for air surrounding the plant spawn location (defaults to 1, just the target node). Values of 1 and 9 for the two new variables would check the 3x3 area around the spawn location. Don't make these numbers too large or it will slow the abm down. --- API.txt | 4 ++++ plants_lib/init.lua | 13 +++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/API.txt b/API.txt index 42fefc9..cc6fb38 100644 --- a/API.txt +++ b/API.txt @@ -88,6 +88,10 @@ sbiomesize: How large of an area to check for the above node. Defaults to 0. sbiomecount: How many of the above nodes must be within that radius. Defaults to 1. +airradius: How large of an area to check for air around the target. + Defaults to 0 (only check the target). +aircount: How many of the surrounding nodes need to be air for the + above check to return true. Defaults to 1. By default, if a biome node, size, and count are not defined, the biome checking is disabled. Same holds true for the nneighbors bit above that. diff --git a/plants_lib/init.lua b/plants_lib/init.lua index f5bcf1b..cb96940 100644 --- a/plants_lib/init.lua +++ b/plants_lib/init.lua @@ -35,7 +35,7 @@ end -- The spawning ABM -spawn_on_surfaces = function(sdelay, splant, sradius, schance, ssurface, savoid, seed_diff, lightmin, lightmax, nneighbors, ocount, facedir, depthmax, altmin, altmax, sbiome, sbiomesize, sbiomecount) +spawn_on_surfaces = function(sdelay, splant, sradius, schance, ssurface, savoid, seed_diff, lightmin, lightmax, nneighbors, ocount, facedir, depthmax, altmin, altmax, sbiome, sbiomesize, sbiomecount, airsize, aircount) if seed_diff == nil then seed_diff = 0 end if lightmin == nil then lightmin = 0 end if lightmax == nil then lightmax = LIGHT_MAX end @@ -47,6 +47,8 @@ spawn_on_surfaces = function(sdelay, splant, sradius, schance, ssurface, savoid, if sbiome == nil then sbiome = "" end if sbiomesize == nil then sbiomesize = 0 end if sbiomecount == nil then sbiomecount = 1 end + if airsize == nil then airsize = 0 end + if aircount == nil then aircount = 1 end minetest.register_abm({ nodenames = { ssurface }, interval = sdelay, @@ -57,17 +59,16 @@ spawn_on_surfaces = function(sdelay, splant, sradius, schance, ssurface, savoid, local n_top = minetest.env:get_node(p_top) 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}) - if noise > plantlife_limit and n_top.name == "air" and is_node_loaded(p_top) then + if noise > plantlife_limit and is_node_loaded(p_top) then 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 and n_light >= lightmin 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 or ocount == -1) - and - (table.getn(minetest.env:find_nodes_in_area({x=pos.x-sbiomesize, y=pos.y-1, z=pos.z-sbiomesize}, {x=pos.x+sbiomesize, y=pos.y+1, z=pos.z+sbiomesize}, sbiome)) >= sbiomecount + and (table.getn(minetest.env:find_nodes_in_area({x=pos.x-sbiomesize, y=pos.y-1, z=pos.z-sbiomesize}, {x=pos.x+sbiomesize, y=pos.y+1, z=pos.z+sbiomesize}, sbiome)) >= sbiomecount or sbiome == "") + and table.getn(minetest.env:find_nodes_in_area({x=p_top.x-airsize, y=p_top.y, z=p_top.z-airsize}, {x=p_top.x+airsize, y=p_top.y, z=p_top.z+airsize}, "air")) >= aircount and pos.y >= altmin and pos.y <= altmax then