From 489d856176e65a973ad191b32c24519e1c4bcc51 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Wed, 24 Feb 2021 08:40:53 -0800 Subject: [PATCH 01/11] Added srect and basename Also moved saplingaliases and corrected the block text in forest.lua --- worldeditadditions/init.lua | 1 + worldeditadditions/utils/selector_helps.lua | 9 ++++ .../commands/extra/basename.lua | 18 +++++++ .../commands/{ => extra}/saplingaliases.lua | 9 +++- .../commands/forest.lua | 17 ++++--- .../commands/selectors/srect.lua | 51 +++++++++++++++++++ worldeditadditions_commands/init.lua | 8 ++- 7 files changed, 102 insertions(+), 11 deletions(-) create mode 100644 worldeditadditions/utils/selector_helps.lua create mode 100644 worldeditadditions_commands/commands/extra/basename.lua rename worldeditadditions_commands/commands/{ => extra}/saplingaliases.lua (55%) create mode 100644 worldeditadditions_commands/commands/selectors/srect.lua diff --git a/worldeditadditions/init.lua b/worldeditadditions/init.lua index 163a071..49acea4 100644 --- a/worldeditadditions/init.lua +++ b/worldeditadditions/init.lua @@ -15,6 +15,7 @@ dofile(worldeditadditions.modpath.."/utils/node_identification.lua") dofile(worldeditadditions.modpath.."/utils/tables.lua") dofile(worldeditadditions.modpath.."/utils/terrain.lua") dofile(worldeditadditions.modpath.."/utils/raycast_adv.lua") -- For the farwand +dofile(worldeditadditions.modpath.."/utils/selector_helps.lua") dofile(worldeditadditions.modpath.."/lib/compat/saplingnames.lua") diff --git a/worldeditadditions/utils/selector_helps.lua b/worldeditadditions/utils/selector_helps.lua new file mode 100644 index 0000000..208eec4 --- /dev/null +++ b/worldeditadditions/utils/selector_helps.lua @@ -0,0 +1,9 @@ +function worldeditadditions.player_axis2d(name) + -- minetest.get_player_by_name("singleplayer"): + local dir = math.floor(minetest.get_player_by_name(name):get_look_horizontal() / math.pi * 2 + 0.5) % 3 + local crdnl = { {1,"z"},{-1,"x"},{-1,"z"},{1,"x"} } + return crdnl[dir+1] +end + +-- Tests +-- /lua print(unpack(worldeditadditions.player_axis2d(myname))) diff --git a/worldeditadditions_commands/commands/extra/basename.lua b/worldeditadditions_commands/commands/extra/basename.lua new file mode 100644 index 0000000..d814aa6 --- /dev/null +++ b/worldeditadditions_commands/commands/extra/basename.lua @@ -0,0 +1,18 @@ +-- ██████ █████ ███████ ███████ ███ ██ █████ ███ ███ ███████ +-- ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ████ ████ ██ +-- ██████ ███████ ███████ █████ ██ ██ ██ ███████ ██ ████ ██ █████ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ██████ ██ ██ ███████ ███████ ██ ████ ██ ██ ██ ██ ███████ +worldedit.register_command("basename", { + params = "", + description = "Returns the base name of nodes that use a given alias.", + privs = {worldedit = true}, + parse = function(params_text) + params_text = params_text or "air" + return true, params_text + end, + func = function(name, params_text) + if name == nil then return end + worldedit.player_notify(name, worldedit.normalize_nodename(params_text) or 'Error 404: "'..params_text..'" not found!') + end +}) diff --git a/worldeditadditions_commands/commands/saplingaliases.lua b/worldeditadditions_commands/commands/extra/saplingaliases.lua similarity index 55% rename from worldeditadditions_commands/commands/saplingaliases.lua rename to worldeditadditions_commands/commands/extra/saplingaliases.lua index 7fd1b11..ee2b6cb 100644 --- a/worldeditadditions_commands/commands/saplingaliases.lua +++ b/worldeditadditions_commands/commands/extra/saplingaliases.lua @@ -1,3 +1,8 @@ +-- ███████ █████ ██████ ██ ██ ███ ██ ██████ █████ ██ ██ █████ ███████ ███████ ███████ +-- ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ███████ ███████ ██████ ██ ██ ██ ██ ██ ██ ███ ███████ ██ ██ ███████ ███████ █████ ███████ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ███████ ██ ██ ██ ███████ ██ ██ ████ ██████ ██ ██ ███████ ██ ██ ██ ███████ ███████ ███████ minetest.register_chatcommand("/saplingaliases", { params = "[aliases|all_saplings]", description = "Lists all the currently registered sapling aliases (default). A single argument is taken as the mode of operation. Current modes: aliases (default; as described previously), all_saplings (lists all node names with the group \"sapling\")", @@ -7,9 +12,9 @@ minetest.register_chatcommand("/saplingaliases", { if params_text == "" or not params_text then params_text = "aliases" end - + local msg = {} - + if params_text == "aliases" then table.insert(msg, "Currently registered aliases:\n") local aliases = worldeditadditions.get_all_sapling_aliases() diff --git a/worldeditadditions_commands/commands/forest.lua b/worldeditadditions_commands/commands/forest.lua index e780ea4..3271b94 100644 --- a/worldeditadditions_commands/commands/forest.lua +++ b/worldeditadditions_commands/commands/forest.lua @@ -1,8 +1,9 @@ --- ██████ ██ ██ ███████ ██████ ██ █████ ██ ██ --- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ --- ██ ██ ██ ██ █████ ██████ ██ ███████ ████ --- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ --- ██████ ████ ███████ ██ ██ ███████ ██ ██ ██ +-- ███████ ██████ ██████ ███████ ███████ ████████ +-- ██ ██ ██ ██ ██ ██ ██ ██ +-- █████ ██ ██ ██████ █████ ███████ ██ +-- ██ ██ ██ ██ ██ ██ ██ ██ +-- ██ ██████ ██ ██ ███████ ███████ ██ + worldedit.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).", @@ -15,7 +16,7 @@ worldedit.register_command("forest", { density = tonumber(match_start) params_text = params_text:sub(#match_start + 1) -- everything starts at 1 in Lua :-/ end - + local success, sapling_list = worldeditadditions.parse_weighted_nodes( worldeditadditions.split(params_text, "%s+", false), false, @@ -42,11 +43,11 @@ worldedit.register_command("forest", { ) if not success then return success, stats end local time_taken = worldeditadditions.human_time(worldeditadditions.get_ms_time() - start_time) - + local distribution_display = worldeditadditions.make_ascii_table( worldeditadditions.node_distribution_to_list(stats.placed, stats.successes) ) - + minetest.log("action", name.." used //forest at "..worldeditadditions.vector.tostring(worldedit.pos1[name]).." - "..worldeditadditions.vector.tostring(worldedit.pos2[name])..", "..stats.successes.." trees placed, averaging "..stats.attempts_avg.." growth attempts / tree and "..stats.failures.." failed attempts in "..time_taken) return true, distribution_display.."\n=========================\n"..stats.successes.." trees placed, averaging "..stats.attempts_avg.." growth attempts / tree and "..stats.failures.." failed attempts in "..time_taken end diff --git a/worldeditadditions_commands/commands/selectors/srect.lua b/worldeditadditions_commands/commands/selectors/srect.lua new file mode 100644 index 0000000..e4c85d3 --- /dev/null +++ b/worldeditadditions_commands/commands/selectors/srect.lua @@ -0,0 +1,51 @@ +-- ███████ ██████ ███████ ██████ ████████ +-- ██ ██ ██ ██ ██ ██ +-- ███████ ██████ █████ ██ ██ +-- ██ ██ ██ ██ ██ ██ +-- ███████ ██ ██ ███████ ██████ ██ +-- lua parse_params_srect("10") +-- local +function parse_params_srect(params_text) + local find, _, sn1, ax1, sn2, ax2, len = params_text:find("([+-]?)([xyz]?)%s*([+-]?)([xyz]?)%s*(%d*)") + + -- If ax1 is nil set to player facing dir + if ax1 == "" then ax1 = "get" + else ax1 = {tonumber(sn1..1),string.lower(ax1)} + end + -- If ax2 is nil set to +y + if ax2 == "" then ax2 = "y" end + ax2 = {tonumber(sn2..1),string.lower(ax2)} + + len = tonumber(len) + if len == nil then + return false, "No length specified." + end + + return true, ax1, ax2, len +end +worldedit.register_command("srect", { + params = "[ []] ", + description = "Set WorldEdit region position 2 at a set distance along 2 axes.", + privs = {worldedit=true}, + require_pos = 1, + parse = function(params_text) + local values = {parse_params_srect(params_text)} + return unpack(values) + end, + func = function(name, axis1, axis2, len) + if axis1 == "get" then axis1 = worldeditadditions.player_axis2d(name) end + + local pos1 = worldedit.pos1[name] + local p2 = {["x"] = pos1.x,["y"] = pos1.y,["z"] = pos1.z} + + p2[axis1[2]] = p2[axis1[2]] + tonumber(len) * axis1[1] + p2[axis2[2]] = p2[axis2[2]] + tonumber(len) * axis2[1] + + worldedit.pos2[name] = p2 + worldedit.mark_pos2(name) + worldedit.player_notify(name, "position 2 set to " .. minetest.pos_to_string(p2)) + end, +}) + +-- Tests +-- params_text = "-x z 13" diff --git a/worldeditadditions_commands/init.lua b/worldeditadditions_commands/init.lua index ff3aa89..425413c 100644 --- a/worldeditadditions_commands/init.lua +++ b/worldeditadditions_commands/init.lua @@ -35,13 +35,19 @@ dofile(we_c.modpath.."/commands/hollow.lua") dofile(we_c.modpath.."/commands/scale.lua") dofile(we_c.modpath.."/commands/count.lua") -dofile(we_c.modpath.."/commands/saplingaliases.lua") dofile(we_c.modpath.."/commands/meta/multi.lua") dofile(we_c.modpath.."/commands/meta/many.lua") dofile(we_c.modpath.."/commands/meta/subdivide.lua") dofile(we_c.modpath.."/commands/meta/ellipsoidapply.lua") +-- dofile(we_c.modpath.."/commands/selectors/scol.lua") +dofile(we_c.modpath.."/commands/selectors/srect.lua") +-- dofile(we_c.modpath.."/commands/selectors/scube.lua") + +dofile(we_c.modpath.."/commands/extra/saplingaliases.lua") +dofile(we_c.modpath.."/commands/extra/basename.lua") + -- Don't registry the //bonemeal command if the bonemeal mod isn't present if minetest.get_modpath("bonemeal") then dofile(we_c.modpath.."/commands/bonemeal.lua") From 191f1385b142c9ad6ed1e66443079a6ce282f40e Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Wed, 24 Feb 2021 09:08:49 -0800 Subject: [PATCH 02/11] fixed modulo --- worldeditadditions/utils/selector_helps.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worldeditadditions/utils/selector_helps.lua b/worldeditadditions/utils/selector_helps.lua index 208eec4..904f233 100644 --- a/worldeditadditions/utils/selector_helps.lua +++ b/worldeditadditions/utils/selector_helps.lua @@ -1,6 +1,6 @@ function worldeditadditions.player_axis2d(name) -- minetest.get_player_by_name("singleplayer"): - local dir = math.floor(minetest.get_player_by_name(name):get_look_horizontal() / math.pi * 2 + 0.5) % 3 + local dir = math.floor(minetest.get_player_by_name(name):get_look_horizontal() / math.pi * 2 + 0.5) % 4 local crdnl = { {1,"z"},{-1,"x"},{-1,"z"},{1,"x"} } return crdnl[dir+1] end From 1d93122801117da5445638c8103af52f656fc828 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Wed, 24 Feb 2021 09:19:08 -0800 Subject: [PATCH 03/11] basename error handling --- worldeditadditions_commands/commands/extra/basename.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/worldeditadditions_commands/commands/extra/basename.lua b/worldeditadditions_commands/commands/extra/basename.lua index d814aa6..77fa168 100644 --- a/worldeditadditions_commands/commands/extra/basename.lua +++ b/worldeditadditions_commands/commands/extra/basename.lua @@ -8,7 +8,9 @@ worldedit.register_command("basename", { description = "Returns the base name of nodes that use a given alias.", privs = {worldedit = true}, parse = function(params_text) - params_text = params_text or "air" + if params_text == "" or not params_text then + return false, "Node not specified." + end return true, params_text end, func = function(name, params_text) From f6ed2972704275159947519f3d01b6dd6a2967aa Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Wed, 24 Feb 2021 19:35:20 -0800 Subject: [PATCH 04/11] indentation fixes --- .../commands/extra/basename.lua | 14 ++--- .../commands/extra/saplingaliases.lua | 4 +- .../commands/forest.lua | 6 +-- .../commands/selectors/srect.lua | 51 ++++++++++--------- 4 files changed, 38 insertions(+), 37 deletions(-) diff --git a/worldeditadditions_commands/commands/extra/basename.lua b/worldeditadditions_commands/commands/extra/basename.lua index 77fa168..39d92b5 100644 --- a/worldeditadditions_commands/commands/extra/basename.lua +++ b/worldeditadditions_commands/commands/extra/basename.lua @@ -7,14 +7,14 @@ worldedit.register_command("basename", { params = "", description = "Returns the base name of nodes that use a given alias.", privs = {worldedit = true}, - parse = function(params_text) - if params_text == "" or not params_text then - return false, "Node not specified." - end - return true, params_text + parse = function(params_text) + if params_text == "" or not params_text then + return false, "Node not specified." + end + return true, params_text end, func = function(name, params_text) - if name == nil then return end - worldedit.player_notify(name, worldedit.normalize_nodename(params_text) or 'Error 404: "'..params_text..'" not found!') + if name == nil then return end + worldedit.player_notify(name, worldedit.normalize_nodename(params_text) or 'Error 404: "'..params_text..'" not found!') end }) diff --git a/worldeditadditions_commands/commands/extra/saplingaliases.lua b/worldeditadditions_commands/commands/extra/saplingaliases.lua index ee2b6cb..a495ca6 100644 --- a/worldeditadditions_commands/commands/extra/saplingaliases.lua +++ b/worldeditadditions_commands/commands/extra/saplingaliases.lua @@ -12,9 +12,9 @@ minetest.register_chatcommand("/saplingaliases", { if params_text == "" or not params_text then params_text = "aliases" end - + local msg = {} - + if params_text == "aliases" then table.insert(msg, "Currently registered aliases:\n") local aliases = worldeditadditions.get_all_sapling_aliases() diff --git a/worldeditadditions_commands/commands/forest.lua b/worldeditadditions_commands/commands/forest.lua index 3271b94..e9d8336 100644 --- a/worldeditadditions_commands/commands/forest.lua +++ b/worldeditadditions_commands/commands/forest.lua @@ -16,7 +16,7 @@ worldedit.register_command("forest", { density = tonumber(match_start) params_text = params_text:sub(#match_start + 1) -- everything starts at 1 in Lua :-/ end - + local success, sapling_list = worldeditadditions.parse_weighted_nodes( worldeditadditions.split(params_text, "%s+", false), false, @@ -43,11 +43,11 @@ worldedit.register_command("forest", { ) if not success then return success, stats end local time_taken = worldeditadditions.human_time(worldeditadditions.get_ms_time() - start_time) - + local distribution_display = worldeditadditions.make_ascii_table( worldeditadditions.node_distribution_to_list(stats.placed, stats.successes) ) - + minetest.log("action", name.." used //forest at "..worldeditadditions.vector.tostring(worldedit.pos1[name]).." - "..worldeditadditions.vector.tostring(worldedit.pos2[name])..", "..stats.successes.." trees placed, averaging "..stats.attempts_avg.." growth attempts / tree and "..stats.failures.." failed attempts in "..time_taken) return true, distribution_display.."\n=========================\n"..stats.successes.." trees placed, averaging "..stats.attempts_avg.." growth attempts / tree and "..stats.failures.." failed attempts in "..time_taken end diff --git a/worldeditadditions_commands/commands/selectors/srect.lua b/worldeditadditions_commands/commands/selectors/srect.lua index e4c85d3..4f28db4 100644 --- a/worldeditadditions_commands/commands/selectors/srect.lua +++ b/worldeditadditions_commands/commands/selectors/srect.lua @@ -4,43 +4,43 @@ -- ██ ██ ██ ██ ██ ██ -- ███████ ██ ██ ███████ ██████ ██ -- lua parse_params_srect("10") --- local +-- local -- TODO: set this to local once development is finished function parse_params_srect(params_text) - local find, _, sn1, ax1, sn2, ax2, len = params_text:find("([+-]?)([xyz]?)%s*([+-]?)([xyz]?)%s*(%d*)") - - -- If ax1 is nil set to player facing dir - if ax1 == "" then ax1 = "get" - else ax1 = {tonumber(sn1..1),string.lower(ax1)} + local find, _, sn1, ax1, sn2, ax2, len = params_text:find("([+-]?)([xyz]?)%s*([+-]?)([xyz]?)%s*(%d*)") + + -- If ax1 is nil set to player facing dir + if ax1 == "" then ax1 = "get" + else ax1 = {tonumber(sn1..1),string.lower(ax1)} end - -- If ax2 is nil set to +y - if ax2 == "" then ax2 = "y" end - ax2 = {tonumber(sn2..1),string.lower(ax2)} - - len = tonumber(len) - if len == nil then - return false, "No length specified." - end - - return true, ax1, ax2, len + -- If ax2 is nil set to +y + if ax2 == "" then ax2 = "y" end + ax2 = {tonumber(sn2..1),string.lower(ax2)} + + len = tonumber(len) + if len == nil then + return false, "No length specified." + end + + return true, ax1, ax2, len end worldedit.register_command("srect", { params = "[ []] ", description = "Set WorldEdit region position 2 at a set distance along 2 axes.", privs = {worldedit=true}, - require_pos = 1, - parse = function(params_text) + require_pos = 1, + parse = function(params_text) local values = {parse_params_srect(params_text)} return unpack(values) end, func = function(name, axis1, axis2, len) - if axis1 == "get" then axis1 = worldeditadditions.player_axis2d(name) end - + if axis1 == "get" then axis1 = worldeditadditions.player_axis2d(name) end + local pos1 = worldedit.pos1[name] - local p2 = {["x"] = pos1.x,["y"] = pos1.y,["z"] = pos1.z} - - p2[axis1[2]] = p2[axis1[2]] + tonumber(len) * axis1[1] - p2[axis2[2]] = p2[axis2[2]] + tonumber(len) * axis2[1] - + local p2 = {["x"] = pos1.x,["y"] = pos1.y,["z"] = pos1.z} + + p2[axis1[2]] = p2[axis1[2]] + tonumber(len) * axis1[1] + p2[axis2[2]] = p2[axis2[2]] + tonumber(len) * axis2[1] + worldedit.pos2[name] = p2 worldedit.mark_pos2(name) worldedit.player_notify(name, "position 2 set to " .. minetest.pos_to_string(p2)) @@ -49,3 +49,4 @@ worldedit.register_command("srect", { -- Tests -- params_text = "-x z 13" +-- params_text = "-x a 13" From b62e4f706d1817ca5a2c767d88d921913cbbec3a Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Wed, 24 Feb 2021 19:42:24 -0800 Subject: [PATCH 05/11] added description --- worldeditadditions/utils/selector_helps.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/worldeditadditions/utils/selector_helps.lua b/worldeditadditions/utils/selector_helps.lua index 904f233..60d31ba 100644 --- a/worldeditadditions/utils/selector_helps.lua +++ b/worldeditadditions/utils/selector_helps.lua @@ -1,3 +1,6 @@ +-- Returns the player's facing direction on the horizontal axes only. +-- @param name string The name of the player to return facing direction of. +-- @return table Returns axis name and sign multiplyer. function worldeditadditions.player_axis2d(name) -- minetest.get_player_by_name("singleplayer"): local dir = math.floor(minetest.get_player_by_name(name):get_look_horizontal() / math.pi * 2 + 0.5) % 4 From cb1d54c665ca734b4dc645a55c0b979bcce12584 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Thu, 25 Feb 2021 20:22:39 -0800 Subject: [PATCH 06/11] Added getsign, fixed srect glitch --- worldeditadditions/utils/numbers.lua | 42 +++++++++++++------ .../commands/selectors/srect.lua | 25 +++++------ 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/worldeditadditions/utils/numbers.lua b/worldeditadditions/utils/numbers.lua index 82565fe..2f5d10e 100644 --- a/worldeditadditions/utils/numbers.lua +++ b/worldeditadditions/utils/numbers.lua @@ -1,7 +1,7 @@ -- From http://lua-users.org/wiki/SimpleRound function worldeditadditions.round(num, numDecimalPlaces) - local mult = 10^(numDecimalPlaces or 0) - return math.floor(num * mult + 0.5) / mult + local mult = 10^(numDecimalPlaces or 0) + return math.floor(num * mult + 0.5) / mult end function worldeditadditions.hypotenuse(x1, y1, x2, y2) @@ -11,17 +11,17 @@ function worldeditadditions.hypotenuse(x1, y1, x2, y2) end function worldeditadditions.sum(list) - if #list == 0 then return 0 end + if #list == 0 then return 0 end local sum = 0 for i,value in ipairs(list) do sum = sum + value end - return sum + return sum end function worldeditadditions.average(list) - if #list == 0 then return 0 end + if #list == 0 then return 0 end return worldeditadditions.sum(list) / #list end @@ -32,11 +32,29 @@ function worldeditadditions.get_ms_time() end function worldeditadditions.eta(existing_times, done_count, total_count) - local max = 100 - local average = worldeditadditions.average( - worldeditadditions.table_get_last(existing_times, max) - ) - local times_left = total_count - done_count - if times_left == 0 then return 0 end - return average * times_left + local max = 100 + local average = worldeditadditions.average( + worldeditadditions.table_get_last(existing_times, max) + ) + local times_left = total_count - done_count + if times_left == 0 then return 0 end + return average * times_left +end + +--- Returns the sign (+ or -) at the beginning of a string if present. +-- @param str string Input string. +-- @param type string The type of value to return. Valid values: "string" (default), "int" +-- @return string|int Returns the sign string or signed multiplier (1|-1). +function worldeditadditions.getsign(str, type) + if not type then type = "string" end + if not (type == "string" or type == "int") then + return false, "Error: Unknown type '"..type.."'." + end + if str:sub(1, 1) == "-" then + if type == "int" then return -1 + else return "-" end + else + if type == "int" then return 1 + else return "+" end + end end diff --git a/worldeditadditions_commands/commands/selectors/srect.lua b/worldeditadditions_commands/commands/selectors/srect.lua index 4f28db4..7138bd8 100644 --- a/worldeditadditions_commands/commands/selectors/srect.lua +++ b/worldeditadditions_commands/commands/selectors/srect.lua @@ -3,20 +3,22 @@ -- ███████ ██████ █████ ██ ██ -- ██ ██ ██ ██ ██ ██ -- ███████ ██ ██ ███████ ██████ ██ --- lua parse_params_srect("10") -- local -- TODO: set this to local once development is finished function parse_params_srect(params_text) - local find, _, sn1, ax1, sn2, ax2, len = params_text:find("([+-]?)([xyz]?)%s*([+-]?)([xyz]?)%s*(%d*)") + local wea = worldeditadditions + local find = wea.split(params_text, "%s", false) + local ax1, ax2, len = find[1], find[2], find[table.maxn(find)] - -- If ax1 is nil set to player facing dir - if ax1 == "" then ax1 = "get" - else ax1 = {tonumber(sn1..1),string.lower(ax1)} + -- If ax1 is bad set to player facing dir + if ax1 == len or not ax1:match('[xyz]') then ax1 = "get" + else ax1 = {wea.getsign(ax1, "int"),ax1:gsub('-?',''):sub(1,1)} end - -- If ax2 is nil set to +y - if ax2 == "" then ax2 = "y" end - ax2 = {tonumber(sn2..1),string.lower(ax2)} + -- If ax2 is bad set to +y + if not ax2 or ax2 == len or not ax2:match('[xyz]') then ax2 = "y" end + ax2 = {wea.getsign(ax2, "int"),ax2:gsub('-?',''):sub(1,1)} len = tonumber(len) + -- If len == nill cancel the operation if len == nil then return false, "No length specified." end @@ -36,17 +38,16 @@ worldedit.register_command("srect", { if axis1 == "get" then axis1 = worldeditadditions.player_axis2d(name) end local pos1 = worldedit.pos1[name] - local p2 = {["x"] = pos1.x,["y"] = pos1.y,["z"] = pos1.z} + local p2 = vector.new(pos1) p2[axis1[2]] = p2[axis1[2]] + tonumber(len) * axis1[1] p2[axis2[2]] = p2[axis2[2]] + tonumber(len) * axis2[1] worldedit.pos2[name] = p2 worldedit.mark_pos2(name) - worldedit.player_notify(name, "position 2 set to " .. minetest.pos_to_string(p2)) + return true, "position 2 set to " .. minetest.pos_to_string(p2) end, }) -- Tests --- params_text = "-x z 13" --- params_text = "-x a 13" +-- /multi //fp set1 -63 19 -20 //srect 5 From b31b005bdd04a7b2749e455c9fc8a603903d8e9a Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Fri, 26 Feb 2021 08:23:10 -0800 Subject: [PATCH 07/11] -axyzb patch --- worldeditadditions_commands/commands/selectors/srect.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/worldeditadditions_commands/commands/selectors/srect.lua b/worldeditadditions_commands/commands/selectors/srect.lua index 7138bd8..8193052 100644 --- a/worldeditadditions_commands/commands/selectors/srect.lua +++ b/worldeditadditions_commands/commands/selectors/srect.lua @@ -11,11 +11,11 @@ function parse_params_srect(params_text) -- If ax1 is bad set to player facing dir if ax1 == len or not ax1:match('[xyz]') then ax1 = "get" - else ax1 = {wea.getsign(ax1, "int"),ax1:gsub('-?',''):sub(1,1)} + else ax1 = {wea.getsign(ax1, "int"),ax1:gsub('[^xyz]',''):sub(1,1)} end -- If ax2 is bad set to +y if not ax2 or ax2 == len or not ax2:match('[xyz]') then ax2 = "y" end - ax2 = {wea.getsign(ax2, "int"),ax2:gsub('-?',''):sub(1,1)} + ax2 = {wea.getsign(ax2, "int"),ax2:gsub('[^xyz]',''):sub(1,1)} len = tonumber(len) -- If len == nill cancel the operation From e82c8b1e8196b37efb6ed9b1f81f614760b65a74 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Sun, 28 Feb 2021 07:25:31 -0800 Subject: [PATCH 08/11] error handling Co-authored-by: Starbeamrainbowlabs --- worldeditadditions/utils/numbers.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/worldeditadditions/utils/numbers.lua b/worldeditadditions/utils/numbers.lua index 2f5d10e..97131a0 100644 --- a/worldeditadditions/utils/numbers.lua +++ b/worldeditadditions/utils/numbers.lua @@ -51,10 +51,10 @@ function worldeditadditions.getsign(str, type) return false, "Error: Unknown type '"..type.."'." end if str:sub(1, 1) == "-" then - if type == "int" then return -1 - else return "-" end + if type == "int" then return true, -1 + else return true, "-" end else - if type == "int" then return 1 - else return "+" end + if type == "int" then return true, 1 + else return true, "+" end end end From 0c4736fbc287959bd441243292fc73badc15c8ff Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Sun, 28 Feb 2021 09:56:39 -0800 Subject: [PATCH 09/11] Debugging returns Co-authored-by: Starbeamrainbowlabs --- worldeditadditions_commands/commands/selectors/srect.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/worldeditadditions_commands/commands/selectors/srect.lua b/worldeditadditions_commands/commands/selectors/srect.lua index 8193052..e06a916 100644 --- a/worldeditadditions_commands/commands/selectors/srect.lua +++ b/worldeditadditions_commands/commands/selectors/srect.lua @@ -11,11 +11,15 @@ function parse_params_srect(params_text) -- If ax1 is bad set to player facing dir if ax1 == len or not ax1:match('[xyz]') then ax1 = "get" - else ax1 = {wea.getsign(ax1, "int"),ax1:gsub('[^xyz]',''):sub(1,1)} + local success, value = wea.getsign(ax1, "int") + if not success then return success, value end + else ax1 = { value, ax1:gsub('[^xyz]',''):sub(1,1) } end -- If ax2 is bad set to +y if not ax2 or ax2 == len or not ax2:match('[xyz]') then ax2 = "y" end - ax2 = {wea.getsign(ax2, "int"),ax2:gsub('[^xyz]',''):sub(1,1)} + local success, value = wea.getsign(ax2, "int") + if not success then return success, value end + ax2 = { value, ax2:gsub('[^xyz]',''):sub(1,1) } len = tonumber(len) -- If len == nill cancel the operation From 727ee41e72fb8da13bff869502214571c6fc791e Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Sun, 28 Feb 2021 09:59:09 -0800 Subject: [PATCH 10/11] Simplify srect function --- worldeditadditions/utils/numbers.lua | 4 ++++ worldeditadditions_commands/commands/selectors/srect.lua | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/worldeditadditions/utils/numbers.lua b/worldeditadditions/utils/numbers.lua index 97131a0..f287199 100644 --- a/worldeditadditions/utils/numbers.lua +++ b/worldeditadditions/utils/numbers.lua @@ -58,3 +58,7 @@ function worldeditadditions.getsign(str, type) else return true, "+" end end end + +-- For Testing: +-- worldeditadditions = {} +-- print(worldeditadditions.getsign('-y')) diff --git a/worldeditadditions_commands/commands/selectors/srect.lua b/worldeditadditions_commands/commands/selectors/srect.lua index e06a916..df7bf00 100644 --- a/worldeditadditions_commands/commands/selectors/srect.lua +++ b/worldeditadditions_commands/commands/selectors/srect.lua @@ -41,8 +41,7 @@ worldedit.register_command("srect", { func = function(name, axis1, axis2, len) if axis1 == "get" then axis1 = worldeditadditions.player_axis2d(name) end - local pos1 = worldedit.pos1[name] - local p2 = vector.new(pos1) + local p2 = vector.new(worldedit.pos1[name]) p2[axis1[2]] = p2[axis1[2]] + tonumber(len) * axis1[1] p2[axis2[2]] = p2[axis2[2]] + tonumber(len) * axis2[1] From 12e5be8da69f27c505d30057eaaa8d0ea018080c Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Sun, 28 Feb 2021 11:59:46 -0800 Subject: [PATCH 11/11] stable axis1 processing --- .../commands/selectors/srect.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/worldeditadditions_commands/commands/selectors/srect.lua b/worldeditadditions_commands/commands/selectors/srect.lua index df7bf00..ee25709 100644 --- a/worldeditadditions_commands/commands/selectors/srect.lua +++ b/worldeditadditions_commands/commands/selectors/srect.lua @@ -11,9 +11,11 @@ function parse_params_srect(params_text) -- If ax1 is bad set to player facing dir if ax1 == len or not ax1:match('[xyz]') then ax1 = "get" + else local success, value = wea.getsign(ax1, "int") - if not success then return success, value end - else ax1 = { value, ax1:gsub('[^xyz]',''):sub(1,1) } + if not success then return success, value + else ax1 = { value, ax1:gsub('[^xyz]',''):sub(1,1) } + end end -- If ax2 is bad set to +y if not ax2 or ax2 == len or not ax2:match('[xyz]') then ax2 = "y" end @@ -54,3 +56,9 @@ worldedit.register_command("srect", { -- Tests -- /multi //fp set1 -63 19 -20 //srect 5 +-- /multi //fp set1 -63 19 -20 //srect z 5 +-- /multi //fp set1 -63 19 -20 //srect a z 5 +-- /multi //fp set1 -63 19 -20 //srect z a 5 +-- /multi //fp set1 -63 19 -20 //srect -z 5 +-- /multi //fp set1 -63 19 -20 //srect a -x 5 +-- /multi //fp set1 -63 19 -20 //srect -x -a 5