From 8e515c377846c11c64c9e3b3bb954e18655eed8c Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Sun, 10 May 2020 21:00:16 +0100 Subject: [PATCH] Refactor //maze to use worldedit.register_command ....but I'm confused as to how the automatic safe_region thing works - I can't get it to trigger --- worldeditadditions_commands/commands/maze.lua | 44 +++++++++---------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/worldeditadditions_commands/commands/maze.lua b/worldeditadditions_commands/commands/maze.lua index e116ea6..c540cfa 100644 --- a/worldeditadditions_commands/commands/maze.lua +++ b/worldeditadditions_commands/commands/maze.lua @@ -38,16 +38,31 @@ local function parse_params_maze(params_text, is_3d) replace_node = worldedit.normalize_nodename(replace_node) - return replace_node, seed, path_length, path_width, path_depth + 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 end -minetest.register_chatcommand("/maze", { +worldedit.register_command("maze", { params = " [ [ []]]", 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).", privs = { worldedit = true }, - func = we_c.safe_region(function(name, params_text) - local replace_node, seed, path_length, path_width = parse_params_maze(params_text, false) + 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) + return (pos2.x - pos1.x) * (pos2.y - pos1.y) * (pos1.z - pos2.z) + end, + func = function(name, replace_node, seed, path_length, path_width) if not replace_node then worldedit.player_notify(name, "Error: Invalid node name.") return false @@ -57,26 +72,9 @@ minetest.register_chatcommand("/maze", { local replaced = worldeditadditions.maze2d(worldedit.pos1[name], worldedit.pos2[name], replace_node, seed, path_length, path_width) 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 /maze' 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 /maze' 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) + return true, replaced .. " nodes replaced in " .. time_taken .. "s" + end })