2014-07-04 06:49:32 +02:00
|
|
|
local NODE_YOUNG = "young"
|
|
|
|
|
|
|
|
nature = {}
|
|
|
|
|
|
|
|
local function set_young_node(pos)
|
2014-07-05 08:01:24 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
2014-07-04 06:49:32 +02:00
|
|
|
|
|
|
|
meta:set_string(NODE_YOUNG, "true")
|
|
|
|
minetest.after(5,
|
|
|
|
function(pos)
|
2014-07-05 08:01:24 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
2014-07-04 06:49:32 +02:00
|
|
|
meta:set_string(NODE_YOUNG, "false")
|
|
|
|
end,
|
|
|
|
pos)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function is_not_young(pos)
|
2014-07-05 08:01:24 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
2014-07-04 06:49:32 +02:00
|
|
|
|
|
|
|
local young = meta:get_string(NODE_YOUNG)
|
|
|
|
return young ~= "true"
|
|
|
|
end
|
|
|
|
|
|
|
|
function nature:grow_node(pos, nodename)
|
|
|
|
if pos ~= nil then
|
2014-07-05 08:01:24 +02:00
|
|
|
local light_enough = minetest.get_node_light(pos, nil)
|
2014-07-04 06:49:32 +02:00
|
|
|
>= MINIMUM_GROWTH_LIGHT
|
|
|
|
|
|
|
|
if is_not_young(pos) and light_enough then
|
2014-07-05 08:01:24 +02:00
|
|
|
minetest.remove_node(pos)
|
2014-08-16 01:34:15 +02:00
|
|
|
minetest.set_node(pos, { name = nodename })
|
2014-07-04 06:49:32 +02:00
|
|
|
set_young_node(pos)
|
|
|
|
|
|
|
|
minetest.log("info", nodename .. " has grown at " .. pos.x .. ","
|
|
|
|
.. pos.y .. "," .. pos.z)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function nature:is_near_water(pos)
|
2014-07-05 08:01:24 +02:00
|
|
|
return minetest.find_node_near(pos, DISTANCE_FROM_WATER,
|
2014-07-04 06:49:32 +02:00
|
|
|
{ "default:water_source" }) ~= nil or DISTANCE_FROM_WATER == -1
|
|
|
|
end
|