mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-22 15:33:00 +00:00
Add safe_region support
This commit is contained in:
parent
85cfd93d5e
commit
a9d8dab77c
1 changed files with 32 additions and 14 deletions
|
@ -5,12 +5,9 @@
|
||||||
-- @license Mozilla Public License, 2.0
|
-- @license Mozilla Public License, 2.0
|
||||||
-- @author Starbeamrainbowlabs
|
-- @author Starbeamrainbowlabs
|
||||||
|
|
||||||
minetest.register_chatcommand("/floodfill", {
|
local safe_region, check_region, reset_pending = dofile(minetest.get_modpath("worldedit_commands") .. "/safe.lua")
|
||||||
params = "<replace_node> [<radius>]",
|
|
||||||
description = "Floods all connected nodes of the same type starting at pos1 with <replace_node>, in a box-shape with a radius of <radius>, which defaults to 50.",
|
local function parse_params_floodfill(params_text)
|
||||||
privs = { worldedit = true },
|
|
||||||
-- TODO: Integrate will the safe_region feature of regular worldedit
|
|
||||||
func = function(name, params_text)
|
|
||||||
local found, _, replace_node, radius = params_text:find("([a-z:_\\-]+)%s+([0-9]+)")
|
local found, _, replace_node, radius = params_text:find("([a-z:_\\-]+)%s+([0-9]+)")
|
||||||
|
|
||||||
if found == nil then
|
if found == nil then
|
||||||
|
@ -24,10 +21,31 @@ minetest.register_chatcommand("/floodfill", {
|
||||||
|
|
||||||
replace_node = worldedit.normalize_nodename(replace_node)
|
replace_node = worldedit.normalize_nodename(replace_node)
|
||||||
|
|
||||||
|
return replace_node, radius
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_chatcommand("/floodfill", {
|
||||||
|
params = "<replace_node> [<radius>]",
|
||||||
|
description = "Floods all connected nodes of the same type starting at pos1 with <replace_node>, in a box-shape with a radius of <radius>, which defaults to 50.",
|
||||||
|
privs = { worldedit = true },
|
||||||
|
-- TODO: Integrate will the safe_region feature of regular worldedit
|
||||||
|
func = safe_region(function(name, params_text)
|
||||||
|
local replace_node, radius = parse_params_floodfill(params_text)
|
||||||
|
|
||||||
|
if not replace_node then
|
||||||
|
worldedit.player_notify(name, "Error: Invalid node name.")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
local start_time = os.clock()
|
local start_time = os.clock()
|
||||||
local nodes_replaced = worldedit.floodfill(worldedit.pos1[name], radius, replace_node)
|
local nodes_replaced = worldedit.floodfill(worldedit.pos1[name], radius, replace_node)
|
||||||
|
local time_taken = os.clock() - start_time
|
||||||
|
|
||||||
worldedit.player_notify(name, nodes_replaced .. " nodes replaced in " .. (os.clock() - start_time) .. "s")
|
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 " .. (os.clock() - start_time) .. "s")
|
minetest.log("action", name .. " used floodfill at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. nodes_replaced .. " nodes in " .. time_taken .. "s")
|
||||||
end
|
end, function(name, params_text)
|
||||||
|
local replace_node, radius = parse_params_floodfill(params_text)
|
||||||
|
|
||||||
|
return math.ceil(((4 * math.pi * (tonumber(radius) ^ 3)) / 3) / 2) -- Volume of a hemisphere
|
||||||
|
end)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue