diff --git a/API.txt b/API.txt index 13cab6a..5d3db83 100644 --- a/API.txt +++ b/API.txt @@ -198,13 +198,12 @@ gresult: Name of the node into which the above should transform dry_early_node: This value is ignored except for jungle grass, where it indicates which node the grass must be on in order for it to turn from "short" to default:dry_shrub. -grow_nodes: This node must be under the plant in order for it to grow - at all. Normally this should be the same as the list of +grow_nodes: One of these nodes must be under the plant in order for it to + grow at all. Normally this should be the same as the list of surfaces passed to the spawning ABM as the "nodenames" - parameter, such as {"default:dirt_with_grass", - "default:sand"}. This is so that the plant can be - manually placed on something like a flower pot or - something without it growing and eventually dieing. + parameter. This is so that the plant can be manually placed + on something like a flower pot or something without it growing + and eventually dieing. Defaults to "default:dirt_with_grass". facedir: Same as with spawning a plant. If supplied, this value is passed to the param2 variable when changing the plant. If nil or left out, no new param2 value is applied. @@ -229,8 +228,9 @@ grow_function: String indicating what function to use to grow the plant, if parameter for the current position, followed by the "can grow here" and temperature map Perlin values at that location. If it's a table, the tree described by that table is spawned at - the current position. In both cases, all parameters from - gresult to ground_nodes are ignored. + the current position. In both string and table cases, all + parameters from gresult to ground_nodes, except for + grow_nodes, are ignored. seed_diff: The Perlin seed diff to be use to calculate the first noise value given to the above grow_function. Should be the same as the seed diff used when first spawning the plant that's being diff --git a/plants_lib/init.lua b/plants_lib/init.lua index 944ee19..c68f7e6 100644 --- a/plants_lib/init.lua +++ b/plants_lib/init.lua @@ -213,7 +213,7 @@ function plantslib:grow_plants( if need_wall ~= true then need_wall = false end if grow_vertically ~= true then grow_vertically = false end if height_limit == nil then height_limit = 62000 end - if ground_node == nil then ground_nodes = { "default:dirt_with_grass" } end + if ground_nodes == nil then ground_nodes = { "default:dirt_with_grass" } end minetest.register_abm({ nodenames = { gplant }, interval = gdelay, @@ -223,9 +223,9 @@ function plantslib:grow_plants( local p_bot = {x=pos.x, y=pos.y-1, z=pos.z} local n_top = minetest.env:get_node(p_top) local n_bot = minetest.env:get_node(p_bot) - local groundnode = minetest.env:get_node({x=pos.x, y=pos.y-height_limit, z=pos.z}) - if grow_function == nil then - if string.find(dump(grow_nodes), n_bot.name) ~= nil and n_top.name == "air" then + local root_node = minetest.env:get_node({x=pos.x, y=pos.y-height_limit, z=pos.z}) + if string.find(dump(grow_nodes), n_bot.name) ~= nil and n_top.name == "air" then + if grow_function == nil then if grow_vertically then if plantslib:find_first_node(pos, height_limit, ground_nodes) ~= nil then if need_wall then @@ -257,20 +257,20 @@ function plantslib:grow_plants( minetest.env:add_node(pos, { name = gresult, param2 = facedir }) end end - end - else - if seed_diff == nil then seed_diff = 0 end - local perlin1 = minetest.env:get_perlin(seed_diff, perlin_octaves, perlin_persistence, perlin_scale) - local perlin2 = minetest.env:get_perlin(temperature_seeddiff, temperature_octaves, temperature_persistence, temperature_scale) - 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)) - minetest.env:remove_node(pos) - minetest.env:spawn_tree(pos, grow_function) else - dbg("Call function: "..grow_function.."("..dump(pos)..","..noise1..","..noise2..")") - assert(loadstring(grow_function.."("..dump(pos)..","..noise1..","..noise2..")"))() + if seed_diff == nil then seed_diff = 0 end + local perlin1 = minetest.env:get_perlin(seed_diff, perlin_octaves, perlin_persistence, perlin_scale) + local perlin2 = minetest.env:get_perlin(temperature_seeddiff, temperature_octaves, temperature_persistence, temperature_scale) + 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)) + minetest.env:remove_node(pos) + minetest.env:spawn_tree(pos, grow_function) + else + dbg("Call function: "..grow_function.."("..dump(pos)..","..noise1..","..noise2..")") + assert(loadstring(grow_function.."("..dump(pos)..","..noise1..","..noise2..")"))() + end end end end