Refactored nature classic global functions

This commit is contained in:
neko259 2014-10-31 22:09:32 +02:00
parent 7a513e85b1
commit b16a5f0a68

View File

@ -1,15 +1,20 @@
local NODE_YOUNG = "young"
local SETTING_TRUE = "true"
local SETTING_FALSE = "false"
local YOUTH_DELAY = 5
nature = {}
local function set_young_node(pos)
local meta = minetest.get_meta(pos)
meta:set_string(NODE_YOUNG, "true")
minetest.after(5,
meta:set_string(NODE_YOUNG, SETTING_TRUE)
minetest.after(YOUTH_DELAY,
function(pos)
local meta = minetest.get_meta(pos)
meta:set_string(NODE_YOUNG, "false")
meta:set_string(NODE_YOUNG, SETTING_FALSE)
end,
pos)
end
@ -18,7 +23,7 @@ local function is_not_young(pos)
local meta = minetest.get_meta(pos)
local young = meta:get_string(NODE_YOUNG)
return young ~= "true"
return young ~= SETTING_TRUE
end
function nature:grow_node(pos, nodename)
@ -38,6 +43,6 @@ function nature:grow_node(pos, nodename)
end
function nature:is_near_water(pos)
return minetest.find_node_near(pos, DISTANCE_FROM_WATER,
{ "default:water_source" }) ~= nil or DISTANCE_FROM_WATER == -1
return DISTANCE_FROM_WATER == -1 or minetest.find_node_near(pos, DISTANCE_FROM_WATER,
{ "default:water_source" }) ~= nil
end