From ae26cfad421574d41a76c9a702c02f0627dfa712 Mon Sep 17 00:00:00 2001 From: trans_soup <> Date: Thu, 19 Oct 2023 16:09:09 +0200 Subject: [PATCH] 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). --- mods/bg_tree/decompose.lua | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/mods/bg_tree/decompose.lua b/mods/bg_tree/decompose.lua index cd5bcd2..66adf0c 100644 --- a/mods/bg_tree/decompose.lua +++ b/mods/bg_tree/decompose.lua @@ -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,