2020-05-02 23:37:18 +00:00
local we_c = worldeditadditions_commands
-- ███ ███ █████ ███████ ███████
-- ████ ████ ██ ██ ███ ██
-- ██ ████ ██ ███████ ███ █████
-- ██ ██ ██ ██ ██ ███ ██
-- ██ ██ ██ ██ ███████ ███████
2020-05-03 16:02:28 +00:00
local function parse_params_maze ( params_text , is_3d )
2020-05-02 23:37:18 +00:00
if not params_text then
2020-05-03 15:19:42 +00:00
return nil , nil , nil , nil
2020-05-02 23:37:18 +00:00
end
2020-05-03 15:19:42 +00:00
local parts = we_c.split ( params_text , " %s+ " , false )
2020-05-02 23:37:18 +00:00
2020-05-03 15:19:42 +00:00
local replace_node = parts [ 1 ]
local seed = os.time ( )
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
seed = tonumber ( 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
return true , replace_node , seed , path_length , path_width , path_depth
2020-05-02 23:37:18 +00:00
end
2020-05-10 20:00:16 +00:00
worldedit.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 )
worldedit.player_notify ( name , " Called nodes_needed " )
local pos1 = worldedit.pos1 [ name ]
local pos2 = worldedit.pos2 [ name ]
pos1 , pos2 = worldedit.sort_pos ( pos1 , pos2 )
2020-05-02 23:37:18 +00:00
2020-05-10 20:00:16 +00:00
return ( pos2.x - pos1.x ) * ( pos2.y - pos1.y ) * ( pos1.z - pos2.z )
end ,
func = function ( name , replace_node , seed , path_length , path_width )
2020-05-02 23:37:18 +00:00
if not replace_node then
worldedit.player_notify ( name , " Error: Invalid node name. " )
return false
end
local start_time = os.clock ( )
2020-05-03 15:19:42 +00:00
local replaced = worldeditadditions.maze2d ( worldedit.pos1 [ name ] , worldedit.pos2 [ name ] , replace_node , seed , path_length , path_width )
2020-05-02 23:37:18 +00:00
local time_taken = os.clock ( ) - start_time
minetest.log ( " action " , name .. " used //maze at " .. worldeditadditions.vector . tostring ( worldedit.pos1 [ name ] ) .. " , replacing " .. replaced .. " nodes in " .. time_taken .. " s " )
2020-05-10 20:00:16 +00:00
return true , replaced .. " nodes replaced in " .. time_taken .. " s "
end
2020-05-02 23:37:18 +00:00
} )
-- ███ ███ █████ ███████ ███████ ██████ ██████
-- ████ ████ ██ ██ ███ ██ ██ ██ ██
-- ██ ████ ██ ███████ ███ █████ █████ ██ ██
-- ██ ██ ██ ██ ██ ███ ██ ██ ██ ██
-- ██ ██ ██ ██ ███████ ███████ ██████ ██████
minetest.register_chatcommand ( " /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 } ,
func = we_c.safe_region ( function ( name , params_text )
2020-05-03 16:10:41 +00:00
local replace_node , seed , path_length , path_width , path_depth = parse_params_maze ( params_text , true )
2020-05-02 23:37:18 +00:00
if not replace_node then
worldedit.player_notify ( name , " Error: Invalid node name. " )
return false
end
if not seed and has_seed then
worldedit.player_notify ( name , " Error: Invalid seed. " )
return false
end
if not seed then seed = os.time ( ) end
local start_time = os.clock ( )
2020-05-03 16:02:28 +00:00
local replaced = worldeditadditions.maze3d ( worldedit.pos1 [ name ] , worldedit.pos2 [ name ] , replace_node , seed , path_length , path_width , path_depth )
2020-05-02 23:37:18 +00:00
local time_taken = os.clock ( ) - start_time
worldedit.player_notify ( name , replaced .. " nodes replaced in " .. time_taken .. " s " )
minetest.log ( " action " , name .. " used //maze at " .. worldeditadditions.vector . tostring ( worldedit.pos1 [ name ] ) .. " , replacing " .. replaced .. " nodes in " .. time_taken .. " s " )
end , function ( name , params_text )
local replace_node , seed , has_seed = parse_params_maze ( params_text )
if not params_text then params_text = " " end
if not replace_node then
worldedit.player_notify ( name , " Error: Invalid input ' " .. params_text .. " ' (specifically the replace node). Try '/help /maze3d' to learn how to use this command. " )
return 0
end
if not seed and has_seed then
worldedit.player_notify ( name , " Error: Invalid input ' " .. params_text .. " ' (specifically the seed). Try '/help /maze3d' to learn how to use this command. " )
return 0
end
local pos1 = worldedit.pos1 [ name ]
local pos2 = worldedit.pos2 [ name ]
return ( pos2.x - pos1.x ) * ( pos2.y - pos1.y ) * ( pos1.z - pos2.z )
end )
} )