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},
|
2023-10-17 08:15:13 +00:00
|
|
|
neighbors = {"group:dirty", leaves_decomposing},
|
2023-10-16 18:41:09 +00:00
|
|
|
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-19 11:10:49 +00:00
|
|
|
local decompose_scores = {
|
2023-10-17 11:41:30 +00:00
|
|
|
dirty = 50,
|
2023-10-19 11:10:49 +00:00
|
|
|
leaves_decomposing = 30,
|
2023-10-17 11:41:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
local decompose_cost = 2000
|
|
|
|
|
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",
|
2023-10-19 10:54:09 +00:00
|
|
|
nodenames = {"group:leaves_decomposing"},
|
2023-10-19 11:11:41 +00:00
|
|
|
-- neighbors = {"group:dirty", "group:leaves_decomposing"},
|
2023-10-17 11:41:30 +00:00
|
|
|
interval = 30,
|
|
|
|
chance = 10,
|
2023-10-16 19:30:57 +00:00
|
|
|
rate = function (pos, node, data)
|
2023-10-17 11:41:30 +00:00
|
|
|
local score = 100
|
|
|
|
|
|
|
|
local source_pos = pos
|
|
|
|
blockgame.flood_fill(pos, function (pos, distance)
|
|
|
|
if pos == source_pos then return true end
|
|
|
|
|
|
|
|
local name = minetest.get_node(pos).name
|
|
|
|
|
|
|
|
local gain = 0
|
2023-10-19 11:10:49 +00:00
|
|
|
for group, value in pairs(decompose_scores) do
|
|
|
|
local group = minetest.get_item_group(name, group)
|
|
|
|
if group > 0 then
|
|
|
|
gain = math.max(gain, value * group)
|
2023-10-17 11:41:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
gain = math.floor(gain / distance)
|
|
|
|
|
|
|
|
if gain > 0 then
|
|
|
|
score = score + gain
|
|
|
|
return true
|
|
|
|
end
|
2023-10-19 11:12:10 +00:00
|
|
|
|
|
|
|
return false
|
2023-10-17 11:41:30 +00:00
|
|
|
end, 4)
|
|
|
|
|
|
|
|
return data.value + score
|
2023-10-16 19:30:57 +00:00
|
|
|
end,
|
|
|
|
check = function (pos, node, data)
|
2023-10-17 11:41:30 +00:00
|
|
|
return data.value >= decompose_cost
|
2023-10-16 19:30:57 +00:00
|
|
|
end,
|
|
|
|
action = function (pos, node, data)
|
2023-10-19 10:58:31 +00:00
|
|
|
-- currently, larger leaf piles have a greater chance of turning into dirt instead of disappearing.
|
|
|
|
-- might wanna make it so that instead, dirt is layered as well?
|
|
|
|
local def = minetest.registered_nodes[node.name]
|
|
|
|
local dirt_chance = def.level_max - def.level + 1
|
|
|
|
|
|
|
|
if blockgame.chance(dirt_chance) then
|
2023-10-17 08:27:41 +00:00
|
|
|
minetest.set_node(pos, {name = "bg_terrain:dirt"})
|
|
|
|
else
|
|
|
|
minetest.remove_node(pos)
|
|
|
|
end
|
2023-10-16 18:41:09 +00:00
|
|
|
end,
|
|
|
|
})
|