diff --git a/mods/bg_api/util_node.lua b/mods/bg_api/util_node.lua index 431955c..a1b82b7 100644 --- a/mods/bg_api/util_node.lua +++ b/mods/bg_api/util_node.lua @@ -58,7 +58,9 @@ function blockgame.flood_fill (start, step, max_range) local matches = {} local rejected = {} - while #queue > 0 do + local cancel = false + + while #queue > 0 and not cancel do local current = table.remove(queue, 1) local pos = current.pos local range = current.range @@ -66,14 +68,18 @@ function blockgame.flood_fill (start, step, max_range) local hash = minetest.hash_node_position(pos) if not visited[hash] and range <= max_range and step(pos, range) then - table.insert(matches, pos) + local step_result = step(pos, range) - local neighbors = blockgame.vector.get_neighbors(pos) - for _, p in pairs(neighbors) do - table.insert(queue, { pos = p, range = range + 1 }) - end - else - table.insert(rejected, pos) + if step_result then + table.insert(matches, pos) + + local neighbors = blockgame.vector.get_neighbors(pos) + for _, p in pairs(neighbors) do + table.insert(queue, { pos = p, range = range + 1 }) + end + elseif step_result == nil then + table.insert(rejected, pos) + else cancel = true end end visited[hash] = true diff --git a/mods/bg_tree/decompose.lua b/mods/bg_tree/decompose.lua index da193f0..dbf78a5 100644 --- a/mods/bg_tree/decompose.lua +++ b/mods/bg_tree/decompose.lua @@ -70,8 +70,6 @@ blockgame.register_increasing_abm({ score = score + math.floor(decompose_node_scores[name] / distance) return true end - - return false end, 4) return data.value + score