2020-08-21 21:59:50 +02:00
-- ███████ ██████ ██████ ██████ ███████
-- ██ ██ ██ ██ ██ ██ ██ ██
-- █████ ██████ ██ ██ ██ ██ █████
-- ██ ██ ██ ██ ██ ██ ██ ██
-- ███████ ██ ██ ██████ ██████ ███████
2020-08-21 14:27:40 +02:00
worldedit.register_command ( " erode " , {
2020-08-21 22:28:14 +02:00
params = " [<snowballs|...> [<key_1> [<value_1>]] [<key_2> [<value_2>]] ...] " ,
2020-08-21 22:26:29 +02:00
description = " **experimental** Runs the specified erosion algorithm over the given defined region. This may occur in 2d or 3d. Currently implemented algorithms: snowballs (default;2d hydraulic-like). Also optionally takes an arbitrary set of key - value pairs representing parameters to pass to the algorithm. See the full documentation for details. " ,
2020-08-21 14:27:40 +02:00
privs = { worldedit = true } ,
require_pos = 2 ,
parse = function ( params_text )
if not params_text or params_text == " " then
return true , " snowballs " , { }
end
if params_text : find ( " %s " ) == nil then
return true , params_text , { }
end
local algorithm , params = params_text : match ( " ([^%s]+)%s(.+) " )
if algorithm == nil then
return false , " Failed to split params_text into 2 parts (this is probably a bug) "
end
2021-03-20 02:48:56 +01:00
local success , map = worldeditadditions.parse . map ( params )
2020-08-21 14:27:40 +02:00
if not success then return success , map end
return true , algorithm , map
end ,
nodes_needed = function ( name )
return worldedit.volume ( worldedit.pos1 [ name ] , worldedit.pos2 [ name ] )
end ,
func = function ( name , algorithm , params )
local start_time = worldeditadditions.get_ms_time ( )
2020-08-21 23:01:24 +02:00
local success , msg , stats = worldeditadditions.erode . run (
2020-08-21 14:27:40 +02:00
worldedit.pos1 [ name ] , worldedit.pos2 [ name ] ,
algorithm , params
)
2020-08-21 23:01:24 +02:00
if not success then return success , msg end
2020-08-21 14:27:40 +02:00
local time_taken = worldeditadditions.get_ms_time ( ) - start_time
2020-08-21 16:21:10 +02:00
minetest.log ( " action " , name .. " used //erode " .. algorithm .. " at " .. worldeditadditions.vector . tostring ( worldedit.pos1 [ name ] ) .. " , adding " .. stats.added .. " nodes and removing " .. stats.removed .. " nodes in " .. time_taken .. " s " )
2021-03-20 02:48:56 +01:00
return true , msg .. " \n " .. stats.added .. " nodes added and " .. stats.removed .. " nodes removed in " .. worldeditadditions.format . human_time ( time_taken )
2020-08-21 14:27:40 +02:00
end
} )