2018-05-20 10:52:16 +00:00
--- WorldEditAdditions-ChatCommands
-- @module worldeditadditions_commands
-- @release 0.1
-- @copyright 2018 Starbeamrainbowlabs
-- @license Mozilla Public License, 2.0
-- @author Starbeamrainbowlabs
2018-05-20 13:46:54 +00:00
local safe_region , check_region , reset_pending = dofile ( minetest.get_modpath ( " worldedit_commands " ) .. " /safe.lua " )
local function parse_params_floodfill ( params_text )
local found , _ , replace_node , radius = params_text : find ( " ([a-z:_ \\ -]+)%s+([0-9]+) " )
if found == nil then
found , _ , replace_node = params_text : find ( " ([a-z:_ \\ -]+) " )
radius = 25
end
if found == nil then
replace_node = " default:water_source "
end
radius = tonumber ( radius )
replace_node = worldedit.normalize_nodename ( replace_node )
return replace_node , radius
end
2018-05-20 10:52:16 +00:00
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
2018-05-20 13:46:54 +00:00
func = safe_region ( function ( name , params_text )
local replace_node , radius = parse_params_floodfill ( params_text )
2018-05-20 11:23:09 +00:00
2018-05-20 13:46:54 +00:00
if not replace_node then
worldedit.player_notify ( name , " Error: Invalid node name. " )
return false
2018-05-20 10:52:16 +00:00
end
2018-05-20 11:23:09 +00:00
2018-05-20 13:19:43 +00:00
local start_time = os.clock ( )
2018-05-20 10:52:16 +00:00
local nodes_replaced = worldedit.floodfill ( worldedit.pos1 [ name ] , radius , replace_node )
2018-05-20 13:46:54 +00:00
local time_taken = os.clock ( ) - start_time
2018-05-20 10:52:16 +00:00
2018-05-20 13:46:54 +00:00
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 )
return math.ceil ( ( ( 4 * math.pi * ( tonumber ( radius ) ^ 3 ) ) / 3 ) / 2 ) -- Volume of a hemisphere
end )
2018-05-20 10:52:16 +00:00
} )