refactor: make decomposition use new API function.

make leaves decomposition use the `blockgame.score_nearby_nodes` API
function (which was created largely from previous decomposition code).
This commit is contained in:
trans_soup 2023-10-19 16:09:09 +02:00
parent a3537b5dda
commit ae26cfad42

View file

@ -48,29 +48,11 @@ blockgame.register_increasing_abm({
rate = function (pos, node, data)
local score = 20
local source_pos = pos
blockgame.flood_fill(pos, function (pos, distance)
if pos == source_pos then return true end
local bonus = blockgame.score_nearby_nodes(pos, 4, decompose_scores, function (gain, distance)
return math.floor(gain / (distance ^ 3))
end)
local name = minetest.get_node(pos).name
local gain = 0
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)
end
end
gain = math.floor(gain / (distance ^ 3))
if gain > 0 then
score = score + gain
return true
end
return false
end, 4)
score = score + bonus
return data.value + score
end,