2015-02-09 05:17:02 +01:00
|
|
|
-- helper functions
|
|
|
|
|
|
|
|
minetest.register_globalstep(function(dtime)
|
|
|
|
nature.dtime = dtime
|
|
|
|
if #nature.blossomqueue > 0 and dtime < 0.2 then
|
|
|
|
local pos = nature.blossomqueue[1][1]
|
|
|
|
local node = nature.blossomqueue[1][2]
|
2015-04-02 12:16:50 +02:00
|
|
|
local replace = nature.blossomqueue[1][3]
|
|
|
|
if (nature.blossomqueue[1][3] == nature.blossom_node and not nature:is_near_water(pos)) then
|
2015-02-09 05:17:02 +01:00
|
|
|
table.remove(nature.blossomqueue, 1) -- don't grow if it's not near water, pop from queue.
|
|
|
|
return
|
|
|
|
end
|
2015-04-02 12:16:50 +02:00
|
|
|
nature:grow_node(pos, replace) -- now actually grow it.
|
2015-02-09 05:17:02 +01:00
|
|
|
table.remove(nature.blossomqueue, 1)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2015-04-02 12:16:50 +02:00
|
|
|
function nature.enqueue_node(pos, node, replace)
|
2015-02-09 05:17:02 +01:00
|
|
|
local idx = #nature.blossomqueue
|
|
|
|
nature.blossomqueue[idx+1] = {}
|
|
|
|
nature.blossomqueue[idx+1][1] = pos
|
|
|
|
nature.blossomqueue[idx+1][2] = node
|
2015-04-02 12:16:50 +02:00
|
|
|
nature.blossomqueue[idx+1][3] = replace
|
2015-02-09 05:17:02 +01:00
|
|
|
end
|
2014-07-04 06:49:32 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
2015-02-09 05:17:02 +01:00
|
|
|
meta:set_string(nature.node_young, nature.setting_true)
|
|
|
|
minetest.after(nature.youth_delay,
|
2014-10-31 21:09:32 +01:00
|
|
|
function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
2015-02-09 05:17:02 +01:00
|
|
|
meta:set_string(nature.node_young, nature.setting_false)
|
2014-10-31 21:09:32 +01:00
|
|
|
end,
|
2014-07-04 06:49:32 +02:00
|
|
|
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
|
|
|
|
2015-02-09 05:17:02 +01:00
|
|
|
local young = meta:get_string(nature.node_young)
|
|
|
|
return young ~= nature.setting_true
|
2014-07-04 06:49:32 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function nature:grow_node(pos, nodename)
|
|
|
|
if pos ~= nil then
|
2015-02-09 18:50:32 +01:00
|
|
|
local light_enough = (minetest.get_node_light(pos, nil) or 0)
|
2015-02-09 05:17:02 +01:00
|
|
|
>= nature.minimum_growth_light
|
2014-07-04 06:49:32 +02:00
|
|
|
|
2014-10-31 21:09:32 +01:00
|
|
|
if is_not_young(pos) and light_enough then
|
|
|
|
minetest.remove_node(pos)
|
|
|
|
minetest.set_node(pos, { name = nodename })
|
|
|
|
set_young_node(pos)
|
2014-07-04 06:49:32 +02:00
|
|
|
|
2014-10-31 21:09:32 +01:00
|
|
|
minetest.log("info", nodename .. " has grown at " .. pos.x .. ","
|
|
|
|
.. pos.y .. "," .. pos.z)
|
|
|
|
end
|
2014-07-04 06:49:32 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function nature:is_near_water(pos)
|
2015-02-09 05:17:02 +01:00
|
|
|
return nature.distance_from_water == -1 or minetest.find_node_near(pos, nature.distance_from_water,
|
2014-10-31 21:09:32 +01:00
|
|
|
{ "default:water_source" }) ~= nil
|
2014-07-04 06:49:32 +02:00
|
|
|
end
|