nodecore-cd2025/mods/nc_tree/leafdecay.lua

66 lines
1.5 KiB
Lua
Raw Normal View History

2019-01-05 23:11:38 -05:00
-- LUALOCALS < ---------------------------------------------------------
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 = {}
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
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
return true
end
if n == modname .. ":leaves"
or n == modname .. ":leaves_bud" then
return
end
return false
end
)
end
nodecore.register_limited_abm({
label = "leaves decay",
interval = 2,
2020-06-17 00:54:21 -04:00
chance = 5,
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)
if not leafcheck(pos) then
return nodecore.leaf_decay(pos)
end
end
})
nodecore.register_limited_abm({
label = "growing leaves decay",
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
})