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:
parent
a3537b5dda
commit
ae26cfad42
|
@ -48,29 +48,11 @@ blockgame.register_increasing_abm({
|
||||||
rate = function (pos, node, data)
|
rate = function (pos, node, data)
|
||||||
local score = 20
|
local score = 20
|
||||||
|
|
||||||
local source_pos = pos
|
local bonus = blockgame.score_nearby_nodes(pos, 4, decompose_scores, function (gain, distance)
|
||||||
blockgame.flood_fill(pos, function (pos, distance)
|
return math.floor(gain / (distance ^ 3))
|
||||||
if pos == source_pos then return true end
|
end)
|
||||||
|
|
||||||
local name = minetest.get_node(pos).name
|
score = score + bonus
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
return data.value + score
|
return data.value + score
|
||||||
end,
|
end,
|
||||||
|
|
Loading…
Reference in New Issue