From 0d7922d7470443a75d4153cc98185ee0f2dc94d1 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Mon, 16 May 2022 00:29:50 +0100 Subject: [PATCH 01/25] typo --- worldeditadditions_commands/commands/dome.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worldeditadditions_commands/commands/dome.lua b/worldeditadditions_commands/commands/dome.lua index 031312c..499a6e3 100644 --- a/worldeditadditions_commands/commands/dome.lua +++ b/worldeditadditions_commands/commands/dome.lua @@ -46,7 +46,7 @@ worldedit.register_command("dome+", { -- TODO: Make this an override return false, "Error: Invalid radius '"..parts[1].."'. The radius must be a positive integer." end if radius < 1 then - return false, "Error: The minimum radius size is 1, but you entered"..tostring(radius).."." + return false, "Error: The minimum radius size is 1, but you entered "..tostring(radius).."." end if not replace_node then From 3311d80a2a38ce0c1d8ffaf183f1d79946032247 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Mon, 16 May 2022 01:01:01 +0100 Subject: [PATCH 02/25] Rework metaballs backend We need a way of defining metaballs per-player. Our solution to this is a custom in-memory per-player storage system. The reason for this is because just a position (e.g. that provided by pos1/pos2) is not enough - we need a radius as well. --- worldeditadditions/init.lua | 4 +- worldeditadditions/lib/metaballs/init.lua | 15 +++ .../lib/metaballs/playerdata.lua | 104 ++++++++++++++++++ .../{metaballs.lua => metaballs/render.lua} | 5 +- .../commands/metaballs.lua | 71 ++++++++++++ 5 files changed, 196 insertions(+), 3 deletions(-) create mode 100644 worldeditadditions/lib/metaballs/init.lua create mode 100644 worldeditadditions/lib/metaballs/playerdata.lua rename worldeditadditions/lib/{metaballs.lua => metaballs/render.lua} (97%) create mode 100644 worldeditadditions_commands/commands/metaballs.lua diff --git a/worldeditadditions/init.lua b/worldeditadditions/init.lua index 609ffd4..2e12168 100644 --- a/worldeditadditions/init.lua +++ b/worldeditadditions/init.lua @@ -59,11 +59,11 @@ dofile(wea.modpath.."/lib/scale.lua") dofile(wea.modpath.."/lib/spiral_square.lua") dofile(wea.modpath.."/lib/spiral_circle.lua") dofile(wea.modpath.."/lib/dome.lua") -dofile(wea.modpath.."/lib/metaballs.lua") dofile(wea.modpath.."/lib/conv/conv.lua") dofile(wea.modpath.."/lib/erode/erode.lua") dofile(wea.modpath.."/lib/noise/init.lua") -wea.sculpt = dofile(wea.modpath.."/lib/sculpt/init.lua") +wea.sculpt = dofile(wea.modpath.."/lib/sculpt/init.lua") +wea.metaballs = dofile(wea.modpath.."/lib/metaballs.lua") dofile(wea.modpath.."/lib/copy.lua") dofile(wea.modpath.."/lib/move.lua") diff --git a/worldeditadditions/lib/metaballs/init.lua b/worldeditadditions/lib/metaballs/init.lua new file mode 100644 index 0000000..729737c --- /dev/null +++ b/worldeditadditions/lib/metaballs/init.lua @@ -0,0 +1,15 @@ +local wea = worldeditadditions +local wea_m = wea.modpath .. "/lib/metaballs/" + +local playerdata = dofile(wea_m.."playerdata.lua") + +local metaballs_ns = { + render = dofile(wea_m.."render.lua"), + add = playerdata.add, + remove = playerdata.remove, + list = playerdata.list, + list_pretty = playerdata.list_pretty, + clear = playerdata.clear +} + +return metaballs_ns diff --git a/worldeditadditions/lib/metaballs/playerdata.lua b/worldeditadditions/lib/metaballs/playerdata.lua new file mode 100644 index 0000000..8367573 --- /dev/null +++ b/worldeditadditions/lib/metaballs/playerdata.lua @@ -0,0 +1,104 @@ +local wea = worldeditadditions +local Vector3 = wea.Vector3 + +local metaballdata = {} + +--- Adds a new metaball for a given player at the specified position with a specified radius. +-- @param player_name string The name of the player. +-- @param pos Vector3 The position of the metaball. +-- @param radius number The radius of the metaball. +-- @returns bool,number The number of metaballs now defined for the given player. +local function add(player_name, pos, radius) + local pos = Vector3.clone(pos) + + if type(player_name) ~= "string" then + return false, "Error: Invalid player name specified." + end + if type(radius) ~= "number" then + return false, "Error: Expected the radius to be of type number, but got value of type "..type(radius).." instead." + end + if radius < 1 then + return false, "The minimum radius of a metaball is 1, but got a radius of "..tostring(radius).."." + end + + if not metaballdata[player_name] then + metaballdata[player_name] = {} + end + + -- TODO: Limit the number of metaballs that can be defined? + table.insert(metaballdata[player_name], { + pos = pos, + radius = radius + }) + + return true, #metaballdata[player_name] +end + +--- Returns a list of all metaballs defined for the given player. +-- @param player_name string The name of the player. +-- @returns bool,[{ pos: Vector3, radius: number }, ...] A list of metaballs for the given player. +local function list(player_name) + if type(player_name) ~= "string" then + return false, "Error: Invalid player name specified." + end + + if not metaballdata[player_name] then return {} end + + return true, metaballdata[player_name] +end + +--- Returns a pretty-printed list of metaballs for the given player. +-- @param player_name string The name of the player. +-- @returns bool,string A pretty-printed list of metaballs for the given player. +local function list_pretty(player_name) + local success, metaball_list = list(player_name) + if not success then return success, metaball_list end + + local rows = { { "Index", "Position", "Radius" } } + for i,metaball in ipairs(metaball_list) do + table.insert(rows, { + i, + metaball.pos, + metaball.radius + }) + end + + return true, wea.format.make_ascii_table(rows).."\n---------------------------\nTotal "..tostring(#metaball_list).." metaballs" +end + +--- Removes the metaball with the specified index for a given player. +-- @param player_name string The name of the player. +-- @param index number The index of the metaball to remove. +-- @returns bool,number The number of metaballs now defined for the given player. +local function remove(player_name, index) + local success, metaball_list = list(player_name) + if not success then return success, metaball_list end + + if #metaball_list > index then + return false, "Error: Requested the removal of metaball "..tostring(index)..", but there are "..tostring(#metaball_list).." metaballs defined." + end + + table.remove(metaball_list, index) + + return #metaball_list +end + +--- Removes all the currently defined metaballs for the given player. +-- @param player_name string The name of the player. +-- @returns bool,number The number of metaballs that WERE defined for the given player. +local function clear(player_name) + local success, metaball_list = list(player_name) + if not success then return success, metaball_list end + + metaballdata[player_name] = {} + + return #metaball_list +end + +return { + add = add, + list = list, + list_pretty = list_pretty, + remove = remove, + clear = clear +} diff --git a/worldeditadditions/lib/metaballs.lua b/worldeditadditions/lib/metaballs/render.lua similarity index 97% rename from worldeditadditions/lib/metaballs.lua rename to worldeditadditions/lib/metaballs/render.lua index d205b98..4ef11d4 100644 --- a/worldeditadditions/lib/metaballs.lua +++ b/worldeditadditions/lib/metaballs/render.lua @@ -10,7 +10,7 @@ local Vector3 = wea.Vector3 -- direction the point should point. -- @param metaballs [{pos: Vector3, radius: number}] Aa list of metaballs to render. Each metaball should be a table with 2 properties: pos - the position of the centre of the metaball as a Vector3, and radius - the radius of the metaball. -- @param replace_node string The fully qualified name of the node to use to make the dome with. -function worldeditadditions.metaballs(metaballs, replace_node, threshold) +local function render(metaballs, replace_node, threshold) local pos1, pos2 if not threshold then threshold = 1 end @@ -61,3 +61,6 @@ function worldeditadditions.metaballs(metaballs, replace_node, threshold) return true, replaced end + + +return render diff --git a/worldeditadditions_commands/commands/metaballs.lua b/worldeditadditions_commands/commands/metaballs.lua new file mode 100644 index 0000000..bc9879d --- /dev/null +++ b/worldeditadditions_commands/commands/metaballs.lua @@ -0,0 +1,71 @@ +local wea = worldeditadditions +local Vector3 = wea.Vector3 + +-- ██████ ██████ ███ ███ ███████ +-- ██ ██ ██ ██ ████ ████ ██ +-- ██ ██ ██ ██ ██ ████ ██ █████ +-- ██ ██ ██ ██ ██ ██ ██ ██ +-- ██████ ██████ ██ ██ ███████ +worldedit.register_command("metaballs", { + params = "add | remove | list | render | clear", + description = "Defines and creates metaballs. After using the add subcommand to define 1 or more metaballs (uses pos1), the render subcommand can then be used to create the metaballs as nodes.", + privs = { worldedit = true }, + require_pos = 1, + parse = function(params_text) + if not params_text then params_text = "" end + + local parts = wea.split_shell(params_text) + + if #parts < 1 then + return false, "Error: Not enough arguments (see /help /dome for usage information)." + end + local subcommand = parts[1] + local subargs = {} + if subcommand == "add" then + local radius = tonumber(parts[2]) + if not radius then + return false, "Error: Invalid radius '"..parts[1].."'. The radius must be a positive integer." + end + if radius < 1 then + return false, "Error: The minimum radius size is 1, but you entered "..tostring(radius).."." + end + table.insert(subargs, radius) + elseif subcommand == "remove" then + local index = tonumber(parts[2]) + if not index then + return false, "Error: Invalid index '"..parts[1].."'. The index to remove must be a positive integer." + end + if index < 1 then + return false, "Error: The minimum index size is 1, but you entered "..tostring(index).."." + end + table.insert(subargs, index) + elseif subcommand == "render" then + local replace_node = worldedit.normalize_nodename(parts[2]) + if not replace_node then + return false, "Error: Invalid replace_node '"..parts[2].."'." + end + table.insert(subargs, replace_node) + end + + return true, subcommand, subargs + end, + nodes_needed = function(name, subcommand) + if subcommand == "render" then + return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name]) + else + return 0 + end + end, + func = function(name, radius, replace_node, axes, hollow) + local start_time = wea.get_ms_time() + + + + + local time_taken = wea.get_ms_time() - start_time + + + minetest.log("action", name.." used //dome+ at "..pos.." with a radius of "..tostring(radius)..", modifying "..nodes_replaced.." nodes in "..wea.format.human_time(time_taken)) + return true, nodes_replaced.." nodes replaced "..wea.format.human_time(time_taken) + end +}) From 722e62bae04df764bd7b4212c598f81988efbcbc Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Mon, 16 May 2022 01:21:09 +0100 Subject: [PATCH 03/25] Finish initial //metaballs command implementation, but it's untested --- worldeditadditions/init.lua | 2 +- .../commands/metaballs.lua | 81 +++++++++++++++++-- 2 files changed, 75 insertions(+), 8 deletions(-) diff --git a/worldeditadditions/init.lua b/worldeditadditions/init.lua index 2e12168..7b04b3c 100644 --- a/worldeditadditions/init.lua +++ b/worldeditadditions/init.lua @@ -63,7 +63,7 @@ dofile(wea.modpath.."/lib/conv/conv.lua") dofile(wea.modpath.."/lib/erode/erode.lua") dofile(wea.modpath.."/lib/noise/init.lua") wea.sculpt = dofile(wea.modpath.."/lib/sculpt/init.lua") -wea.metaballs = dofile(wea.modpath.."/lib/metaballs.lua") +wea.metaballs = dofile(wea.modpath.."/lib/metaballs/init.lua") dofile(wea.modpath.."/lib/copy.lua") dofile(wea.modpath.."/lib/move.lua") diff --git a/worldeditadditions_commands/commands/metaballs.lua b/worldeditadditions_commands/commands/metaballs.lua index bc9879d..311045a 100644 --- a/worldeditadditions_commands/commands/metaballs.lua +++ b/worldeditadditions_commands/commands/metaballs.lua @@ -7,7 +7,7 @@ local Vector3 = wea.Vector3 -- ██ ██ ██ ██ ██ ██ ██ ██ -- ██████ ██████ ██ ██ ███████ worldedit.register_command("metaballs", { - params = "add | remove | list | render | clear", + params = "add | remove | list | render [] | clear", description = "Defines and creates metaballs. After using the add subcommand to define 1 or more metaballs (uses pos1), the render subcommand can then be used to create the metaballs as nodes.", privs = { worldedit = true }, require_pos = 1, @@ -19,8 +19,18 @@ worldedit.register_command("metaballs", { if #parts < 1 then return false, "Error: Not enough arguments (see /help /dome for usage information)." end + local subcommand = parts[1] local subargs = {} + + if subcommand == "delete" then subcommand = "remove" end + if subcommand == "deleteall" then subcommand = "clear" end + if subcommand == "append" then subcommand = "add" end + if subcommand == "list" then subcommand = "list" end + if subcommand == "make" then subcommand = "render" end + if subcommand == "generate" then subcommand = "render" end + if subcommand == "create" then subcommand = "render" end + if subcommand == "add" then local radius = tonumber(parts[2]) if not radius then @@ -41,10 +51,22 @@ worldedit.register_command("metaballs", { table.insert(subargs, index) elseif subcommand == "render" then local replace_node = worldedit.normalize_nodename(parts[2]) + local threshold = 1 + if not replace_node then return false, "Error: Invalid replace_node '"..parts[2].."'." end + + if #parts >= 3 then + threshold = tonumber(parts[3]) + if not threshold then + return false, "Error: The threshold value must be a valid number (a floating-point number is ok)." + end + end table.insert(subargs, replace_node) + table.insert(subargs, threshold) + elseif subcommand ~= "list" and subcommand ~= "clear" then + return false, "Error: Unknown subcommand '"..parts[1].."'." end return true, subcommand, subargs @@ -56,16 +78,61 @@ worldedit.register_command("metaballs", { return 0 end end, - func = function(name, radius, replace_node, axes, hollow) + func = function(name, subcommand, subargs) local start_time = wea.get_ms_time() - - - + local message = "" + local append_time = true + if subcommand == "list" then + local success, list = wea.metaballs.list_pretty(name) + if not success then return success, list end + + message = list + append_time = false + elseif subcommand == "clear" then + local success, metaballs_cleared = wea.metaballs.clear(name) + if not success then return success, metaballs_cleared end + + message = tostring(metaballs_cleared).." cleared" + elseif subcommand == "remove" then + local index = subargs[1] + + local success, metaballs_count = wea.metaballs.remove(name, index) + if not success then return success, metaballs_count end + + message = "metaball at index "..tostring(index).." removed - "..metaballs_count.." metaballs remain" + elseif subcommand == "add" then + local pos = Vector3.clone(worldedit.pos1[name]) + local radius = subargs[1] + + local success, metaballs_count = wea.metaballs.add(name, pos, radius) + if not success then return success, metaballs_count end + + message = "added metaball at "..pos.." with radius "..tostring(radius).." - "..metaballs_count.." metaballs are now defined" + elseif subcommand == "render" then + local replace_node = subargs[1] + local threshold = subargs[2] + + local success, metaballs = wea.metaballs.list(name) + if not success then return success, metaballs end + + if #metaballs < 2 then + return false, "Error: At least 2 metaballs must be defined to render them." + end + + local success2, nodes_replaced = wea.metaballs.render(metaballs, replace_node, threshold) + if not success2 then return success2, nodes_replaced end + + message = nodes_replaced.." nodes replaced using "..tostring(#metaballs).." metaballs" + end local time_taken = wea.get_ms_time() - start_time - minetest.log("action", name.." used //dome+ at "..pos.." with a radius of "..tostring(radius)..", modifying "..nodes_replaced.." nodes in "..wea.format.human_time(time_taken)) - return true, nodes_replaced.." nodes replaced "..wea.format.human_time(time_taken) + if append_time then + message = message.." in "..wea.format.human_time(time_taken) + end + + minetest.log("action", name.." used //metaballs "..subcommand.." in "..wea.format.human_time(time_taken)) + return true, message end }) From 98909f0fae171e792abc6470f2da8be6b5f5efa6 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Mon, 16 May 2022 20:14:31 +0100 Subject: [PATCH 04/25] //metaball: bugfix It works! --- worldeditadditions/lib/metaballs/init.lua | 3 +- .../lib/metaballs/playerdata.lua | 25 ++++++++++++-- worldeditadditions/lib/metaballs/render.lua | 2 +- .../commands/{metaballs.lua => metaball.lua} | 33 ++++++++++++++----- worldeditadditions_commands/init.lua | 2 +- 5 files changed, 52 insertions(+), 13 deletions(-) rename worldeditadditions_commands/commands/{metaballs.lua => metaball.lua} (82%) diff --git a/worldeditadditions/lib/metaballs/init.lua b/worldeditadditions/lib/metaballs/init.lua index 729737c..78f3f09 100644 --- a/worldeditadditions/lib/metaballs/init.lua +++ b/worldeditadditions/lib/metaballs/init.lua @@ -9,7 +9,8 @@ local metaballs_ns = { remove = playerdata.remove, list = playerdata.list, list_pretty = playerdata.list_pretty, - clear = playerdata.clear + clear = playerdata.clear, + volume = playerdata.volume } return metaballs_ns diff --git a/worldeditadditions/lib/metaballs/playerdata.lua b/worldeditadditions/lib/metaballs/playerdata.lua index 8367573..4edf96f 100644 --- a/worldeditadditions/lib/metaballs/playerdata.lua +++ b/worldeditadditions/lib/metaballs/playerdata.lua @@ -74,7 +74,7 @@ local function remove(player_name, index) local success, metaball_list = list(player_name) if not success then return success, metaball_list end - if #metaball_list > index then + if index > #metaball_list then return false, "Error: Requested the removal of metaball "..tostring(index)..", but there are "..tostring(#metaball_list).." metaballs defined." end @@ -95,10 +95,31 @@ local function clear(player_name) return #metaball_list end +--- Calculates the total volume that the currently defined metaballs are expected to take up. +-- @param player_name string The name of the player. +-- @returns bool,number The total volume that the currently defined metaballs are expected to take up. +local function volume(player_name) + local success, metaball_list = list(player_name) + if not success then return success, metaball_list end + + if #metaball_list == 0 then return 0 end + + local pos1 = metaball_list[1].pos + local pos2 = pos1 + + for i,metaball in ipairs(metaball_list) do + pos1 = Vector3.min(pos1, metaball.pos - metaball.radius) + pos2 = Vector3.max(pos2, metaball.pos + metaball.radius) + end + + return (pos2 - pos1):area() +end + return { add = add, list = list, list_pretty = list_pretty, remove = remove, - clear = clear + clear = clear, + volume = volume } diff --git a/worldeditadditions/lib/metaballs/render.lua b/worldeditadditions/lib/metaballs/render.lua index 4ef11d4..660c3e6 100644 --- a/worldeditadditions/lib/metaballs/render.lua +++ b/worldeditadditions/lib/metaballs/render.lua @@ -48,7 +48,7 @@ local function render(metaballs, replace_node, threshold) metaball_sum = metaball_sum + falloff end - if metaball_sum <= threshold then + if metaball_sum >= threshold then data[area:index(x, y, z)] = node_id_replace replaced = replaced + 1 end diff --git a/worldeditadditions_commands/commands/metaballs.lua b/worldeditadditions_commands/commands/metaball.lua similarity index 82% rename from worldeditadditions_commands/commands/metaballs.lua rename to worldeditadditions_commands/commands/metaball.lua index 311045a..6e00d04 100644 --- a/worldeditadditions_commands/commands/metaballs.lua +++ b/worldeditadditions_commands/commands/metaball.lua @@ -6,8 +6,8 @@ local Vector3 = wea.Vector3 -- ██ ██ ██ ██ ██ ████ ██ █████ -- ██ ██ ██ ██ ██ ██ ██ ██ -- ██████ ██████ ██ ██ ███████ -worldedit.register_command("metaballs", { - params = "add | remove | list | render [] | clear", +worldedit.register_command("metaball", { + params = "add | remove | render [] | list | clear | volume", description = "Defines and creates metaballs. After using the add subcommand to define 1 or more metaballs (uses pos1), the render subcommand can then be used to create the metaballs as nodes.", privs = { worldedit = true }, require_pos = 1, @@ -32,24 +32,33 @@ worldedit.register_command("metaballs", { if subcommand == "create" then subcommand = "render" end if subcommand == "add" then + if #parts < 2 then + return false, "Error: Not enough arguments." + end local radius = tonumber(parts[2]) if not radius then - return false, "Error: Invalid radius '"..parts[1].."'. The radius must be a positive integer." + return false, "Error: Invalid radius '"..parts[2].."'. The radius must be a positive integer." end if radius < 1 then return false, "Error: The minimum radius size is 1, but you entered "..tostring(radius).."." end table.insert(subargs, radius) elseif subcommand == "remove" then + if #parts < 2 then + return false, "Error: Not enough arguments." + end local index = tonumber(parts[2]) if not index then - return false, "Error: Invalid index '"..parts[1].."'. The index to remove must be a positive integer." + return false, "Error: Invalid index '"..parts[2].."'. The index to remove must be a positive integer." end if index < 1 then return false, "Error: The minimum index size is 1, but you entered "..tostring(index).."." end table.insert(subargs, index) elseif subcommand == "render" then + if #parts < 2 then + return false, "Error: Not enough arguments." + end local replace_node = worldedit.normalize_nodename(parts[2]) local threshold = 1 @@ -65,7 +74,7 @@ worldedit.register_command("metaballs", { end table.insert(subargs, replace_node) table.insert(subargs, threshold) - elseif subcommand ~= "list" and subcommand ~= "clear" then + elseif subcommand ~= "list" and subcommand ~= "clear" and subcommand ~= "volume" then return false, "Error: Unknown subcommand '"..parts[1].."'." end @@ -73,7 +82,7 @@ worldedit.register_command("metaballs", { end, nodes_needed = function(name, subcommand) if subcommand == "render" then - return worldedit.volume(worldedit.pos1[name], worldedit.pos2[name]) + return wea.metaballs.volume(name) else return 0 end @@ -81,13 +90,19 @@ worldedit.register_command("metaballs", { func = function(name, subcommand, subargs) local start_time = wea.get_ms_time() local message = "" - local append_time = true + local append_time = false if subcommand == "list" then local success, list = wea.metaballs.list_pretty(name) if not success then return success, list end message = list - append_time = false + elseif subcommand == "volume" then + local success, metaballs_list = wea.metaballs.list(name) + if not success then return success, metaballs_list end + local success2, volume = wea.metaballs.volume(name) + if not success2 then return success2, volume end + + message = #metaballs_list.." will take up to "..tostring(volume).." nodes of space" elseif subcommand == "clear" then local success, metaballs_cleared = wea.metaballs.clear(name) if not success then return success, metaballs_cleared end @@ -108,6 +123,7 @@ worldedit.register_command("metaballs", { if not success then return success, metaballs_count end message = "added metaball at "..pos.." with radius "..tostring(radius).." - "..metaballs_count.." metaballs are now defined" + append_time = false elseif subcommand == "render" then local replace_node = subargs[1] local threshold = subargs[2] @@ -123,6 +139,7 @@ worldedit.register_command("metaballs", { if not success2 then return success2, nodes_replaced end message = nodes_replaced.." nodes replaced using "..tostring(#metaballs).." metaballs" + append_time = true end local time_taken = wea.get_ms_time() - start_time diff --git a/worldeditadditions_commands/init.lua b/worldeditadditions_commands/init.lua index bacbd60..ed8d1d7 100644 --- a/worldeditadditions_commands/init.lua +++ b/worldeditadditions_commands/init.lua @@ -39,7 +39,7 @@ dofile(we_c.modpath.."/commands/spiral2.lua") dofile(we_c.modpath.."/commands/copy.lua") dofile(we_c.modpath.."/commands/move.lua") dofile(we_c.modpath.."/commands/dome.lua") - +dofile(we_c.modpath.."/commands/metaball.lua") dofile(we_c.modpath.."/commands/count.lua") dofile(we_c.modpath.."/commands/sculpt.lua") From 60c8f30109d4ba5034ee687ba64c6b563696bf59 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Mon, 16 May 2022 20:16:48 +0100 Subject: [PATCH 05/25] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 008b5cc..d1c97d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Note to self: See the bottom of this file for the release template text. ## v1.14: The untitled update (unreleased) - Add `//dome+`, which allows you to change the direction the dome is pointing in, and also create multiple domes at once + - Add `//metaball`, which renders 2 or more [metaballs](https://en.wikipedia.org/wiki/Metaballs) in Minetest - Migrate from `depends.txt` to `mod.conf` From 9d3a4ce263885e08d0f9edf8a0fc12d4d3d10ee2 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Mon, 16 May 2022 20:33:04 +0100 Subject: [PATCH 06/25] refactor aliases into a separate file --- worldeditadditions_commands/aliases.lua | 11 +++++++++++ worldeditadditions_commands/init.lua | 12 +----------- 2 files changed, 12 insertions(+), 11 deletions(-) create mode 100644 worldeditadditions_commands/aliases.lua diff --git a/worldeditadditions_commands/aliases.lua b/worldeditadditions_commands/aliases.lua new file mode 100644 index 0000000..ca16922 --- /dev/null +++ b/worldeditadditions_commands/aliases.lua @@ -0,0 +1,11 @@ +worldedit.alias_command("smoothadv", "convolve") +worldedit.alias_command("conv", "convolve") + +worldedit.alias_command("naturalise", "layers") +worldedit.alias_command("naturalize", "layers") + +worldedit.alias_command("flora", "bonemeal") + +-- Measure Tools +worldedit.alias_command("mcount", "count") +worldedit.alias_command("mfacing", "mface") diff --git a/worldeditadditions_commands/init.lua b/worldeditadditions_commands/init.lua index ed8d1d7..168508d 100644 --- a/worldeditadditions_commands/init.lua +++ b/worldeditadditions_commands/init.lua @@ -80,17 +80,7 @@ end -- end -worldedit.alias_command("smoothadv", "convolve") -worldedit.alias_command("conv", "convolve") - -worldedit.alias_command("naturalise", "layers") -worldedit.alias_command("naturalize", "layers") - -worldedit.alias_command("flora", "bonemeal") - --- Measure Tools -worldedit.alias_command("mcount", "count") -worldedit.alias_command("mfacing", "mface") +dofile(we_c.modpath.."/aliases.lua") --- Overrides to core WorldEdit commands From 10f350c967ae18736816ecd734b04ff67a59eeb6 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Mon, 16 May 2022 21:21:15 +0100 Subject: [PATCH 07/25] Delete copied code Given licence incompatibilities, we can't really copy code from WorldEdit --- worldeditadditions_commands/aliases.lua | 10 ++++++ worldeditadditions_commands/init.lua | 10 ------ worldeditadditions_core/register/init.lua | 4 +-- worldeditadditions_core/register/override.lua | 35 ------------------- worldeditadditions_core/register/register.lua | 32 ----------------- 5 files changed, 12 insertions(+), 79 deletions(-) delete mode 100644 worldeditadditions_core/register/override.lua delete mode 100644 worldeditadditions_core/register/register.lua diff --git a/worldeditadditions_commands/aliases.lua b/worldeditadditions_commands/aliases.lua index ca16922..3d64993 100644 --- a/worldeditadditions_commands/aliases.lua +++ b/worldeditadditions_commands/aliases.lua @@ -9,3 +9,13 @@ worldedit.alias_command("flora", "bonemeal") -- Measure Tools worldedit.alias_command("mcount", "count") worldedit.alias_command("mfacing", "mface") + + +--- Overrides to core WorldEdit commands +-- These are commented out for now, as they could be potentially dangerous to stability +-- Thorough testing is required of our replacement commands before these are uncommented +-- TODO: Depend on worldeditadditions_core before uncommenting this +-- BUG: //move+ seems to be leaving stuff behind for some strange reason --@sbrl 2021-12-26 +-- worldeditadditions_core.alias_override("copy", "copy+") +-- worldeditadditions_core.alias_override("move", "move+") -- MAY have issues where it doesn't overwrite the old region properly, but haven't been able to reliably reproduce this +-- worldeditadditions_core.alias_override("replace", "replacemix") diff --git a/worldeditadditions_commands/init.lua b/worldeditadditions_commands/init.lua index 168508d..22f17d1 100644 --- a/worldeditadditions_commands/init.lua +++ b/worldeditadditions_commands/init.lua @@ -81,13 +81,3 @@ end dofile(we_c.modpath.."/aliases.lua") - - ---- Overrides to core WorldEdit commands --- These are commented out for now, as they could be potentially dangerous to stability --- Thorough testing is required of our replacement commands before these are uncommented --- TODO: Depend on worldeditadditions_core before uncommenting this --- BUG: //move+ seems to be leaving stuff behind for some strange reason --@sbrl 2021-12-26 --- worldeditadditions_core.alias_override("copy", "copy+") --- worldeditadditions_core.alias_override("move", "move+") -- MAY have issues where it doesn't overwrite the old region properly, but haven't been able to reliably reproduce this --- worldeditadditions_core.alias_override("replace", "replacemix") diff --git a/worldeditadditions_core/register/init.lua b/worldeditadditions_core/register/init.lua index 2ebb6c5..ff1fc86 100644 --- a/worldeditadditions_core/register/init.lua +++ b/worldeditadditions_core/register/init.lua @@ -10,5 +10,5 @@ local we_cm = worldeditadditions_core.modpath .. "/register/" dofile(we_cm.."check.lua") dofile(we_cm.."handler.lua") -dofile(we_cm.."register.lua") -dofile(we_cm.."override.lua") +-- dofile(we_cm.."register.lua") +-- dofile(we_cm.."override.lua") diff --git a/worldeditadditions_core/register/override.lua b/worldeditadditions_core/register/override.lua deleted file mode 100644 index cc74d2a..0000000 --- a/worldeditadditions_core/register/override.lua +++ /dev/null @@ -1,35 +0,0 @@ -local we_c = worldeditadditions_core -function we_c.override_command(name, def) - local def = table.copy(def) - local success, err = we_c.check_command(name, def) - - if not success then - error(err) - return false - end - - minetest.override_chatcommand("/" .. name, { - privs = def.privs, - params = def.params, - description = def.description, - func = function(player_name, param) - return we_c.chatcommand_handler(name, player_name, param) - end, - }) - worldedit.registered_commands[name] = def -end - -function we_c.alias_override(alias, original) - if not worldedit.registered_commands[original] then - minetest.log("error", "worldedit_shortcommands: original " .. original .. " does not exist") - return - end - if minetest.chatcommands["/" .. alias] then - minetest.override_chatcommand("/" .. alias, minetest.chatcommands["/" .. original]) - worldedit.registered_commands[alias] = worldedit.registered_commands[original] - else - minetest.register_chatcommand("/" .. alias, minetest.chatcommands["/" .. original]) - worldedit.registered_commands[alias] = worldedit.registered_commands[original] - end - -end diff --git a/worldeditadditions_core/register/register.lua b/worldeditadditions_core/register/register.lua deleted file mode 100644 index acd845d..0000000 --- a/worldeditadditions_core/register/register.lua +++ /dev/null @@ -1,32 +0,0 @@ -local we_c = worldeditadditions_core -function we_c.register_command(name, def) - local def = table.copy(def) - local success, err = we_c.check_command(name, def) - if not success then - return false, err - end - - minetest.register_chatcommand("/" .. name, { - privs = def.privs, - params = def.params, - description = def.description, - func = function(player_name, param) - return we_c.chatcommand_handler(name, player_name, param) - end, - }) - worldedit.registered_commands[name] = def -end - -function we_c.alias_command(alias, original) - if not worldedit.registered_commands[original] then - minetest.log("error", "worldedit_shortcommands: original " .. original .. " does not exist") - return - end - if minetest.chatcommands["/" .. alias] then - minetest.log("error", "worldedit_shortcommands: alias " .. alias .. " already exists") - return - end - - minetest.register_chatcommand("/" .. alias, minetest.chatcommands["/" .. original]) - worldedit.registered_commands[alias] = worldedit.registered_commands[original] -end From d3119ee54a760a9bf77edfe42076a45ac220074f Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Mon, 16 May 2022 22:37:10 +0100 Subject: [PATCH 08/25] Delete more copied code --- worldeditadditions_core/register/check.lua | 26 ------------- worldeditadditions_core/register/handler.lua | 40 -------------------- 2 files changed, 66 deletions(-) delete mode 100644 worldeditadditions_core/register/check.lua delete mode 100644 worldeditadditions_core/register/handler.lua diff --git a/worldeditadditions_core/register/check.lua b/worldeditadditions_core/register/check.lua deleted file mode 100644 index 5c08285..0000000 --- a/worldeditadditions_core/register/check.lua +++ /dev/null @@ -1,26 +0,0 @@ -function worldeditadditions_core.check_command(name, def) - if not (name and #name > 0) then - return false, "Error: No command name." - end - if not def.privs then - return false, "Error: privs is nill. Expected table." - end - def.require_pos = def.require_pos or 0 - if not (def.require_pos >= 0 and def.require_pos < 3) then - return false, "Error: require_pos must be greater than -1 and less than 3." - end - if not def.parse then - if def.params == "" then - def.parse = function(params_text) return true end - else - return false, "Error: parse function is invalid." - end - end - if not (def.nodes_needed == nil or type(def.nodes_needed) == "function") then - return false, "Error: nodes_needed must be nil or function." - end - if not def.func then - return false, "Error: main function is invalid." - end - return true -end diff --git a/worldeditadditions_core/register/handler.lua b/worldeditadditions_core/register/handler.lua deleted file mode 100644 index a9beb9a..0000000 --- a/worldeditadditions_core/register/handler.lua +++ /dev/null @@ -1,40 +0,0 @@ -function worldeditadditions_core.chatcommand_handler(cmd_name, name, param) - local def = assert(worldedit.registered_commands[cmd_name], "Error: Failed to locate worldedit command definition for command '"..name.."' (this is probably a bug).") - - if def.require_pos == 2 then - local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] - if pos1 == nil or pos2 == nil then - worldedit.player_notify(name, "no region selected") - return - end - elseif def.require_pos == 1 then - local pos1 = worldedit.pos1[name] - if pos1 == nil then - worldedit.player_notify(name, "no position 1 selected") - return - end - end - - local parsed = {def.parse(param)} - local success = table.remove(parsed, 1) - if not success then - worldedit.player_notify(name, parsed[1] or "invalid usage") - return - end - - if def.nodes_needed then - local count = def.nodes_needed(name, unpack(parsed)) - safe_region(name, count, function() - local success, msg = def.func(name, unpack(parsed)) - if msg then - minetest.chat_send_player(name, msg) - end - end) - else - -- no "safe region" check - local success, msg = def.func(name, unpack(parsed)) - if msg then - minetest.chat_send_player(name, msg) - end - end -end From f984f5d7b7932b0336ffe14e321350bc2295b22d Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Mon, 16 May 2022 23:32:40 +0100 Subject: [PATCH 09/25] Begin rewriting worldeditadditions_core We should be able to make things a lot cleaner and more robust. --- .../core/integrations/noworldedit.lua | 8 +++ .../core/integrations/worldedit.lua | 15 +++++ .../core/register_command.lua | 58 +++++++++++++++++++ worldeditadditions_core/init.lua | 27 ++++++--- worldeditadditions_core/register/init.lua | 14 ----- worldeditadditions_core/worldedit/init.lua | 5 -- 6 files changed, 100 insertions(+), 27 deletions(-) create mode 100644 worldeditadditions_core/core/integrations/noworldedit.lua create mode 100644 worldeditadditions_core/core/integrations/worldedit.lua create mode 100644 worldeditadditions_core/core/register_command.lua delete mode 100644 worldeditadditions_core/register/init.lua delete mode 100644 worldeditadditions_core/worldedit/init.lua diff --git a/worldeditadditions_core/core/integrations/noworldedit.lua b/worldeditadditions_core/core/integrations/noworldedit.lua new file mode 100644 index 0000000..1fd0810 --- /dev/null +++ b/worldeditadditions_core/core/integrations/noworldedit.lua @@ -0,0 +1,8 @@ +local wea_c = worldeditadditions_core + +--- WorldEdit shim just in case WorldEdit doesn't exist. +-- Eventually this will go away. +worldedit = { + -- Note that you want worldeditadditions_core.registered_commands, and not worldedit.registered_commands! This table is not guaranteed to contain all command definitions in the future, whereas worldedit command definitions are guaranteed to be imported into this worldeditadditions_core.registered_commands. + registered_commands = { } +} diff --git a/worldeditadditions_core/core/integrations/worldedit.lua b/worldeditadditions_core/core/integrations/worldedit.lua new file mode 100644 index 0000000..23913ac --- /dev/null +++ b/worldeditadditions_core/core/integrations/worldedit.lua @@ -0,0 +1,15 @@ +local wea_c = worldeditadditions_core + + +for name,definition in pairs(worldedit.registered_commands) do + -- This check should not be needed since worldeditadditions_commands + -- depends on this mod (so it will overwrite any worldedit definitions, + -- since worldedit is loaded first), but it's here just in case + if not wea_c.registered_commands[name] then + -- The Minetest chat command should already be imported here, so we + -- just need to import worldedit chat command definition here + wea_c.registered_commands[name] = definition + else + minetest.log("info", "Skipping registration of worldedit command "..name..", as it's already a registered worldeditadditions command") + end +end diff --git a/worldeditadditions_core/core/register_command.lua b/worldeditadditions_core/core/register_command.lua new file mode 100644 index 0000000..509ea86 --- /dev/null +++ b/worldeditadditions_core/core/register_command.lua @@ -0,0 +1,58 @@ +-- ██████ ███████ ██████ ██ ███████ ████████ ███████ ██████ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ██████ █████ ██ ███ ██ ███████ ██ █████ ██████ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ██ ██ ███████ ██████ ██ ███████ ██ ███████ ██ ██ + +-- WorldEditAdditions chat command registration + +local function log_error(cmdname, error_message) + minetest.log("error", "register_command("..cmdname..") error: "..error_message) +end + +local function register_command(cmdname, options) + --- + -- 1: Validation + --- + if type(options.params) ~= "string" then + log_error(cmdname, "The params option is not a string.") + return false + end + if type(options.description) ~= "string" then + log_error(cmdname, "The description option is not a string.") + return false + end + if type(options.parse) ~= "string" then + log_error(cmdname, "The parse option is not a function.") + return false + end + if type(options.nodes_needed) ~= "string" then + log_error(cmdname, "The nodes_needed option is not a function.") + return false + end + if type(options.func) ~= "string" then + log_error(cmdname, "The func option is not a function.") + return false + end + + + --- + -- 2: Normalisation + --- + if not options.privs then options.privs = {} end + if not options.require_pos then options.require_pos = 0 end + + + --- + -- 3: Registration + --- + minetest.register_chatcommand("/"..cmdname, { + params = options.params, + description = options.description, + privs = options.privs, + func = function(player_name, paramtext) + -- TODO: Fill this in + end + + }) +end diff --git a/worldeditadditions_core/init.lua b/worldeditadditions_core/init.lua index e4e22ad..b34c1d6 100644 --- a/worldeditadditions_core/init.lua +++ b/worldeditadditions_core/init.lua @@ -5,14 +5,25 @@ -- @license Mozilla Public License, 2.0 -- @author Starbeamrainbowlabs and VorTechnix -worldeditadditions_core = {} +local temp = true +if temp then return end +-- This mod isn't finished yet, so it will not be executed for now. + + +local modpath = minetest.get_modpath("worldeditadditions_core") + +worldeditadditions_core = { + modpath = modpath, + registered_commands = {}, + register_command = dofile(modpath.."/core/register_command.lua") +} + + local we_c = worldeditadditions_core -we_c.modpath = minetest.get_modpath("worldeditadditions_core") - -- Initialise WorldEdit stuff if the WorldEdit mod is not present -if not minetest.get_modpath("worldedit") then - dofile(we_c.modpath.."/worldedit/init.lua") -end - -dofile(we_c.modpath.."/register/init.lua") +if minetest.global_exists("bonemeal") then + dofile(we_c.modpath.."/core/integrations/worldedit.lua") +else + dofile(we_c.modpath.."/core/integrations/noworldedit.lua") +end) diff --git a/worldeditadditions_core/register/init.lua b/worldeditadditions_core/register/init.lua deleted file mode 100644 index ff1fc86..0000000 --- a/worldeditadditions_core/register/init.lua +++ /dev/null @@ -1,14 +0,0 @@ --- ██████ ███████ ██████ ██ ███████ ████████ ███████ ██████ --- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ --- ██████ █████ ██ ███ ██ ███████ ██ █████ ██████ --- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ --- ██ ██ ███████ ██████ ██ ███████ ██ ███████ ██ ██ - --- WorldEditAdditions Register/Overwrite Functions - -local we_cm = worldeditadditions_core.modpath .. "/register/" - -dofile(we_cm.."check.lua") -dofile(we_cm.."handler.lua") --- dofile(we_cm.."register.lua") --- dofile(we_cm.."override.lua") diff --git a/worldeditadditions_core/worldedit/init.lua b/worldeditadditions_core/worldedit/init.lua deleted file mode 100644 index f43eb44..0000000 --- a/worldeditadditions_core/worldedit/init.lua +++ /dev/null @@ -1,5 +0,0 @@ ---- WorldEdit shim just in case WorldEdit doesn't exist - -worldedit = { - registered_commands = { } -} From 19c8d0e7b9693580bebf6f7aa7a2d419b5af8829 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Mon, 16 May 2022 23:33:22 +0100 Subject: [PATCH 10/25] core: make options.nodes_needed optional --- worldeditadditions_core/core/register_command.lua | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/worldeditadditions_core/core/register_command.lua b/worldeditadditions_core/core/register_command.lua index 509ea86..c06094d 100644 --- a/worldeditadditions_core/core/register_command.lua +++ b/worldeditadditions_core/core/register_command.lua @@ -26,10 +26,6 @@ local function register_command(cmdname, options) log_error(cmdname, "The parse option is not a function.") return false end - if type(options.nodes_needed) ~= "string" then - log_error(cmdname, "The nodes_needed option is not a function.") - return false - end if type(options.func) ~= "string" then log_error(cmdname, "The func option is not a function.") return false @@ -41,7 +37,7 @@ local function register_command(cmdname, options) --- if not options.privs then options.privs = {} end if not options.require_pos then options.require_pos = 0 end - + if not options.nodes_needed then options.nodes_needed = function() return 0 end --- -- 3: Registration From fa9b511e339f6e48d795da9c8ee150bd8c558398 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Mon, 16 May 2022 23:40:03 +0100 Subject: [PATCH 11/25] core: finish initial register_command --- worldeditadditions_core/core/register_command.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/worldeditadditions_core/core/register_command.lua b/worldeditadditions_core/core/register_command.lua index c06094d..0e47e31 100644 --- a/worldeditadditions_core/core/register_command.lua +++ b/worldeditadditions_core/core/register_command.lua @@ -5,6 +5,9 @@ -- ██ ██ ███████ ██████ ██ ███████ ██ ███████ ██ ██ -- WorldEditAdditions chat command registration +local we_c = worldeditadditions_core + +local run_command = dofile(we_c.modpath.."/core/run_command.lua") local function log_error(cmdname, error_message) minetest.log("error", "register_command("..cmdname..") error: "..error_message) @@ -30,6 +33,10 @@ local function register_command(cmdname, options) log_error(cmdname, "The func option is not a function.") return false end + if we_c.registered_commands[cmdname] and options.override ~= true then + log_error(cmdname, "A WorldEditAdditions command with that name is registered, but the option override is not set to true.") + return false + end --- @@ -37,7 +44,7 @@ local function register_command(cmdname, options) --- if not options.privs then options.privs = {} end if not options.require_pos then options.require_pos = 0 end - if not options.nodes_needed then options.nodes_needed = function() return 0 end + if not options.nodes_needed then options.nodes_needed = function() return 0 end end --- -- 3: Registration @@ -47,8 +54,8 @@ local function register_command(cmdname, options) description = options.description, privs = options.privs, func = function(player_name, paramtext) - -- TODO: Fill this in + run_command(cmdname, player_name, paramtext) end - }) + we_c.registered_commands[cmdname] = options end From 9bdd7d2a253410c0d6840d25e39e47aa7cb6d9ea Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Mon, 16 May 2022 23:40:17 +0100 Subject: [PATCH 12/25] core: add run_command shim, but it's not finished yet --- worldeditadditions_core/core/run_command.lua | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 worldeditadditions_core/core/run_command.lua diff --git a/worldeditadditions_core/core/run_command.lua b/worldeditadditions_core/core/run_command.lua new file mode 100644 index 0000000..de74a80 --- /dev/null +++ b/worldeditadditions_core/core/run_command.lua @@ -0,0 +1,5 @@ + + +function run_command(cmdname, func, paramtext) + -- TODO: Fill this in +end From 4ab386788d720e3db691b16fe3df68e76f2151fc Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Mon, 16 May 2022 23:41:09 +0100 Subject: [PATCH 13/25] fixup --- worldeditadditions_core/core/register_command.lua | 2 ++ worldeditadditions_core/core/run_command.lua | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/worldeditadditions_core/core/register_command.lua b/worldeditadditions_core/core/register_command.lua index 0e47e31..a503a7b 100644 --- a/worldeditadditions_core/core/register_command.lua +++ b/worldeditadditions_core/core/register_command.lua @@ -59,3 +59,5 @@ local function register_command(cmdname, options) }) we_c.registered_commands[cmdname] = options end + +return register_command diff --git a/worldeditadditions_core/core/run_command.lua b/worldeditadditions_core/core/run_command.lua index de74a80..fcd7bf1 100644 --- a/worldeditadditions_core/core/run_command.lua +++ b/worldeditadditions_core/core/run_command.lua @@ -1,5 +1,7 @@ -function run_command(cmdname, func, paramtext) +local function run_command(cmdname, func, paramtext) -- TODO: Fill this in end + +return run_command From 1fda9725c773a500418ce6091b58be887828785e Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Tue, 17 May 2022 01:03:58 +0100 Subject: [PATCH 14/25] Implement run_command, but it's not quite finished yet We still have yet to implement safe_region. Doing so will be non-trivial, as we'll need to override //y and //n, but then also keep track of commands defined in worldedit and call the right version of //y and //n. --- worldeditadditions_core/README.md | 2 + .../core/lib/human_size.lua | 17 +++++++ .../core/register_command.lua | 2 +- worldeditadditions_core/core/run_command.lua | 50 ++++++++++++++++++- worldeditadditions_core/init.lua | 5 ++ 5 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 worldeditadditions_core/core/lib/human_size.lua diff --git a/worldeditadditions_core/README.md b/worldeditadditions_core/README.md index 0f2350c..4deee17 100644 --- a/worldeditadditions_core/README.md +++ b/worldeditadditions_core/README.md @@ -1,3 +1,5 @@ # worldeditadditions_core This mod's purpose is to provide a solid base upon which the rest of WorldEditAdditions can function. Once it is complete, we will be able to mark our dependency on `worldedit` itself optional. To get to that point though will still require a significant effort in implementing enhanced versions of all existing WorldEdit commands. If you've got some free time and a great idea for a command, please do open a pull request! :D + +In short, `worldeditadditions_core` is a reimplementation of a number of underlying parts of the worldedit engine. Parts of `worldeditadditions_core` are likely to look very similar to parts of WorldEdit - this is because inspiration was taken from Uberi/WorldEdit when implementing `worldeditadditions_core`. diff --git a/worldeditadditions_core/core/lib/human_size.lua b/worldeditadditions_core/core/lib/human_size.lua new file mode 100644 index 0000000..fa8dce3 --- /dev/null +++ b/worldeditadditions_core/core/lib/human_size.lua @@ -0,0 +1,17 @@ + +-- TODO: This is duplicated from worldeditadditions/utils. We should consider moving worldeditadditions/utils to worldeditadditions_core. Perhaps also we could move the definition of the worldeditadditions namespace to worldeditadditions_core too? + +--- Formats (usually large) numbers as human-readable strings. +-- Ported from PHP: https://github.com/sbrl/Pepperminty-Wiki/blob/0a81c940c5803856db250b29f54658476bc81e21/core/05-functions.php#L67 +-- @param n number The number to format. +-- @param decimals number The number of decimal places to show. +-- @return string A formatted string that represents the given input number. +local function human_size(n, decimals) + local sizes = { "", "K", "M", "G", "T", "P", "E", "Y", "Z" } + local factor = math.floor((#tostring(n) - 1) / 3) + local multiplier = 10^(decimals or 0) + local result = math.floor(0.5 + (n / math.pow(1000, factor)) * multiplier) / multiplier + return result .. sizes[factor+1] +end + +return human_size diff --git a/worldeditadditions_core/core/register_command.lua b/worldeditadditions_core/core/register_command.lua index a503a7b..e29a1a2 100644 --- a/worldeditadditions_core/core/register_command.lua +++ b/worldeditadditions_core/core/register_command.lua @@ -54,7 +54,7 @@ local function register_command(cmdname, options) description = options.description, privs = options.privs, func = function(player_name, paramtext) - run_command(cmdname, player_name, paramtext) + run_command(cmdname, options, player_name, paramtext) end }) we_c.registered_commands[cmdname] = options diff --git a/worldeditadditions_core/core/run_command.lua b/worldeditadditions_core/core/run_command.lua index fcd7bf1..463da39 100644 --- a/worldeditadditions_core/core/run_command.lua +++ b/worldeditadditions_core/core/run_command.lua @@ -1,7 +1,53 @@ +local we_c = worldeditadditions_core +local human_size = dofile(we_c.modpath.."/core/lib/human_size.lua") -local function run_command(cmdname, func, paramtext) - -- TODO: Fill this in +-- TODO: Reimplement worldedit.player_notify(player_name, msg_text) + +local function run_command_stage2(player_name, func, parse_result) + local success, result_message = func(player_name, unpack(parse_result)) + if result_message then + -- TODO: If we were unsuccessfull, then colour the message red + worldedit.player_notify(player_name, result_message) + end +end + +local function run_command(cmdname, options, player_name, paramtext) + if options.require_pos > 0 and not worldedit.pos1[player_name] then + worldedit.player_notify(player_name, "Error: pos1 must be selected to use this command.") + return false + end + if options.require_pos > 1 and not worldedit.pos2[player_name] then + worldedit.player_notify(player_name, "Error: Both pos1 and pos2 must be selected (together making a region) to use this command.") + return false + end + + local parse_result = { options.parse(paramtext) } + local success = table.remove(parse_result, 1) + if not success then + worldedit.player_notify(player_name, parse_result[1] or "Invalid usage (no further error message was provided by the command. This is probably a bug.)") + return false + end + + if options.nodes_needed then + local potential_changes = options.nodes_needed(player_name, unpack(parse_result)) + + local limit = we_c.safe_region_limit_default + if we_c.safe_region_limits[player_name] then + limit = we_c.safe_region_limits[player_name] + end + + if potential_changes > limit then + worldedit.player_notify(player_name, "/"..cmdname.." "..paramtext.."' may affect up to "..human_size(potential_changes).." nodes. Type //y to continue, or //n to cancel (see the //saferegion command to control when this message appears).") + + -- TODO: Wrap run_command_stage2 in safe_region stuff + run_command_stage2(player_name, options.func, parse_result) + end + else + run_command_stage2(player_name, options.func, parse_result) + end + + end return run_command diff --git a/worldeditadditions_core/init.lua b/worldeditadditions_core/init.lua index b34c1d6..6446338 100644 --- a/worldeditadditions_core/init.lua +++ b/worldeditadditions_core/init.lua @@ -15,6 +15,11 @@ local modpath = minetest.get_modpath("worldeditadditions_core") worldeditadditions_core = { modpath = modpath, registered_commands = {}, + -- Storage for per-player node limits before safe_region kicks in. + -- TODO: Persist these to disk. + safe_region_limits = {}, + -- The default limit for new players on the number of potential nodes changed before safe_region kicks in. + safe_region_limit_default = 100000, register_command = dofile(modpath.."/core/register_command.lua") } From d21f7ca5fba3c1e5bfdbdb3bfc925b682ffda3db Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Tue, 17 May 2022 01:04:38 +0100 Subject: [PATCH 15/25] core: minor fixes --- worldeditadditions_core/core/run_command.lua | 1 - worldeditadditions_core/init.lua | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/worldeditadditions_core/core/run_command.lua b/worldeditadditions_core/core/run_command.lua index 463da39..4a1e252 100644 --- a/worldeditadditions_core/core/run_command.lua +++ b/worldeditadditions_core/core/run_command.lua @@ -47,7 +47,6 @@ local function run_command(cmdname, options, player_name, paramtext) run_command_stage2(player_name, options.func, parse_result) end - end return run_command diff --git a/worldeditadditions_core/init.lua b/worldeditadditions_core/init.lua index 6446338..9ca8cae 100644 --- a/worldeditadditions_core/init.lua +++ b/worldeditadditions_core/init.lua @@ -31,4 +31,4 @@ if minetest.global_exists("bonemeal") then dofile(we_c.modpath.."/core/integrations/worldedit.lua") else dofile(we_c.modpath.."/core/integrations/noworldedit.lua") -end) +end From 8f6c3e020feadd5eae23bc9a7572ddedaafb0f5c Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Tue, 17 May 2022 01:04:51 +0100 Subject: [PATCH 16/25] fixup --- worldeditadditions_core/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worldeditadditions_core/init.lua b/worldeditadditions_core/init.lua index 9ca8cae..9ed82b3 100644 --- a/worldeditadditions_core/init.lua +++ b/worldeditadditions_core/init.lua @@ -27,7 +27,7 @@ worldeditadditions_core = { local we_c = worldeditadditions_core -- Initialise WorldEdit stuff if the WorldEdit mod is not present -if minetest.global_exists("bonemeal") then +if minetest.global_exists("worldedit") then dofile(we_c.modpath.."/core/integrations/worldedit.lua") else dofile(we_c.modpath.."/core/integrations/noworldedit.lua") From 4306035ef23c537f4cb2058273d4de7be63b42b4 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Wed, 18 May 2022 02:31:08 +0100 Subject: [PATCH 17/25] core: implement safe_region --- worldeditadditions_core/core/run_command.lua | 8 ++- worldeditadditions_core/core/safe_region.lua | 65 ++++++++++++++++++++ 2 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 worldeditadditions_core/core/safe_region.lua diff --git a/worldeditadditions_core/core/run_command.lua b/worldeditadditions_core/core/run_command.lua index 4a1e252..22428fa 100644 --- a/worldeditadditions_core/core/run_command.lua +++ b/worldeditadditions_core/core/run_command.lua @@ -1,5 +1,7 @@ local we_c = worldeditadditions_core +-- WARNING: safe_region MUST NOT be imported more than once, as it defines chat commands. If you want to import it again elsewhere, check first that multiple dofile() calls don't execute a file more than once. +local safe_region = dofile(we_c.modpath.."/core/safe_region.lua") local human_size = dofile(we_c.modpath.."/core/lib/human_size.lua") -- TODO: Reimplement worldedit.player_notify(player_name, msg_text) @@ -39,9 +41,9 @@ local function run_command(cmdname, options, player_name, paramtext) if potential_changes > limit then worldedit.player_notify(player_name, "/"..cmdname.." "..paramtext.."' may affect up to "..human_size(potential_changes).." nodes. Type //y to continue, or //n to cancel (see the //saferegion command to control when this message appears).") - - -- TODO: Wrap run_command_stage2 in safe_region stuff - run_command_stage2(player_name, options.func, parse_result) + safe_region(player_name, cmdname, function() + run_command_stage2(player_name, options.func, parse_result) + end) end else run_command_stage2(player_name, options.func, parse_result) diff --git a/worldeditadditions_core/core/safe_region.lua b/worldeditadditions_core/core/safe_region.lua new file mode 100644 index 0000000..0facbf4 --- /dev/null +++ b/worldeditadditions_core/core/safe_region.lua @@ -0,0 +1,65 @@ + +-- ███████ █████ ███████ ███████ ██████ ███████ ██████ ██ ██████ ███ ██ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ +-- ███████ ███████ █████ █████ ██████ █████ ██ ███ ██ ██ ██ ██ ██ ██ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ███████ ██ ██ ██ ███████ ██ ██ ███████ ██████ ██ ██████ ██ ████ + +local worldedit_command_y, worldedit_command_n + +if minetest.global_exists("worldedit") then + worldedit_command_y = minetest.registered_commands["/y"].func + worldedit_command_n = minetest.registered_commands["/n"].func +end + +--- A table that holds at most 1 pending function call per player. +local pending_calls = {} + +--- Captures the given function in the safe_region subsystem for later execution. +-- @param player_name string The name of the player. +-- @param cmdname string The name of the command being executed. +-- @param func function The function to execute later. Will be passed NO ARGUMENTS should it ever get executed in the future (this is not guaranteed). +-- @returns nil +local function safe_region(player_name, cmdname, func) + pending_calls[player_name] = { + cmdname = cmdname, + func = func + } +end + +minetest.override_chatcommand("/y", { + params = "", + description = "Run a pending operation that was captured by the safe region system earlier.", + func = function(player_name) + if pending_calls[player_name] == nil then + if minetest.global_exists("worldedit") and worldedit_command_y ~= nil then + worldedit_command_y(player_name) + else + worldedit.player_notify(player_name, "There aren't any pending operations at the moment.") + end + else + pending_calls[player_name].func() + pending_calls[player_name] = nil + end + end +}) + +minetest.override_chatcommand("/n", { + params = "", + description = "Abort a pending operation that was captured by the safe region system.", + func = function(player_name) + if pending_calls[player_name] == nil then + if minetest.global_exists("worldedit") and worldedit_command_y ~= nil then + worldedit_command_n(player_name) + else + worldedit.player_notify(player_name, "There aren't any operations pending, so there's nothing to abort.") + end + else + worldedit.player_notify(player_name, "Aborting captured command /"..pending_calls[player_name].cmdname..".") + pending_calls[player_name] = nil + end + end +}) + + +return safe_region From c60b5c5bad5a20d2573bd6a6401563344f16068a Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Thu, 19 May 2022 01:45:36 +0100 Subject: [PATCH 18/25] core: fix bugs, enable! --- worldeditadditions_core/core/register_command.lua | 7 ++++--- worldeditadditions_core/core/run_command.lua | 8 ++++---- worldeditadditions_core/core/safe_region.lua | 4 ++-- worldeditadditions_core/init.lua | 4 ++-- worldeditadditions_core/mod.conf | 2 +- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/worldeditadditions_core/core/register_command.lua b/worldeditadditions_core/core/register_command.lua index e29a1a2..e7525ae 100644 --- a/worldeditadditions_core/core/register_command.lua +++ b/worldeditadditions_core/core/register_command.lua @@ -5,15 +5,16 @@ -- ██ ██ ███████ ██████ ██ ███████ ██ ███████ ██ ██ -- WorldEditAdditions chat command registration -local we_c = worldeditadditions_core - -local run_command = dofile(we_c.modpath.."/core/run_command.lua") +local modpath = minetest.get_modpath("worldeditadditions_core") +local run_command = dofile(modpath.."/core/run_command.lua") local function log_error(cmdname, error_message) minetest.log("error", "register_command("..cmdname..") error: "..error_message) end local function register_command(cmdname, options) + local we_c = worldeditadditions_core + --- -- 1: Validation --- diff --git a/worldeditadditions_core/core/run_command.lua b/worldeditadditions_core/core/run_command.lua index 22428fa..71dd4bc 100644 --- a/worldeditadditions_core/core/run_command.lua +++ b/worldeditadditions_core/core/run_command.lua @@ -1,8 +1,7 @@ -local we_c = worldeditadditions_core - -- WARNING: safe_region MUST NOT be imported more than once, as it defines chat commands. If you want to import it again elsewhere, check first that multiple dofile() calls don't execute a file more than once. -local safe_region = dofile(we_c.modpath.."/core/safe_region.lua") -local human_size = dofile(we_c.modpath.."/core/lib/human_size.lua") +local modpath = minetest.get_modpath("worldeditadditions_core") +local safe_region = dofile(modpath.."/core/safe_region.lua") +local human_size = dofile(modpath.."/core/lib/human_size.lua") -- TODO: Reimplement worldedit.player_notify(player_name, msg_text) @@ -15,6 +14,7 @@ local function run_command_stage2(player_name, func, parse_result) end local function run_command(cmdname, options, player_name, paramtext) + local we_c = worldeditadditions_core if options.require_pos > 0 and not worldedit.pos1[player_name] then worldedit.player_notify(player_name, "Error: pos1 must be selected to use this command.") return false diff --git a/worldeditadditions_core/core/safe_region.lua b/worldeditadditions_core/core/safe_region.lua index 0facbf4..a311889 100644 --- a/worldeditadditions_core/core/safe_region.lua +++ b/worldeditadditions_core/core/safe_region.lua @@ -8,8 +8,8 @@ local worldedit_command_y, worldedit_command_n if minetest.global_exists("worldedit") then - worldedit_command_y = minetest.registered_commands["/y"].func - worldedit_command_n = minetest.registered_commands["/n"].func + worldedit_command_y = minetest.chatcommands["/y"].func + worldedit_command_n = minetest.chatcommands["/n"].func end --- A table that holds at most 1 pending function call per player. diff --git a/worldeditadditions_core/init.lua b/worldeditadditions_core/init.lua index 9ed82b3..19938c2 100644 --- a/worldeditadditions_core/init.lua +++ b/worldeditadditions_core/init.lua @@ -5,8 +5,8 @@ -- @license Mozilla Public License, 2.0 -- @author Starbeamrainbowlabs and VorTechnix -local temp = true -if temp then return end +-- local temp = true +-- if temp then return end -- This mod isn't finished yet, so it will not be executed for now. diff --git a/worldeditadditions_core/mod.conf b/worldeditadditions_core/mod.conf index fc9db3e..38d5e0d 100644 --- a/worldeditadditions_core/mod.conf +++ b/worldeditadditions_core/mod.conf @@ -1,3 +1,3 @@ name = worldeditadditions_core description = worldeditadditions: core components -optional_depends = worldedit +optional_depends = worldedit, worldedit_commands, worldedit_shortcommands From b8161337167de3c8ac9594723a0e4cfe6cfc00c6 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Thu, 19 May 2022 02:31:01 +0100 Subject: [PATCH 19/25] core: implement fetch_command_def This rovides an abstraction to fetch a worldedit command's definition, regardless of where it was registered. We would normally expect all commands to be registered in wea_c.registered_commands, but before we only do a one-off pass to import commands from worldedit should a new mod we aren't aware of register a command with worldedit and get loaded after us, we won't detect it - hencee the need for this function. --- worldeditadditions/mod.conf | 2 +- .../commands/meta/airapply.lua | 4 ++-- .../commands/meta/ellipsoidapply.lua | 3 ++- .../commands/meta/noiseapply2d.lua | 3 ++- .../commands/meta/subdivide.lua | 9 +++++---- worldeditadditions_commands/doc/init.lua | 2 +- worldeditadditions_commands/mod.conf | 2 +- .../core/fetch_command_def.lua | 20 +++++++++++++++++++ .../core/register_command.lua | 5 ++--- worldeditadditions_core/core/run_command.lua | 13 ++++++------ worldeditadditions_core/init.lua | 9 +++++---- 11 files changed, 47 insertions(+), 25 deletions(-) create mode 100644 worldeditadditions_core/core/fetch_command_def.lua diff --git a/worldeditadditions/mod.conf b/worldeditadditions/mod.conf index ea02050..2d0ac3a 100644 --- a/worldeditadditions/mod.conf +++ b/worldeditadditions/mod.conf @@ -1,4 +1,4 @@ name = worldeditadditions description = Extra tools and commands to extend WorldEdit for Minetest depends = worldedit -optional_depends = bonemeal, cool_trees, default, moretrees, ethereal +optional_depends = worldeditadditions_core, bonemeal, cool_trees, default, moretrees, ethereal diff --git a/worldeditadditions_commands/commands/meta/airapply.lua b/worldeditadditions_commands/commands/meta/airapply.lua index bd0f548..7989f44 100644 --- a/worldeditadditions_commands/commands/meta/airapply.lua +++ b/worldeditadditions_commands/commands/meta/airapply.lua @@ -3,7 +3,7 @@ -- ███████ ██ ██████ ███████ ██████ ██████ ██ ████ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ███████ ██ - +local wea_c = worldeditadditions_core worldedit.register_command("airapply", { params = " ", @@ -20,7 +20,7 @@ worldedit.register_command("airapply", { end -- Note that we search the worldedit commands here, not the minetest ones - local cmd_we = worldedit.registered_commands[cmd_name] + local cmd_we = wea_c.fetch_command_def(cmd_name) if cmd_we == nil then return false, "Error: "..cmd_name.." isn't a valid command." end diff --git a/worldeditadditions_commands/commands/meta/ellipsoidapply.lua b/worldeditadditions_commands/commands/meta/ellipsoidapply.lua index 83f00a1..0489407 100644 --- a/worldeditadditions_commands/commands/meta/ellipsoidapply.lua +++ b/worldeditadditions_commands/commands/meta/ellipsoidapply.lua @@ -3,6 +3,7 @@ -- █████ ██ ██ ██ ██████ ███████ █████ ███████ ██████ ██████ ██ ████ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ███████ ███████ ███████ ██ ██ ███████ ███████ ██ ██ ██ ██ ███████ ██ +local wea_c = worldeditadditions_core worldedit.register_command("ellipsoidapply", { params = " ", @@ -21,7 +22,7 @@ worldedit.register_command("ellipsoidapply", { -- print("cmd_name", cmd_name, "args_text", args_text) -- Note that we search the worldedit commands here, not the minetest ones - local cmd_we = worldedit.registered_commands[cmd_name] + local cmd_we = wea_c.fetch_command_def(cmd_name) if cmd_we == nil then return false, "Error: "..cmd_name.." isn't a valid command." end diff --git a/worldeditadditions_commands/commands/meta/noiseapply2d.lua b/worldeditadditions_commands/commands/meta/noiseapply2d.lua index 14d127c..c7edb48 100644 --- a/worldeditadditions_commands/commands/meta/noiseapply2d.lua +++ b/worldeditadditions_commands/commands/meta/noiseapply2d.lua @@ -3,6 +3,7 @@ -- ██ ██ ██ ██ ██ ██ ███████ █████ ███████ ██████ ██████ ██ ████ █████ ██ ██ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ████ ██████ ██ ███████ ███████ ██ ██ ██ ██ ███████ ██ ███████ ██████ +local wea_c = worldeditadditions_core worldedit.register_command("noiseapply2d", { @@ -19,7 +20,7 @@ worldedit.register_command("noiseapply2d", { end -- Note that we search the worldedit commands here, not the minetest ones - local cmd_we = worldedit.registered_commands[cmd_name] + local cmd_we = wea_c.fetch_command_def(cmd_name) if cmd_we == nil then return false, "Error: "..cmd_name.." isn't a valid command." end diff --git a/worldeditadditions_commands/commands/meta/subdivide.lua b/worldeditadditions_commands/commands/meta/subdivide.lua index 5acf272..c291146 100644 --- a/worldeditadditions_commands/commands/meta/subdivide.lua +++ b/worldeditadditions_commands/commands/meta/subdivide.lua @@ -1,11 +1,12 @@ local wea = worldeditadditions +local wea_c = worldeditadditions_core -- Test command: -- //multi //fp set1 1330 60 5455 //fp set2 1355 35 5430 //subdivide 10 10 10 fixlight //y local function will_trigger_saferegion(name, cmd_name, args) - if not worldedit.registered_commands[cmd_name] then return nil, "Error: That worldedit command could not be found (perhaps it hasn't been upgraded to worldedit.register_command() yet?)" end - local def = worldedit.registered_commands[cmd_name] + local def = wea_c.fetch_command_def(cmd_name) + if not def then return nil, "Error: That worldedit command could not be found (perhaps it hasn't been upgraded to worldedit.register_command() yet?)" end if not def.parse then return nil, "Error: No parse method found (this is a bug)." end local parsed = {def.parse(args)} @@ -57,7 +58,7 @@ worldedit.register_command("subdivide", { local cmd_name = parts[4] - if not worldedit.registered_commands[cmd_name] then + if not wea_c.fetch_command_def(cmd_name) then return false, "Error: The worldedit command '"..parts[4].."' does not exist (try /help)." end @@ -73,7 +74,7 @@ worldedit.register_command("subdivide", { local pos1, pos2 = worldedit.sort_pos(worldedit.pos1[name], worldedit.pos2[name]) local volume = worldedit.volume(pos1, pos2) - local cmd = worldedit.registered_commands[cmd_name] + local cmd = wea_c.fetch_command_def(cmd_name) -- Note that we don't need to check for //multi privileges, as it does it at runtime if not minetest.check_player_privs(name, cmd.privs) then return false, "Error: Your privileges are unsufficient to run '"..cmd_name.."'." diff --git a/worldeditadditions_commands/doc/init.lua b/worldeditadditions_commands/doc/init.lua index 9ab9a55..f6b9f0d 100644 --- a/worldeditadditions_commands/doc/init.lua +++ b/worldeditadditions_commands/doc/init.lua @@ -11,7 +11,7 @@ -- The strategy here is not to have duplicate content, but to pull data from -- existing sources. -- Long-form article descriptions: Chat-Command-Reference.md --- Short descriptions: Undecided, but maybe worldedit.registered_commands +-- Short descriptions: Undecided, but maybe from the registered command definition? worldeditadditions.doc = {} diff --git a/worldeditadditions_commands/mod.conf b/worldeditadditions_commands/mod.conf index 3b12d2d..c21809d 100644 --- a/worldeditadditions_commands/mod.conf +++ b/worldeditadditions_commands/mod.conf @@ -1,4 +1,4 @@ name = worldeditadditions_commands description = worldeditadditions: chat command interfaces -depends = worldeditadditions, worldedit_commands, worldedit_shortcommands, worldedit +depends = worldeditadditions, worldeditadditions_core, worldedit_commands, worldedit_shortcommands, worldedit optional_depends = worldeditdebug, bonemeal diff --git a/worldeditadditions_core/core/fetch_command_def.lua b/worldeditadditions_core/core/fetch_command_def.lua new file mode 100644 index 0000000..d77da5b --- /dev/null +++ b/worldeditadditions_core/core/fetch_command_def.lua @@ -0,0 +1,20 @@ + + +--- Fetches the definition of a WorldEditAdditions or WorldEdit command +-- Does not support fetching generic Minetest commands - check +-- minetest.chatcommands for this. +-- @param cmdname string The name of the command to fetch the definition for. +local function fetch_command_def(cmdname) + local wea_c = worldeditadditions_core + + if wea_c.registered_commands[cmdname] then + return wea_c.registered_commands[cmdname] + end + if minetest.global_exists("worldedit") and worldedit.registered_commands and worldedit.registered_commands[cmdname] then + return worldedit.registered_commands[cmdname] + end + + return nil +end + +return fetch_command_def diff --git a/worldeditadditions_core/core/register_command.lua b/worldeditadditions_core/core/register_command.lua index e7525ae..e481848 100644 --- a/worldeditadditions_core/core/register_command.lua +++ b/worldeditadditions_core/core/register_command.lua @@ -5,15 +5,14 @@ -- ██ ██ ███████ ██████ ██ ███████ ██ ███████ ██ ██ -- WorldEditAdditions chat command registration -local modpath = minetest.get_modpath("worldeditadditions_core") -local run_command = dofile(modpath.."/core/run_command.lua") +local wea_c = worldeditadditions_core +local run_command = dofile(wea_c.modpath.."/core/run_command.lua") local function log_error(cmdname, error_message) minetest.log("error", "register_command("..cmdname..") error: "..error_message) end local function register_command(cmdname, options) - local we_c = worldeditadditions_core --- -- 1: Validation diff --git a/worldeditadditions_core/core/run_command.lua b/worldeditadditions_core/core/run_command.lua index 71dd4bc..f6d48e5 100644 --- a/worldeditadditions_core/core/run_command.lua +++ b/worldeditadditions_core/core/run_command.lua @@ -1,7 +1,7 @@ -- WARNING: safe_region MUST NOT be imported more than once, as it defines chat commands. If you want to import it again elsewhere, check first that multiple dofile() calls don't execute a file more than once. -local modpath = minetest.get_modpath("worldeditadditions_core") -local safe_region = dofile(modpath.."/core/safe_region.lua") -local human_size = dofile(modpath.."/core/lib/human_size.lua") +local wea_c = worldeditadditions_core +local safe_region = dofile(wea_c.modpath.."/core/safe_region.lua") +local human_size = dofile(wea_c.modpath.."/core/lib/human_size.lua") -- TODO: Reimplement worldedit.player_notify(player_name, msg_text) @@ -14,7 +14,6 @@ local function run_command_stage2(player_name, func, parse_result) end local function run_command(cmdname, options, player_name, paramtext) - local we_c = worldeditadditions_core if options.require_pos > 0 and not worldedit.pos1[player_name] then worldedit.player_notify(player_name, "Error: pos1 must be selected to use this command.") return false @@ -34,9 +33,9 @@ local function run_command(cmdname, options, player_name, paramtext) if options.nodes_needed then local potential_changes = options.nodes_needed(player_name, unpack(parse_result)) - local limit = we_c.safe_region_limit_default - if we_c.safe_region_limits[player_name] then - limit = we_c.safe_region_limits[player_name] + local limit = wea_c.safe_region_limit_default + if wea_c.safe_region_limits[player_name] then + limit = wea_c.safe_region_limits[player_name] end if potential_changes > limit then diff --git a/worldeditadditions_core/init.lua b/worldeditadditions_core/init.lua index 19938c2..9a77be7 100644 --- a/worldeditadditions_core/init.lua +++ b/worldeditadditions_core/init.lua @@ -20,15 +20,16 @@ worldeditadditions_core = { safe_region_limits = {}, -- The default limit for new players on the number of potential nodes changed before safe_region kicks in. safe_region_limit_default = 100000, - register_command = dofile(modpath.."/core/register_command.lua") } +local wea_c = worldeditadditions_core +wea_c.register_command = dofile(modpath.."/core/register_command.lua") +wea_c.fetch_command_def = dofile(modpath.."/core/fetch_command_def.lua") -local we_c = worldeditadditions_core -- Initialise WorldEdit stuff if the WorldEdit mod is not present if minetest.global_exists("worldedit") then - dofile(we_c.modpath.."/core/integrations/worldedit.lua") + dofile(wea_c.modpath.."/core/integrations/worldedit.lua") else - dofile(we_c.modpath.."/core/integrations/noworldedit.lua") + dofile(wea_c.modpath.."/core/integrations/noworldedit.lua") end From 95c0e96da99bfffd38f0a940172c11191f488ffd Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Thu, 19 May 2022 02:32:17 +0100 Subject: [PATCH 20/25] core: fix luacheck errors --- worldeditadditions_core/core/register_command.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/worldeditadditions_core/core/register_command.lua b/worldeditadditions_core/core/register_command.lua index e481848..7e2f3b2 100644 --- a/worldeditadditions_core/core/register_command.lua +++ b/worldeditadditions_core/core/register_command.lua @@ -33,7 +33,7 @@ local function register_command(cmdname, options) log_error(cmdname, "The func option is not a function.") return false end - if we_c.registered_commands[cmdname] and options.override ~= true then + if wea_c.registered_commands[cmdname] and options.override ~= true then log_error(cmdname, "A WorldEditAdditions command with that name is registered, but the option override is not set to true.") return false end @@ -57,7 +57,7 @@ local function register_command(cmdname, options) run_command(cmdname, options, player_name, paramtext) end }) - we_c.registered_commands[cmdname] = options + wea_c.registered_commands[cmdname] = options end return register_command From c53fb32d2b182f0e56099a29dfce1e9dd248c875 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Thu, 19 May 2022 02:40:05 +0100 Subject: [PATCH 21/25] core: fix register_command and run_command --- worldeditadditions_core/core/register_command.lua | 4 ++-- worldeditadditions_core/core/run_command.lua | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/worldeditadditions_core/core/register_command.lua b/worldeditadditions_core/core/register_command.lua index 7e2f3b2..0e6eb8c 100644 --- a/worldeditadditions_core/core/register_command.lua +++ b/worldeditadditions_core/core/register_command.lua @@ -25,11 +25,11 @@ local function register_command(cmdname, options) log_error(cmdname, "The description option is not a string.") return false end - if type(options.parse) ~= "string" then + if type(options.parse) ~= "function" then log_error(cmdname, "The parse option is not a function.") return false end - if type(options.func) ~= "string" then + if type(options.func) ~= "function" then log_error(cmdname, "The func option is not a function.") return false end diff --git a/worldeditadditions_core/core/run_command.lua b/worldeditadditions_core/core/run_command.lua index f6d48e5..6828215 100644 --- a/worldeditadditions_core/core/run_command.lua +++ b/worldeditadditions_core/core/run_command.lua @@ -43,6 +43,8 @@ local function run_command(cmdname, options, player_name, paramtext) safe_region(player_name, cmdname, function() run_command_stage2(player_name, options.func, parse_result) end) + else + run_command_stage2(player_name, options.func, parse_result) end else run_command_stage2(player_name, options.func, parse_result) From 3bcca82b43e23678b8134e5741d41d1e791918b4 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Thu, 19 May 2022 02:43:19 +0100 Subject: [PATCH 22/25] //maze, //maze3d: registere with our new WEA core rather than WorldEdit --- worldeditadditions_commands/commands/maze.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/worldeditadditions_commands/commands/maze.lua b/worldeditadditions_commands/commands/maze.lua index 3003c1a..c543474 100644 --- a/worldeditadditions_commands/commands/maze.lua +++ b/worldeditadditions_commands/commands/maze.lua @@ -1,5 +1,5 @@ local wea = worldeditadditions -local we_c = worldeditadditions_commands +local wea_c = worldeditadditions_core local Vector3 = worldeditadditions.Vector3 local function parse_params_maze(params_text, is_3d) @@ -61,7 +61,7 @@ end -- ██ ██ ██ ██ ██ ███ ██ -- ██ ██ ██ ██ ███████ ███████ -worldedit.register_command("maze", { +wea_c.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 }, @@ -100,7 +100,7 @@ worldedit.register_command("maze", { -- ██ ██ ██ ██ ██ ███ ██ ██ ██ ██ -- ██ ██ ██ ██ ███████ ███████ ██████ ██████ -worldedit.register_command("maze3d", { +wea_c.register_command("maze3d", { params = " [ [ [ []]]]", 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).", privs = { worldedit = true }, From 8de49ac0aff93146ad8a25c40dcc7063e4ff07d6 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Thu, 19 May 2022 22:10:09 +0100 Subject: [PATCH 23/25] register commands with worldeditadditions, not worldedit --- CONTRIBUTING.md | 2 +- worldeditadditions_commands/commands/bonemeal.lua | 2 +- worldeditadditions_commands/commands/convolve.lua | 2 +- worldeditadditions_commands/commands/copy.lua | 2 +- worldeditadditions_commands/commands/count.lua | 2 +- worldeditadditions_commands/commands/dome.lua | 2 +- worldeditadditions_commands/commands/ellipsoid.lua | 4 ++-- worldeditadditions_commands/commands/ellipsoid2.lua | 2 +- worldeditadditions_commands/commands/erode.lua | 2 +- worldeditadditions_commands/commands/extra/basename.lua | 2 +- worldeditadditions_commands/commands/fillcaves.lua | 2 +- worldeditadditions_commands/commands/floodfill.lua | 2 +- worldeditadditions_commands/commands/forest.lua | 2 +- worldeditadditions_commands/commands/hollow.lua | 2 +- worldeditadditions_commands/commands/layers.lua | 2 +- worldeditadditions_commands/commands/line.lua | 2 +- worldeditadditions_commands/commands/measure/mface.lua | 2 +- worldeditadditions_commands/commands/measure/midpos.lua | 2 +- worldeditadditions_commands/commands/measure/msize.lua | 2 +- worldeditadditions_commands/commands/measure/mtrig.lua | 2 +- worldeditadditions_commands/commands/meta/airapply.lua | 2 +- worldeditadditions_commands/commands/meta/ellipsoidapply.lua | 2 +- worldeditadditions_commands/commands/meta/for.lua | 2 +- worldeditadditions_commands/commands/meta/macro.lua | 2 +- worldeditadditions_commands/commands/meta/noiseapply2d.lua | 2 +- worldeditadditions_commands/commands/meta/subdivide.lua | 2 +- worldeditadditions_commands/commands/metaball.lua | 2 +- worldeditadditions_commands/commands/move.lua | 2 +- worldeditadditions_commands/commands/noise2d.lua | 2 +- worldeditadditions_commands/commands/overlay.lua | 2 +- worldeditadditions_commands/commands/replacemix.lua | 2 +- worldeditadditions_commands/commands/scale.lua | 2 +- worldeditadditions_commands/commands/sculpt.lua | 2 +- worldeditadditions_commands/commands/selectors/scentre.lua | 2 +- worldeditadditions_commands/commands/selectors/scloud.lua | 2 +- worldeditadditions_commands/commands/selectors/scol.lua | 2 +- worldeditadditions_commands/commands/selectors/scube.lua | 2 +- worldeditadditions_commands/commands/selectors/sfactor.lua | 2 +- worldeditadditions_commands/commands/selectors/smake.lua | 2 +- worldeditadditions_commands/commands/selectors/spop.lua | 2 +- worldeditadditions_commands/commands/selectors/spush.lua | 2 +- worldeditadditions_commands/commands/selectors/srect.lua | 2 +- worldeditadditions_commands/commands/selectors/srel.lua | 2 +- worldeditadditions_commands/commands/selectors/sshift.lua | 2 +- worldeditadditions_commands/commands/selectors/sstack.lua | 2 +- worldeditadditions_commands/commands/spiral2.lua | 2 +- worldeditadditions_commands/commands/torus.lua | 4 ++-- worldeditadditions_commands/commands/walls.lua | 2 +- worldeditadditions_commands/commands/wireframe/wbox.lua | 2 +- worldeditadditions_commands/commands/wireframe/wcompass.lua | 2 +- worldeditadditions_commands/commands/wireframe/wcorner.lua | 2 +- 51 files changed, 53 insertions(+), 53 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1e6e84e..518cd91 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -37,7 +37,7 @@ When actually implementing stuff, here are a few guidelines that I recommend to -- ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ████ ██ ██ ██ ██ ███████ local wea = worldeditadditions -worldedit.register_command("{name}", { +worldeditadditions_core.register_command("{name}", { params = " [ ...] | [ []]", description = "A **brief** description of what this command does", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/bonemeal.lua b/worldeditadditions_commands/commands/bonemeal.lua index e4b8f67..daa170b 100644 --- a/worldeditadditions_commands/commands/bonemeal.lua +++ b/worldeditadditions_commands/commands/bonemeal.lua @@ -6,7 +6,7 @@ local wea = worldeditadditions -- ██████ ██ ██ ██ ██ ██ █████ ██ ████ ██ █████ ███████ ██ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██████ ██████ ██ ████ ███████ ██ ██ ███████ ██ ██ ███████ -worldedit.register_command("bonemeal", { +worldeditadditions_core.register_command("bonemeal", { params = "[ [ [ [ ...]]]]", description = "Bonemeals everything that's bonemeal-able that has an air node directly above it. Optionally takes a strength value to use (default: 1, maximum: 4), and a chance to actually bonemeal an eligible node (positive integer; nodes have a 1-in- chance to be bonemealed; higher values mean a lower chance; default: 1 - 100% chance).", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/convolve.lua b/worldeditadditions_commands/commands/convolve.lua index 878e7d8..21de435 100644 --- a/worldeditadditions_commands/commands/convolve.lua +++ b/worldeditadditions_commands/commands/convolve.lua @@ -6,7 +6,7 @@ local Vector3 = wea.Vector3 -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ █████ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██████ ██████ ██ ████ ████ ██████ ███████ ████ ███████ -worldedit.register_command("convolve", { +worldeditadditions_core.register_command("convolve", { params = " [[,]] []", description = "Advanced version of //smooth from we_env. Convolves over the defined region with the given kernel. Possible kernels: box, pascal, gaussian. The width & height (if specified) must be odd integers. If the height is not specified, it defaults to the width. gaussian should give the smoothest result, but the width & height must be identical. The sigma value is only applicable to gaussian kernels, and can be thought of as the 'smoothness' to apply.", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/copy.lua b/worldeditadditions_commands/commands/copy.lua index bbcc554..801256f 100644 --- a/worldeditadditions_commands/commands/copy.lua +++ b/worldeditadditions_commands/commands/copy.lua @@ -24,7 +24,7 @@ end -- ██ ██ ██ ██████ ████ -- ██ ██ ██ ██ ██ -- ██████ ██████ ██ ██ -worldedit.register_command("copy+", { -- TODO: Make this an override +worldeditadditions_core.register_command("copy+", { -- TODO: Make this an override params = " [ [...]]", description = "Copies the defined region to another location - potentially across multiple axes at once.", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/count.lua b/worldeditadditions_commands/commands/count.lua index 3a65d29..a418dbd 100644 --- a/worldeditadditions_commands/commands/count.lua +++ b/worldeditadditions_commands/commands/count.lua @@ -3,7 +3,7 @@ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██████ ██████ ██████ ██ ████ ██ -worldedit.register_command("count", { +worldeditadditions_core.register_command("count", { params = "", description = "Counts all the nodes in the defined region.", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/dome.lua b/worldeditadditions_commands/commands/dome.lua index 499a6e3..054d2dd 100644 --- a/worldeditadditions_commands/commands/dome.lua +++ b/worldeditadditions_commands/commands/dome.lua @@ -25,7 +25,7 @@ end -- ██ ██ ██ ██ ██ ████ ██ █████ -- ██ ██ ██ ██ ██ ██ ██ ██ -- ██████ ██████ ██ ██ ███████ -worldedit.register_command("dome+", { -- TODO: Make this an override +worldeditadditions_core.register_command("dome+", { -- TODO: Make this an override params = " [ ...] [h[ollow]]", description = "Creates a dome shape with a specified radius of the defined node, optionally specifying the direction it should be pointing in (defaults to the positive y direction).", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/ellipsoid.lua b/worldeditadditions_commands/commands/ellipsoid.lua index efa4ebf..2a71e6a 100644 --- a/worldeditadditions_commands/commands/ellipsoid.lua +++ b/worldeditadditions_commands/commands/ellipsoid.lua @@ -30,7 +30,7 @@ local function parse_params_ellipsoid(params_text) return true, replace_node, radius, hollow end -worldedit.register_command("ellipsoid", { +worldeditadditions_core.register_command("ellipsoid", { params = " [h[ollow]]", description = "Creates a 3D ellipsoid with a radius of (rx, ry, rz) at pos1, filled with .", privs = { worldedit = true }, @@ -53,7 +53,7 @@ worldedit.register_command("ellipsoid", { }) -- TODO: This duplicates a lot of code. Perhaps we can trim it down a bit? -worldedit.register_command("hollowellipsoid", { +worldeditadditions_core.register_command("hollowellipsoid", { params = " ", description = "Creates a 3D hollow ellipsoid with a radius of (rx, ry, rz) at pos1, made out of .", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/ellipsoid2.lua b/worldeditadditions_commands/commands/ellipsoid2.lua index 541532a..257ed5b 100644 --- a/worldeditadditions_commands/commands/ellipsoid2.lua +++ b/worldeditadditions_commands/commands/ellipsoid2.lua @@ -5,7 +5,7 @@ -- ███████ ███████ ███████ ██ ██ ███████ ██████ ██ ██████ local wea = worldeditadditions -worldedit.register_command("ellipsoid2", { +worldeditadditions_core.register_command("ellipsoid2", { params = "[ [h[ollow]]]", description = "Creates am optionally hollow 3D ellipsoid that fills the defined region, filled with .", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/erode.lua b/worldeditadditions_commands/commands/erode.lua index d41df3e..5dc755b 100644 --- a/worldeditadditions_commands/commands/erode.lua +++ b/worldeditadditions_commands/commands/erode.lua @@ -3,7 +3,7 @@ -- █████ ██████ ██ ██ ██ ██ █████ -- ██ ██ ██ ██ ██ ██ ██ ██ -- ███████ ██ ██ ██████ ██████ ███████ -worldedit.register_command("erode", { +worldeditadditions_core.register_command("erode", { params = "[ [ []] [ []] ...]", 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.", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/extra/basename.lua b/worldeditadditions_commands/commands/extra/basename.lua index 6d247bb..eac8497 100644 --- a/worldeditadditions_commands/commands/extra/basename.lua +++ b/worldeditadditions_commands/commands/extra/basename.lua @@ -3,7 +3,7 @@ -- ██████ ███████ ███████ █████ ██ ██ ██ ███████ ██ ████ ██ █████ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██████ ██ ██ ███████ ███████ ██ ████ ██ ██ ██ ██ ███████ -worldedit.register_command("basename", { +worldeditadditions_core.register_command("basename", { params = "", description = "Returns the base name of nodes that use a given alias.", privs = {worldedit = true}, diff --git a/worldeditadditions_commands/commands/fillcaves.lua b/worldeditadditions_commands/commands/fillcaves.lua index 1b1cbe6..743221f 100644 --- a/worldeditadditions_commands/commands/fillcaves.lua +++ b/worldeditadditions_commands/commands/fillcaves.lua @@ -3,7 +3,7 @@ -- █████ ██ ██ ██ ██ ███████ ██ ██ █████ ███████ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ███████ ███████ ██████ ██ ██ ████ ███████ ███████ -worldedit.register_command("fillcaves", { +worldeditadditions_core.register_command("fillcaves", { params = "[]", description = "Fills in all airlike nodes beneath the first non-airlike node detected in each column.", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/floodfill.lua b/worldeditadditions_commands/commands/floodfill.lua index e829ead..08ea547 100644 --- a/worldeditadditions_commands/commands/floodfill.lua +++ b/worldeditadditions_commands/commands/floodfill.lua @@ -3,7 +3,7 @@ -- █████ ██ ██ ██ ██ ██ ██ ██ █████ ██ ██ ██ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ███████ ██████ ██████ ██████ ██ ██ ███████ ███████ -worldedit.register_command("floodfill", { +worldeditadditions_core.register_command("floodfill", { params = "[ []]", description = "Floods all connected nodes of the same type starting at pos1 with (which defaults to `water_source`), in a sphere with a radius of (which defaults to 20).", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/forest.lua b/worldeditadditions_commands/commands/forest.lua index 5240ae8..8b944c9 100644 --- a/worldeditadditions_commands/commands/forest.lua +++ b/worldeditadditions_commands/commands/forest.lua @@ -6,7 +6,7 @@ local wea = worldeditadditions -- ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ██████ ██ ██ ███████ ███████ ██ -worldedit.register_command("forest", { +worldeditadditions_core.register_command("forest", { params = "[] [] [] [ []] ...", description = "Plants and grows trees in the defined region according to the given list of sapling names and chances and density factor. The density controls the relative density of the resulting forest, and defaults to 1 (floating-point numbers allowed). Higher chance numbers result in a lower relative chance with respect to other saplings in the list. Saplings that fail to grow are subsequently removed (this will affect pre-existing saplings too).", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/hollow.lua b/worldeditadditions_commands/commands/hollow.lua index 40adc05..ea6ef69 100644 --- a/worldeditadditions_commands/commands/hollow.lua +++ b/worldeditadditions_commands/commands/hollow.lua @@ -3,7 +3,7 @@ -- ███████ ██ ██ ██ ██ ██ ██ ██ █ ██ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ███ ██ -- ██ ██ ██████ ███████ ███████ ██████ ███ ███ -worldedit.register_command("hollow", { +worldeditadditions_core.register_command("hollow", { params = "[]", description = "Replaces nodes inside the defined region with air, but leaving a given number of nodes near the outermost edges alone. In other words, it makes the defined region hollow leaving walls of a given thickness (default: 1)", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/layers.lua b/worldeditadditions_commands/commands/layers.lua index 4c84075..dfcfa54 100644 --- a/worldeditadditions_commands/commands/layers.lua +++ b/worldeditadditions_commands/commands/layers.lua @@ -26,7 +26,7 @@ end -- ██ ██ ██ ██ █████ ██████ ██ ███████ ████ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██████ ████ ███████ ██ ██ ███████ ██ ██ ██ -worldedit.register_command("layers", { +worldeditadditions_core.register_command("layers", { params = "[] [ []] [ []] ...", description = "Replaces the topmost non-airlike nodes with layers of the given nodes from top to bottom. Like WorldEdit for MC's //naturalize command. Optionally takes a maximum or minimum and maximum slope value. If a column's slope value falls outside the defined range, then it's skipped. Default: dirt_with_grass dirt 3", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/line.lua b/worldeditadditions_commands/commands/line.lua index 3bb6d00..0c75cf0 100644 --- a/worldeditadditions_commands/commands/line.lua +++ b/worldeditadditions_commands/commands/line.lua @@ -3,7 +3,7 @@ -- ██ ██ ██ ██ ██ █████ -- ██ ██ ██ ██ ██ ██ -- ███████ ██ ██ ████ ███████ -worldedit.register_command("line", { +worldeditadditions_core.register_command("line", { params = "[ []]", description = "Draws a line of a given radius (default: 1) from pos1 to pos2 in the given node (default: dirt).", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/measure/mface.lua b/worldeditadditions_commands/commands/measure/mface.lua index 53249e6..983a402 100644 --- a/worldeditadditions_commands/commands/measure/mface.lua +++ b/worldeditadditions_commands/commands/measure/mface.lua @@ -4,7 +4,7 @@ -- ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ██ ██ ██ ██████ ███████ local wea = worldeditadditions -worldedit.register_command("mface", { +worldeditadditions_core.register_command("mface", { params = "", description = "Return player facing axis.", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/measure/midpos.lua b/worldeditadditions_commands/commands/measure/midpos.lua index a2fee5f..705f550 100644 --- a/worldeditadditions_commands/commands/measure/midpos.lua +++ b/worldeditadditions_commands/commands/measure/midpos.lua @@ -4,7 +4,7 @@ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ██ ██████ ██ ██████ ███████ local wea = worldeditadditions -worldedit.register_command("midpos", { +worldeditadditions_core.register_command("midpos", { params = "", description = "Return the mid point of current selection.", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/measure/msize.lua b/worldeditadditions_commands/commands/measure/msize.lua index 648f02f..df651f5 100644 --- a/worldeditadditions_commands/commands/measure/msize.lua +++ b/worldeditadditions_commands/commands/measure/msize.lua @@ -4,7 +4,7 @@ -- ██ ██ ██ ██ ██ ███ ██ -- ██ ██ ███████ ██ ███████ ███████ local wea = worldeditadditions -worldedit.register_command("msize", { +worldeditadditions_core.register_command("msize", { params = "", description = "Return the length of each axis of current selection.", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/measure/mtrig.lua b/worldeditadditions_commands/commands/measure/mtrig.lua index 90a28c4..a13a669 100644 --- a/worldeditadditions_commands/commands/measure/mtrig.lua +++ b/worldeditadditions_commands/commands/measure/mtrig.lua @@ -5,7 +5,7 @@ -- ██ ██ ██ ██ ██ ██ ██████ local wea = worldeditadditions local v3 = worldeditadditions.Vector3 -worldedit.register_command("mtrig", { +worldeditadditions_core.register_command("mtrig", { params = "", description = "Return the length of and angles of an imginary line between pos1 and pos2 in the selection.", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/meta/airapply.lua b/worldeditadditions_commands/commands/meta/airapply.lua index 7989f44..41585bf 100644 --- a/worldeditadditions_commands/commands/meta/airapply.lua +++ b/worldeditadditions_commands/commands/meta/airapply.lua @@ -5,7 +5,7 @@ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ███████ ██ local wea_c = worldeditadditions_core -worldedit.register_command("airapply", { +worldeditadditions_core.register_command("airapply", { params = " ", description = "Executes the given command (automatically prepending '//'), but only on non-air nodes within the defined region.", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/meta/ellipsoidapply.lua b/worldeditadditions_commands/commands/meta/ellipsoidapply.lua index 0489407..4923d5f 100644 --- a/worldeditadditions_commands/commands/meta/ellipsoidapply.lua +++ b/worldeditadditions_commands/commands/meta/ellipsoidapply.lua @@ -5,7 +5,7 @@ -- ███████ ███████ ███████ ██ ██ ███████ ███████ ██ ██ ██ ██ ███████ ██ local wea_c = worldeditadditions_core -worldedit.register_command("ellipsoidapply", { +worldeditadditions_core.register_command("ellipsoidapply", { params = " ", description = "Executes the given command (automatically prepending '//'), clipping the result with an ellipse given by the defined region.", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/meta/for.lua b/worldeditadditions_commands/commands/meta/for.lua index 7db3029..5dff676 100644 --- a/worldeditadditions_commands/commands/meta/for.lua +++ b/worldeditadditions_commands/commands/meta/for.lua @@ -45,7 +45,7 @@ local function step(params) end end -worldedit.register_command("for", { +worldeditadditions_core.register_command("for", { params = " ... do // %% ", description = "Executes a chat command for each value before \" do \" replacing any instances of \"%%\" with those values. The forward slashes at the beginning of the chat command must be the same as if you were executing it normally.", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/meta/macro.lua b/worldeditadditions_commands/commands/meta/macro.lua index 9bd8141..92e9eaa 100644 --- a/worldeditadditions_commands/commands/meta/macro.lua +++ b/worldeditadditions_commands/commands/meta/macro.lua @@ -45,7 +45,7 @@ local function step(params) end end -worldedit.register_command("macro", { +worldeditadditions_core.register_command("macro", { params = " []", description = "Load commands from \"(world folder)/macros/[.weamac | .wmac]\" with position 1 of the current WorldEdit region as the origin.", privs = {worldedit=true}, diff --git a/worldeditadditions_commands/commands/meta/noiseapply2d.lua b/worldeditadditions_commands/commands/meta/noiseapply2d.lua index c7edb48..bd31ada 100644 --- a/worldeditadditions_commands/commands/meta/noiseapply2d.lua +++ b/worldeditadditions_commands/commands/meta/noiseapply2d.lua @@ -6,7 +6,7 @@ local wea_c = worldeditadditions_core -worldedit.register_command("noiseapply2d", { +worldeditadditions_core.register_command("noiseapply2d", { params = " ", description = "Executes the given command (automatically prepending '//'), but uses a 2d noise function with both a threshold value (a number between 0 and 1) and a scale value (number, 1 = normal scale, for small areas 10+ is recommended) to filter where in the defined region it's applied.", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/meta/subdivide.lua b/worldeditadditions_commands/commands/meta/subdivide.lua index c291146..724a8da 100644 --- a/worldeditadditions_commands/commands/meta/subdivide.lua +++ b/worldeditadditions_commands/commands/meta/subdivide.lua @@ -30,7 +30,7 @@ local function emerge_stats_tostring(tbl_emerge) return table.concat(result, ", ") end -worldedit.register_command("subdivide", { +worldeditadditions_core.register_command("subdivide", { params = " ", description = "Subdivides the given worldedit area into chunks and runs a worldedit command multiple times to cover the defined region. Note that the given command must NOT be prepended with any forward slashes - just like //cubeapply.", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/metaball.lua b/worldeditadditions_commands/commands/metaball.lua index 6e00d04..312617e 100644 --- a/worldeditadditions_commands/commands/metaball.lua +++ b/worldeditadditions_commands/commands/metaball.lua @@ -6,7 +6,7 @@ local Vector3 = wea.Vector3 -- ██ ██ ██ ██ ██ ████ ██ █████ -- ██ ██ ██ ██ ██ ██ ██ ██ -- ██████ ██████ ██ ██ ███████ -worldedit.register_command("metaball", { +worldeditadditions_core.register_command("metaball", { params = "add | remove | render [] | list | clear | volume", description = "Defines and creates metaballs. After using the add subcommand to define 1 or more metaballs (uses pos1), the render subcommand can then be used to create the metaballs as nodes.", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/move.lua b/worldeditadditions_commands/commands/move.lua index 8856d2f..6e7f5cc 100644 --- a/worldeditadditions_commands/commands/move.lua +++ b/worldeditadditions_commands/commands/move.lua @@ -24,7 +24,7 @@ end -- ██ ████ ██ ██ ██ ██ ██ █████ -- ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ██████ ████ ███████ -worldedit.register_command("move+", { -- TODO: Make this an override +worldeditadditions_core.register_command("move+", { -- TODO: Make this an override params = " [ [...]]", description = "Moves the defined region to another location - potentially across multiple axes at once.", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/noise2d.lua b/worldeditadditions_commands/commands/noise2d.lua index ce2f287..19f18a4 100644 --- a/worldeditadditions_commands/commands/noise2d.lua +++ b/worldeditadditions_commands/commands/noise2d.lua @@ -1,7 +1,7 @@ local wea = worldeditadditions -worldedit.register_command("noise2d", { +worldeditadditions_core.register_command("noise2d", { params = "[ []] [ []] ...]", description = "Applies 2d random noise to the terrain as a 2d heightmap in the defined region. Optionally takes an arbitrary set of key - value pairs representing parameters that control the properties of the noise and how it's applied. See the full documentation for details of these parameters and what they do.", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/overlay.lua b/worldeditadditions_commands/commands/overlay.lua index e7f3d0f..1763f42 100644 --- a/worldeditadditions_commands/commands/overlay.lua +++ b/worldeditadditions_commands/commands/overlay.lua @@ -3,7 +3,7 @@ -- ██ ██ ██ ██ █████ ██████ ██ ███████ ████ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██████ ████ ███████ ██ ██ ███████ ██ ██ ██ -worldedit.register_command("overlay", { +worldeditadditions_core.register_command("overlay", { params = " [] [] [ []] ...", description = "Places in the last contiguous air space encountered above the first non-air node. In other words, overlays all top-most nodes in the specified area with . Optionally supports a mix of nodes and chances, as in //mix and //replacemix.", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/replacemix.lua b/worldeditadditions_commands/commands/replacemix.lua index dd5ff77..07a5d81 100644 --- a/worldeditadditions_commands/commands/replacemix.lua +++ b/worldeditadditions_commands/commands/replacemix.lua @@ -5,7 +5,7 @@ local wea = worldeditadditions -- ██████ █████ ██████ ██ ███████ ██ █████ ██ ████ ██ ██ ███ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ███████ ██ ███████ ██ ██ ██████ ███████ ██ ██ ██ ██ ██ -worldedit.register_command("replacemix", { +worldeditadditions_core.register_command("replacemix", { params = " [] [] [ []] [ []] ...", description = "Replaces target_node with a mix of other nodes. Functions simmilarly to //mix. is optional and the chance to replace the target node at all. replace_node_a is the node to replace target_node with. If multiple nodes are specified in a space separated list, then when replacing an instance of target_node one is randomly chosen from the list. Just like with //mix, if a positive integer is present after a replace_node, that adds a weighting to that particular node making it more common.", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/scale.lua b/worldeditadditions_commands/commands/scale.lua index 3076386..bbc9000 100644 --- a/worldeditadditions_commands/commands/scale.lua +++ b/worldeditadditions_commands/commands/scale.lua @@ -22,7 +22,7 @@ end -- ███████ ██ ███████ ██ █████ -- ██ ██ ██ ██ ██ ██ -- ███████ ██████ ██ ██ ███████ ███████ -worldedit.register_command("scale", { +worldeditadditions_core.register_command("scale", { params = " | [ [ ]]", description = "Combined scale up / down. Takes either an axis name + a scale factor (e.g. y 3 or -z 2; negative values swap the anchor point for the scale operation), or 3 scale factor values for x, y, and z respectively. In the latter mode, a set of anchors can also be specified, which indicate which size the scale operation should be anchored to.", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/sculpt.lua b/worldeditadditions_commands/commands/sculpt.lua index 41a28da..00e4289 100644 --- a/worldeditadditions_commands/commands/sculpt.lua +++ b/worldeditadditions_commands/commands/sculpt.lua @@ -7,7 +7,7 @@ local Vector3 = wea.Vector3 -- ███████ ██ ██ ██ ██ ██████ ██ -- ██ ██ ██ ██ ██ ██ ██ -- ███████ ██████ ██████ ███████ ██ ██ -worldedit.register_command("sculpt", { +worldeditadditions_core.register_command("sculpt", { params = "[ [ []]]", description = "Applies a sculpting brush to the terrain with a given height. See //sculptlist to list all available brushes. Note that while the brush size is configurable, the actual brush size you end up with may be slightly different to that which you request due to brush size restrictions.", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/selectors/scentre.lua b/worldeditadditions_commands/commands/selectors/scentre.lua index 20311d9..3588c2e 100644 --- a/worldeditadditions_commands/commands/selectors/scentre.lua +++ b/worldeditadditions_commands/commands/selectors/scentre.lua @@ -4,7 +4,7 @@ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ███████ ██████ ███████ ██ ████ ██ ███████ ██ ██ local wea = worldeditadditions -worldedit.register_command("scentre", { +worldeditadditions_core.register_command("scentre", { params = "", description = "Set WorldEdit region positions 1 and 2 to the centre of the current selection.", privs = {worldedit=true}, diff --git a/worldeditadditions_commands/commands/selectors/scloud.lua b/worldeditadditions_commands/commands/selectors/scloud.lua index 06ed4f9..6bbe23f 100644 --- a/worldeditadditions_commands/commands/selectors/scloud.lua +++ b/worldeditadditions_commands/commands/selectors/scloud.lua @@ -14,7 +14,7 @@ minetest.register_on_punchnode(function(pos, node, puncher) else wea.add_pos[name] = nil end end end) -worldedit.register_command("scloud", { +worldeditadditions_core.register_command("scloud", { params = "<0-6|stop|reset>", description = "Set and add to WorldEdit region by punching up to six nodes that define the maximums of your target", privs = {worldedit=true}, diff --git a/worldeditadditions_commands/commands/selectors/scol.lua b/worldeditadditions_commands/commands/selectors/scol.lua index 37af6f4..051472c 100644 --- a/worldeditadditions_commands/commands/selectors/scol.lua +++ b/worldeditadditions_commands/commands/selectors/scol.lua @@ -4,7 +4,7 @@ -- ██ ██ ██ ██ ██ -- ███████ ██████ ██████ ███████ local wea = worldeditadditions -worldedit.register_command("scol", { +worldeditadditions_core.register_command("scol", { params = "[] ", description = "Set WorldEdit region position 2 at a set distance along 1 axis.", privs = {worldedit=true}, diff --git a/worldeditadditions_commands/commands/selectors/scube.lua b/worldeditadditions_commands/commands/selectors/scube.lua index e7e38c9..8f4ac8b 100644 --- a/worldeditadditions_commands/commands/selectors/scube.lua +++ b/worldeditadditions_commands/commands/selectors/scube.lua @@ -4,7 +4,7 @@ -- ██ ██ ██ ██ ██ ██ ██ -- ███████ ██████ ██████ ██████ ███████ local wea = worldeditadditions -worldedit.register_command("scube", { +worldeditadditions_core.register_command("scube", { params = "[ [ []]] ", description = "Set WorldEdit region position 2 at a set distance along 3 axes.", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/selectors/sfactor.lua b/worldeditadditions_commands/commands/selectors/sfactor.lua index ac50269..a70f017 100644 --- a/worldeditadditions_commands/commands/selectors/sfactor.lua +++ b/worldeditadditions_commands/commands/selectors/sfactor.lua @@ -4,7 +4,7 @@ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ███████ ██ ██ ██ ██████ ██ ██████ ██ ██ local wea = worldeditadditions -worldedit.register_command("sfactor", { +worldeditadditions_core.register_command("sfactor", { params = " []", description = "Make the length of one or more target axes of the current selection to be multiple(s) of .", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/selectors/smake.lua b/worldeditadditions_commands/commands/selectors/smake.lua index cd6f4a0..dfc99f1 100644 --- a/worldeditadditions_commands/commands/selectors/smake.lua +++ b/worldeditadditions_commands/commands/selectors/smake.lua @@ -4,7 +4,7 @@ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ███████ ██ ██ ██ ██ ██ ██ ███████ local wea = worldeditadditions -worldedit.register_command("smake", { +worldeditadditions_core.register_command("smake", { params = " [ []]", description = "Make one or more axes of the current selection odd, even, or equal to another.", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/selectors/spop.lua b/worldeditadditions_commands/commands/selectors/spop.lua index a7f1ba8..a982367 100644 --- a/worldeditadditions_commands/commands/selectors/spop.lua +++ b/worldeditadditions_commands/commands/selectors/spop.lua @@ -3,7 +3,7 @@ -- ███████ ██████ ██ ██ ██████ -- ██ ██ ██ ██ ██ -- ███████ ██ ██████ ██ -worldedit.register_command("spop", { +worldeditadditions_core.register_command("spop", { params = "", description = "Pops a region off your (per-user) selection stack.", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/selectors/spush.lua b/worldeditadditions_commands/commands/selectors/spush.lua index 8c85fe0..52cd62f 100644 --- a/worldeditadditions_commands/commands/selectors/spush.lua +++ b/worldeditadditions_commands/commands/selectors/spush.lua @@ -3,7 +3,7 @@ -- ███████ ██████ ██ ██ ███████ ███████ -- ██ ██ ██ ██ ██ ██ ██ -- ███████ ██ ██████ ███████ ██ ██ -worldedit.register_command("spush", { +worldeditadditions_core.register_command("spush", { params = "", description = "Pushes the currently defined region onto your (per-user) selection stack.", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/selectors/srect.lua b/worldeditadditions_commands/commands/selectors/srect.lua index 7669100..85534cc 100644 --- a/worldeditadditions_commands/commands/selectors/srect.lua +++ b/worldeditadditions_commands/commands/selectors/srect.lua @@ -4,7 +4,7 @@ -- ██ ██ ██ ██ ██ ██ -- ███████ ██ ██ ███████ ██████ ██ local wea = worldeditadditions -worldedit.register_command("srect", { +worldeditadditions_core.register_command("srect", { params = "[ []] ", description = "Set WorldEdit region position 2 at a set distance along 2 axes.", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/selectors/srel.lua b/worldeditadditions_commands/commands/selectors/srel.lua index 4377d38..1a01e42 100644 --- a/worldeditadditions_commands/commands/selectors/srel.lua +++ b/worldeditadditions_commands/commands/selectors/srel.lua @@ -21,7 +21,7 @@ local function parse_with_name(name,args) until not args:find("([%l%s+-]+%d+)%s*", i) return true, vec end -worldedit.register_command("srel", { +worldeditadditions_core.register_command("srel", { params = " [ [ ]]", description = "Set WorldEdit region position 2 at set distances along 3 axes.", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/selectors/sshift.lua b/worldeditadditions_commands/commands/selectors/sshift.lua index 8414145..82bc138 100644 --- a/worldeditadditions_commands/commands/selectors/sshift.lua +++ b/worldeditadditions_commands/commands/selectors/sshift.lua @@ -22,7 +22,7 @@ local function parse_with_name(name,args) until not args:find("([%l%s+-]+%d+)%s*", i) return true, vec end -worldedit.register_command("sshift", { +worldeditadditions_core.register_command("sshift", { params = " [ [ ]]", description = "Shift the WorldEdit region in 3 dimensions.", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/selectors/sstack.lua b/worldeditadditions_commands/commands/selectors/sstack.lua index e748d2d..82d486c 100644 --- a/worldeditadditions_commands/commands/selectors/sstack.lua +++ b/worldeditadditions_commands/commands/selectors/sstack.lua @@ -3,7 +3,7 @@ -- ███████ ███████ ██ ███████ ██ █████ -- ██ ██ ██ ██ ██ ██ ██ ██ -- ███████ ███████ ██ ██ ██ ██████ ██ ██ -worldedit.register_command("sstack", { +worldeditadditions_core.register_command("sstack", { params = "", description = "Displays the contents of your (per-user) selection stack.", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/spiral2.lua b/worldeditadditions_commands/commands/spiral2.lua index aa9529f..68f689e 100644 --- a/worldeditadditions_commands/commands/spiral2.lua +++ b/worldeditadditions_commands/commands/spiral2.lua @@ -2,7 +2,7 @@ local wea = worldeditadditions local Vector3 = wea.Vector3 -worldedit.register_command("spiral2", { +worldeditadditions_core.register_command("spiral2", { params = "[] [ [ [] ] ]", description = "Generates a spiral that fills the defined region using the specified replace node. The spiral is either square (default) or circular in shape. The interval specifies the distance between the walls of the spiral, and the acceleration specifies how quickly this value should increase.", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/torus.lua b/worldeditadditions_commands/commands/torus.lua index 4ae2b5c..37fa2c3 100644 --- a/worldeditadditions_commands/commands/torus.lua +++ b/worldeditadditions_commands/commands/torus.lua @@ -52,7 +52,7 @@ local function parse_params_torus(params_text) return true, replace_node, major_radius, minor_radius, axes, hollow end -worldedit.register_command("torus", { +worldeditadditions_core.register_command("torus", { params = " [ [h[ollow]]]", description = "Creates a 3D torus with a major radius of and a minor radius of at pos1, filled with , on axes (i.e. 2 axis names: xz, zy, etc).", privs = { worldedit = true }, @@ -81,7 +81,7 @@ worldedit.register_command("torus", { }) -- TODO: This duplicates a lot of code. Perhaps we can trim it down a bit? -worldedit.register_command("hollowtorus", { +worldeditadditions_core.register_command("hollowtorus", { params = " []", description = "Creates a 3D hollow torus with a major radius of and a minor radius of at pos1, made out of , on axes (i.e. 2 axis names: xz, zy, etc).", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/walls.lua b/worldeditadditions_commands/commands/walls.lua index 12d6d72..aa6b694 100644 --- a/worldeditadditions_commands/commands/walls.lua +++ b/worldeditadditions_commands/commands/walls.lua @@ -3,7 +3,7 @@ -- ██ █ ██ ███████ ██ ██ ███████ -- ██ ███ ██ ██ ██ ██ ██ ██ -- ███ ███ ██ ██ ███████ ███████ ███████ -worldedit.register_command("walls", { +worldeditadditions_core.register_command("walls", { params = "[ []]", description = "Creates vertical walls of around the inside edges of the defined region. Optionally specifies a thickness for the walls to be created (defaults to 1)", privs = { worldedit = true }, diff --git a/worldeditadditions_commands/commands/wireframe/wbox.lua b/worldeditadditions_commands/commands/wireframe/wbox.lua index c2bd9c4..d600bba 100644 --- a/worldeditadditions_commands/commands/wireframe/wbox.lua +++ b/worldeditadditions_commands/commands/wireframe/wbox.lua @@ -5,7 +5,7 @@ -- ███ ███ ██████ ██████ ██ ██ local wea = worldeditadditions local v3 = worldeditadditions.Vector3 -worldedit.register_command("wbox", { +worldeditadditions_core.register_command("wbox", { params = "", description = "Sets the edges of the current selection to ", privs = {worldedit=true}, diff --git a/worldeditadditions_commands/commands/wireframe/wcompass.lua b/worldeditadditions_commands/commands/wireframe/wcompass.lua index ba012c8..a54af4d 100644 --- a/worldeditadditions_commands/commands/wireframe/wcompass.lua +++ b/worldeditadditions_commands/commands/wireframe/wcompass.lua @@ -4,7 +4,7 @@ -- ██ ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ███ ███ ██████ ██████ ██ ██ ██ ██ ██ ███████ ███████ local wea = worldeditadditions -worldedit.register_command("wcompass", { +worldeditadditions_core.register_command("wcompass", { params = " []", description = "Creates a compass around pos1 with a single node bead pointing north (+Z).", privs = {worldedit=true}, diff --git a/worldeditadditions_commands/commands/wireframe/wcorner.lua b/worldeditadditions_commands/commands/wireframe/wcorner.lua index af08d6f..67440b6 100644 --- a/worldeditadditions_commands/commands/wireframe/wcorner.lua +++ b/worldeditadditions_commands/commands/wireframe/wcorner.lua @@ -4,7 +4,7 @@ -- ██ ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ███ ███ ██████ ██████ ██ ██ ██ ████ ███████ ██ ██ local wea = worldeditadditions -worldedit.register_command("wcorner", { +worldeditadditions_core.register_command("wcorner", { params = "", description = "Set the corners of the current selection to ", privs = {worldedit=true}, From c2c0fa5d8da8480d3c3d2d2546006088db35a020 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Thu, 19 May 2022 22:13:09 +0100 Subject: [PATCH 24/25] core: if worldedit is installed also register commands there This ensures that e.g. //cubeapply continues to work as expected --- worldeditadditions_core/core/register_command.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/worldeditadditions_core/core/register_command.lua b/worldeditadditions_core/core/register_command.lua index 0e6eb8c..87e5960 100644 --- a/worldeditadditions_core/core/register_command.lua +++ b/worldeditadditions_core/core/register_command.lua @@ -58,6 +58,9 @@ local function register_command(cmdname, options) end }) wea_c.registered_commands[cmdname] = options + if minetest.global_exists("worldedit") then + worldedit.registered_commands[cmdname] = options + end end return register_command From 1750d62d3cc9fc70a4d7dd0a7c525cfff4773992 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Thu, 19 May 2022 22:50:53 +0100 Subject: [PATCH 25/25] core: add register_alias command it is backwards-compatible with worldedit.register_command --- worldeditadditions_commands/aliases.lua | 16 ++++---- .../core/register_alias.lua | 40 +++++++++++++++++++ worldeditadditions_core/init.lua | 1 + 3 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 worldeditadditions_core/core/register_alias.lua diff --git a/worldeditadditions_commands/aliases.lua b/worldeditadditions_commands/aliases.lua index 3d64993..bf102f6 100644 --- a/worldeditadditions_commands/aliases.lua +++ b/worldeditadditions_commands/aliases.lua @@ -1,14 +1,16 @@ -worldedit.alias_command("smoothadv", "convolve") -worldedit.alias_command("conv", "convolve") +local wea_c = worldeditadditions_core -worldedit.alias_command("naturalise", "layers") -worldedit.alias_command("naturalize", "layers") +wea_c.register_alias("smoothadv", "convolve") +wea_c.register_alias("conv", "convolve") -worldedit.alias_command("flora", "bonemeal") +wea_c.register_alias("naturalise", "layers") +wea_c.register_alias("naturalize", "layers") + +wea_c.register_alias("flora", "bonemeal") -- Measure Tools -worldedit.alias_command("mcount", "count") -worldedit.alias_command("mfacing", "mface") +wea_c.register_alias("mcount", "count") +wea_c.register_alias("mfacing", "mface") --- Overrides to core WorldEdit commands diff --git a/worldeditadditions_core/core/register_alias.lua b/worldeditadditions_core/core/register_alias.lua new file mode 100644 index 0000000..0e448a7 --- /dev/null +++ b/worldeditadditions_core/core/register_alias.lua @@ -0,0 +1,40 @@ + +local wea_c = worldeditadditions_core + +local function register_alias(cmdname_target, cmdname_source, override) + if override == nil then override = false end + + local def_source = wea_c.fetch_command_def(cmdname_source) + + if not def_source then + minetest.log("error", "worldeditadditions_core: Failed to register alias for "..cmdname_source.." → "..cmdname_target..", as the source command doesn't exist.") + return false + end + + if wea_c.fetch_command_def(cmdname_target) and not override then + minetest.log("error", "worldeditadditions_core: Failed to register alias for "..cmdname_source.." → "..cmdname_target..", as the target command exists and override wasn't set to true.") + return false + end + + print("DEBUG ALIAS source "..cmdname_source.." target "..cmdname_target) + + if minetest.chatcommands["/"..cmdname_target] then + minetest.override_chatcommand( + "/"..cmdname_target, + minetest.chatcommands["/"..cmdname_source] + ) + else + minetest.register_chatcommand( + "/"..cmdname_target, + minetest.chatcommands["/"..cmdname_source] + ) + end + wea_c.registered_commands[cmdname_target] = wea_c.registered_commands[cmdname_source] + + if minetest.global_exists("worldedit") then + worldedit.registered_commands[cmdname_target] = worldedit.registered_commands[cmdname_source] + end +end + + +return register_alias diff --git a/worldeditadditions_core/init.lua b/worldeditadditions_core/init.lua index 9a77be7..3ce5a68 100644 --- a/worldeditadditions_core/init.lua +++ b/worldeditadditions_core/init.lua @@ -25,6 +25,7 @@ worldeditadditions_core = { local wea_c = worldeditadditions_core wea_c.register_command = dofile(modpath.."/core/register_command.lua") wea_c.fetch_command_def = dofile(modpath.."/core/fetch_command_def.lua") +wea_c.register_alias = dofile(modpath.."/core/register_alias.lua") -- Initialise WorldEdit stuff if the WorldEdit mod is not present