2021-12-26 22:45:37 +00:00
local wea = worldeditadditions
2022-05-19 01:43:19 +00:00
local wea_c = worldeditadditions_core
2022-09-19 17:30:43 +00:00
local Vector3 = wea_c.Vector3
2020-05-02 23:37:18 +00:00
2020-05-03 16:02:28 +00:00
local function parse_params_maze ( params_text , is_3d )
2021-12-26 22:45:37 +00:00
if not params_text then params_text = " " end
2022-09-18 19:58:28 +00:00
params_text = wea_c.trim ( params_text )
2021-12-26 22:45:37 +00:00
if # params_text == 0 then
2020-05-10 22:40:46 +00:00
return false , " No arguments specified "
2020-05-02 23:37:18 +00:00
end
2022-09-18 19:58:28 +00:00
local parts = wea_c.split_shell ( params_text )
2020-05-02 23:37:18 +00:00
2020-05-03 15:19:42 +00:00
local replace_node = parts [ 1 ]
2021-12-31 14:02:53 +00:00
local seed = os.time ( ) * math.random ( )
2020-05-03 15:19:42 +00:00
local path_length = 2
local path_width = 1
2020-05-03 16:02:28 +00:00
local path_depth = 1
local param_index_seed = 4
if is_3d then param_index_seed = 5 end
2020-05-02 23:37:18 +00:00
2020-05-03 15:19:42 +00:00
if # parts >= 2 then
path_length = tonumber ( parts [ 2 ] )
end
if # parts >= 3 then
path_width = tonumber ( parts [ 3 ] )
end
2020-05-03 16:02:28 +00:00
if # parts >= 4 and is_3d then
path_depth = tonumber ( parts [ 4 ] )
end
if # parts >= param_index_seed then
2022-09-18 19:58:28 +00:00
seed = wea_c.parse . seed ( parts [ param_index_seed ] )
2020-05-03 15:19:42 +00:00
end
2020-05-02 23:37:18 +00:00
replace_node = worldedit.normalize_nodename ( replace_node )
2020-05-10 20:00:16 +00:00
if not replace_node then
return false , " Error: Invalid node name for replace_node "
end
2020-05-10 21:18:26 +00:00
if not path_length or path_length < 1 then
return false , " Error: Invalid path length (it must be a positive integer) "
end
if not path_width or path_width < 1 then
return false , " Error: Invalid path width (it must be a positive integer) "
end
if not path_depth or path_depth < 1 then
return false , " Error: Invalid path depth (it must be a positive integer) "
end
2020-05-10 20:00:16 +00:00
2020-05-10 21:18:26 +00:00
-- We unconditionally math.floor here because when we tried to test for it directly it was unreliable
return true , replace_node , seed , math.floor ( path_length ) , math.floor ( path_width ) , math.floor ( path_depth )
2020-05-02 23:37:18 +00:00
end
2020-06-26 20:23:03 +00:00
-- ███ ███ █████ ███████ ███████
-- ████ ████ ██ ██ ███ ██
-- ██ ████ ██ ███████ ███ █████
-- ██ ██ ██ ██ ██ ███ ██
-- ██ ██ ██ ██ ███████ ███████
2024-10-22 13:46:23 +00:00
worldeditadditions_core.register_command ( " maze " , {
2020-05-03 15:19:42 +00:00
params = " <replace_node> [<path_length> [<path_width> [<seed>]]] " ,
description = " Generates a maze covering the currently selected area (must be at least 3x3 on the x,z axes) with replace_node as the walls. Optionally takes a (integer) seed and the path length and width (see the documentation in the worldeditadditions README for more information). " ,
2020-05-02 23:37:18 +00:00
privs = { worldedit = true } ,
2020-05-10 20:00:16 +00:00
require_pos = 2 ,
parse = function ( params_text )
local success , replace_node , seed , path_length , path_width = parse_params_maze ( params_text , false )
return success , replace_node , seed , path_length , path_width
end ,
nodes_needed = function ( name )
2024-10-14 19:50:31 +00:00
-- Note that we could take in additional parameters from the return value of parse (minus the success bool there), but we don't actually need them here
local pos1 , pos2 = wea_c.pos . get12 ( name )
return worldedit.volume ( pos1 , pos2 )
2020-05-10 20:00:16 +00:00
end ,
func = function ( name , replace_node , seed , path_length , path_width )
2022-09-18 19:58:28 +00:00
local start_time = wea_c.get_ms_time ( )
2021-12-26 22:48:37 +00:00
2024-10-14 19:50:31 +00:00
local pos1 , pos2 = wea_c.pos . get12 ( name )
2021-12-26 22:48:37 +00:00
local replaced = wea.maze2d (
pos1 , pos2 ,
replace_node ,
seed ,
path_length , path_width
)
2022-09-18 19:58:28 +00:00
local time_taken = wea_c.get_ms_time ( ) - start_time
2020-05-02 23:37:18 +00:00
2021-12-26 22:48:37 +00:00
minetest.log ( " action " , name .. " used //maze at " .. pos1 .. " - " .. pos2 .. " , replacing " .. replaced .. " nodes in " .. time_taken .. " s " )
2022-09-18 19:58:28 +00:00
return true , replaced .. " nodes replaced in " .. wea_c.format . human_time ( time_taken )
2020-05-10 20:00:16 +00:00
end
2020-05-02 23:37:18 +00:00
} )
-- ███ ███ █████ ███████ ███████ ██████ ██████
-- ████ ████ ██ ██ ███ ██ ██ ██ ██
-- ██ ████ ██ ███████ ███ █████ █████ ██ ██
-- ██ ██ ██ ██ ██ ███ ██ ██ ██ ██
-- ██ ██ ██ ██ ███████ ███████ ██████ ██████
2024-10-22 13:46:23 +00:00
worldeditadditions_core.register_command ( " maze3d " , {
2020-05-03 16:02:28 +00:00
params = " <replace_node> [<path_length> [<path_width> [<path_depth> [<seed>]]]] " ,
description = " Generates a 3d maze covering the currently selected area (must be at least 3x3x3) with replace_node as the walls. Optionally takes a (integer) seed and the path length, width, and depth (see the documentation in the worldeditadditions README for more information). " ,
2020-05-02 23:37:18 +00:00
privs = { worldedit = true } ,
2020-09-20 20:19:29 +00:00
require_pos = 2 ,
2020-05-10 20:21:00 +00:00
parse = function ( params_text )
local values = { parse_params_maze ( params_text , true ) }
2022-09-18 19:58:28 +00:00
return wea_c.table . unpack ( values )
2020-05-10 20:21:00 +00:00
end ,
nodes_needed = function ( name )
return worldedit.volume ( worldedit.pos1 [ name ] , worldedit.pos2 [ name ] )
end ,
func = function ( name , replace_node , seed , path_length , path_width , path_depth )
2022-09-18 19:58:28 +00:00
local start_time = wea_c.get_ms_time ( )
2024-10-14 19:58:50 +00:00
local pos1 , pos2 = Vector3.sort ( wea_c.pos . get12 ( name ) )
2022-09-19 17:30:43 +00:00
local replaced = wea.maze3d (
2022-09-18 19:58:28 +00:00
pos1 , pos2 ,
replace_node ,
seed ,
path_length , path_width , path_depth
)
local time_taken = wea_c.get_ms_time ( ) - start_time
2020-05-02 23:37:18 +00:00
2022-09-18 19:58:28 +00:00
minetest.log ( " action " , name .. " used //maze3d at " .. pos1 .. " - " .. pos2 .. " , replacing " .. replaced .. " nodes in " .. time_taken .. " s " )
return true , replaced .. " nodes replaced in " .. wea_c.format . human_time ( time_taken )
2020-05-10 20:21:00 +00:00
end
2020-05-02 23:37:18 +00:00
} )