mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-22 15:33:00 +00:00
[floodfill] Bugfix: Don't get caught in an infinite loop if the search & replace nodes are identical
Also fix a crash in the //floodfill command logic if pos1 is nil
This commit is contained in:
parent
7883161cb8
commit
bbde06c72e
2 changed files with 18 additions and 0 deletions
|
@ -62,6 +62,10 @@ function worldedit.floodfill(start_pos, radius, replace_node)
|
|||
local replace_id = minetest.get_content_id(replace_node)
|
||||
local radius_sq = radius*radius
|
||||
|
||||
if search_id == replace_id then
|
||||
return false
|
||||
end
|
||||
|
||||
local count = 0
|
||||
local remaining_nodes = Queue.new()
|
||||
Queue.enqueue(remaining_nodes, start_pos_index)
|
||||
|
|
|
@ -43,14 +43,28 @@ minetest.register_chatcommand("/floodfill", {
|
|||
return false
|
||||
end
|
||||
|
||||
if not worldedit.pos1[name] then
|
||||
worldedit.player_notify(name, "Error: No pos1 defined.")
|
||||
return false
|
||||
end
|
||||
|
||||
local start_time = os.clock()
|
||||
local nodes_replaced = worldedit.floodfill(worldedit.pos1[name], radius, replace_node)
|
||||
local time_taken = os.clock() - start_time
|
||||
|
||||
if nodes_replaced == false then
|
||||
worldedit.player_notify(name, "Error: The search node is the same as the replace node.")
|
||||
return false
|
||||
end
|
||||
|
||||
worldedit.player_notify(name, nodes_replaced .. " nodes replaced in " .. time_taken .. "s")
|
||||
minetest.log("action", name .. " used //floodfill at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. nodes_replaced .. " nodes in " .. time_taken .. "s")
|
||||
end, function(name, params_text)
|
||||
local replace_node, radius = parse_params_floodfill(params_text)
|
||||
|
||||
if not worldedit.pos1[name] then
|
||||
return 0 -- The actual command will send the error message to the client
|
||||
end
|
||||
-- Volume of a hemisphere
|
||||
return math.ceil(((4 * math.pi * (tonumber(radius) ^ 3)) / 3) / 2)
|
||||
end)
|
||||
|
|
Loading…
Reference in a new issue