2023-10-16 18:41:09 +00:00
|
|
|
local modname = minetest.get_current_modname()
|
|
|
|
local api = blockgame.tree
|
|
|
|
local vec = blockgame.vector
|
|
|
|
|
|
|
|
-- NODE NAMES
|
|
|
|
|
|
|
|
local leaves = modname .. ":leaves"
|
|
|
|
local leaves_decomposing = modname .. ":leaves_decomposing"
|
|
|
|
|
|
|
|
-- END OF NODE NAMES
|
|
|
|
|
2023-10-16 19:30:57 +00:00
|
|
|
blockgame.register_increasing_abm({
|
2023-10-17 07:48:48 +00:00
|
|
|
id = modname .. ":begin_decompose",
|
2023-10-16 18:41:09 +00:00
|
|
|
label = "decompose leaves",
|
|
|
|
nodenames = {leaves},
|
|
|
|
neighbors = {"group:dirty"},
|
|
|
|
interval = 15,
|
|
|
|
chance = 4,
|
2023-10-16 19:30:57 +00:00
|
|
|
rate = function (pos, node, data)
|
|
|
|
return data.value + math.random(4, 6)
|
|
|
|
end,
|
|
|
|
check = function (pos, node, data)
|
|
|
|
return data.value >= 20
|
|
|
|
end,
|
|
|
|
action = function (pos, node, data)
|
2023-10-16 18:41:09 +00:00
|
|
|
minetest.set_node(pos, {name = leaves_decomposing})
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2023-10-16 19:30:57 +00:00
|
|
|
blockgame.register_increasing_abm({
|
2023-10-17 07:48:48 +00:00
|
|
|
id = modname .. ":decompose",
|
2023-10-16 18:41:09 +00:00
|
|
|
label = "decompose leaves",
|
|
|
|
nodenames = {leaves_decomposing},
|
|
|
|
neighbors = {"group:dirty"},
|
2023-10-16 19:48:53 +00:00
|
|
|
interval = 20,
|
|
|
|
chance = 8,
|
2023-10-16 19:30:57 +00:00
|
|
|
rate = function (pos, node, data)
|
|
|
|
-- TODO: decompose faster depending on surrounding dirty nodes & other decomposing leaves.
|
|
|
|
-- can probably do that with a flood fill that counts up a "score" depending on the nodes it encounters.
|
|
|
|
return data.value + math.random(1, 9)
|
|
|
|
end,
|
|
|
|
check = function (pos, node, data)
|
2023-10-16 19:48:53 +00:00
|
|
|
return data.value >= 25
|
2023-10-16 19:30:57 +00:00
|
|
|
end,
|
|
|
|
action = function (pos, node, data)
|
2023-10-16 18:41:09 +00:00
|
|
|
minetest.set_node(pos, {name = "bg_terrain:dirt"})
|
|
|
|
end,
|
|
|
|
})
|