improve leaves decomposition.
leaves will now decompose faster depending on their surroundings. touching dirty nodes or other decomposing leaves will make them decay quicker.
This commit is contained in:
parent
cca53e76b3
commit
17636dbf87
|
@ -27,20 +27,57 @@ blockgame.register_increasing_abm({
|
|||
end,
|
||||
})
|
||||
|
||||
local decompose_node_scores = {
|
||||
[leaves_decomposing] = 30,
|
||||
}
|
||||
local decompose_group_scores = {
|
||||
dirty = 50,
|
||||
}
|
||||
|
||||
local decompose_cost = 2000
|
||||
|
||||
blockgame.register_increasing_abm({
|
||||
id = modname .. ":decompose",
|
||||
label = "decompose leaves",
|
||||
nodenames = {leaves_decomposing},
|
||||
neighbors = {"group:dirty"},
|
||||
interval = 20,
|
||||
chance = 8,
|
||||
neighbors = {"group:dirty", leaves_decomposing},
|
||||
interval = 30,
|
||||
chance = 10,
|
||||
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)
|
||||
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
|
||||
for group, value in pairs(decompose_group_scores) do
|
||||
if minetest.get_item_group(name, group) > 0 then
|
||||
gain = math.max(gain, value)
|
||||
end
|
||||
end
|
||||
|
||||
gain = math.floor(gain / distance)
|
||||
|
||||
if gain > 0 then
|
||||
score = score + gain
|
||||
return true
|
||||
end
|
||||
|
||||
if decompose_node_scores[name] then
|
||||
score = score + math.floor(decompose_node_scores[name] / distance)
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end, 4)
|
||||
|
||||
return data.value + score
|
||||
end,
|
||||
check = function (pos, node, data)
|
||||
return data.value >= 25
|
||||
return data.value >= decompose_cost
|
||||
end,
|
||||
action = function (pos, node, data)
|
||||
if blockgame.chance(2) then
|
||||
|
|
Loading…
Reference in New Issue