2019-01-05 23:11:38 -05:00
|
|
|
-- LUALOCALS < ---------------------------------------------------------
|
2019-01-06 12:02:37 -05:00
|
|
|
local minetest, nodecore
|
|
|
|
= minetest, nodecore
|
2019-01-05 23:11:38 -05:00
|
|
|
-- LUALOCALS > ---------------------------------------------------------
|
|
|
|
|
|
|
|
local modname = minetest.get_current_modname()
|
|
|
|
|
2020-06-17 00:54:21 -04:00
|
|
|
local cache = {}
|
|
|
|
|
2020-01-16 21:43:07 -05:00
|
|
|
local function leafcheck(pos)
|
2020-06-17 00:54:21 -04:00
|
|
|
local hash = minetest.hash_node_position(pos)
|
|
|
|
local found = cache[hash]
|
|
|
|
if found and minetest.get_node(found).name == found.name then return true end
|
2020-01-16 21:43:07 -05:00
|
|
|
return nodecore.scan_flood(pos, 5, function(p)
|
|
|
|
local n = minetest.get_node(p).name
|
|
|
|
if n == modname .. ":tree"
|
|
|
|
or n == modname .. ":tree_bud"
|
|
|
|
or n == "ignore" then
|
2020-06-17 00:54:21 -04:00
|
|
|
while p.prev do
|
|
|
|
p.name = minetest.get_node(p).name
|
|
|
|
cache[minetest.hash_node_position(p.prev)] = p
|
|
|
|
p = p.prev
|
|
|
|
end
|
2020-01-16 21:43:07 -05:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
if n == modname .. ":leaves"
|
|
|
|
or n == modname .. ":leaves_bud" then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2019-01-06 12:02:37 -05:00
|
|
|
nodecore.register_limited_abm({
|
2020-06-17 07:09:20 -04:00
|
|
|
label = "leaves decay",
|
2020-06-16 21:56:23 -04:00
|
|
|
interval = 2,
|
2020-06-17 00:54:21 -04:00
|
|
|
chance = 5,
|
2019-01-08 02:03:18 -05:00
|
|
|
limited_max = 100,
|
2019-01-12 20:53:02 -05:00
|
|
|
limited_alert = 1000,
|
2019-01-05 23:11:38 -05:00
|
|
|
nodenames = {modname .. ":leaves"},
|
|
|
|
action = function(pos)
|
2020-01-16 21:43:07 -05:00
|
|
|
if not leafcheck(pos) then
|
|
|
|
return nodecore.leaf_decay(pos)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
nodecore.register_limited_abm({
|
2020-06-17 07:09:20 -04:00
|
|
|
label = "growing leaves decay",
|
2020-01-16 21:43:07 -05:00
|
|
|
interval = 1,
|
|
|
|
chance = 10,
|
|
|
|
limited_max = 100,
|
|
|
|
limited_alert = 1000,
|
|
|
|
nodenames = {modname .. ":leaves_bud"},
|
|
|
|
action = function(pos, node)
|
|
|
|
if not leafcheck(pos) then
|
|
|
|
return nodecore.leaf_decay(pos, {
|
|
|
|
name = modname .. ":leaves",
|
|
|
|
param = node.param,
|
|
|
|
param2 = 0
|
|
|
|
})
|
2019-01-05 23:11:38 -05:00
|
|
|
end
|
|
|
|
end
|
2019-01-06 12:02:37 -05:00
|
|
|
})
|