From 38b55712cc631c5fbd81c9a6bbc863977c8b8d1b Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Sun, 15 Sep 2024 09:15:22 -0700 Subject: [PATCH] scentre, sshift stable + housekeeping --- .../commands/selectors/scentre.lua | 68 +++++++++---------- .../commands/selectors/sgrow.lua | 2 + .../commands/selectors/srect.lua | 1 - .../commands/selectors/sshift.lua | 43 +++--------- .../commands/selectors/sshrink.lua | 2 + 5 files changed, 48 insertions(+), 68 deletions(-) diff --git a/worldeditadditions_commands/commands/selectors/scentre.lua b/worldeditadditions_commands/commands/selectors/scentre.lua index af589ff..1d88b75 100644 --- a/worldeditadditions_commands/commands/selectors/scentre.lua +++ b/worldeditadditions_commands/commands/selectors/scentre.lua @@ -1,35 +1,33 @@ -local wea_c = worldeditadditions_core -local Vector3 = wea_c.Vector3 - --- ███████ ██████ ███████ ███ ██ ████████ ███████ ██████ --- ██ ██ ██ ████ ██ ██ ██ ██ ██ --- ███████ ██ █████ ██ ██ ██ ██ █████ ██████ --- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ --- ███████ ██████ ███████ ██ ████ ██ ███████ ██ ██ -worldeditadditions_core.register_command("scentre", { - params = "", - description = "Set WorldEdit region positions 1 and 2 to the centre of the current selection.", - privs = {worldedit=true}, - require_pos = 2, - parse = function(params_text) - return true - end, - func = function(name) - local mean = Vector3.mean( - Vector3.clone(worldedit.pos1[name]), - Vector3.clone(worldedit.pos2[name]) - ) - local pos1, pos2 = Vector3.clone(mean), Vector3.clone(mean) - - pos1 = pos1:floor() - pos2 = pos2:ceil() - - worldedit.pos1[name], worldedit.pos2[name] = pos1, pos2 - worldedit.mark_pos1(name) - worldedit.mark_pos2(name) - - return true, "position 1 set to "..pos1..", position 2 set to "..pos2 - end, -}) - --- lua print(vecs.mean.x..", "..vecs.mean.y..", "..vecs.mean.z) +local wea_c = worldeditadditions_core +local Vector3 = wea_c.Vector3 + +-- ███████ ██████ ███████ ███ ██ ████████ ███████ ██████ +-- ██ ██ ██ ████ ██ ██ ██ ██ ██ +-- ███████ ██ █████ ██ ██ ██ ██ █████ ██████ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ███████ ██████ ███████ ██ ████ ██ ███████ ██ ██ +worldeditadditions_core.register_command("scentre", { + params = "", + description = "Set WorldEdit region positions 1 and 2 to the centre of the current selection.", + privs = {worldedit=true}, + require_pos = 2, + parse = function(params_text) + return true + end, + func = function(name) + local mean = Vector3.mean( + Vector3.clone(wea_c.pos.get(name, 1)), + Vector3.clone(wea_c.pos.get(name, 2)) + ) + local pos1, pos2 = Vector3.clone(mean), Vector3.clone(mean) + + pos1 = pos1:floor() + pos2 = pos2:ceil() + + wea_c.pos.set_all(name, {pos1, pos2}) + + return true, "Pos1 set to "..pos1..", Pos2 set to "..pos2 + end, +}) + +-- lua print(vecs.mean.x..", "..vecs.mean.y..", "..vecs.mean.z) diff --git a/worldeditadditions_commands/commands/selectors/sgrow.lua b/worldeditadditions_commands/commands/selectors/sgrow.lua index f84a058..7cd48db 100644 --- a/worldeditadditions_commands/commands/selectors/sgrow.lua +++ b/worldeditadditions_commands/commands/selectors/sgrow.lua @@ -23,6 +23,8 @@ worldeditadditions_core.register_command("sgrow", { func = function(name, params_text) local facing = wea_c.player_dir(name) local min, max = wea_c.parse.directions(params_text, facing) + if not min then return false, max end + local pos1 = wea_c.pos.get(name, 1) local pos2 = wea_c.pos.get(name, 2) diff --git a/worldeditadditions_commands/commands/selectors/srect.lua b/worldeditadditions_commands/commands/selectors/srect.lua index ab67808..1333aa2 100644 --- a/worldeditadditions_commands/commands/selectors/srect.lua +++ b/worldeditadditions_commands/commands/selectors/srect.lua @@ -1,4 +1,3 @@ -local wea = worldeditadditions local wea_c = worldeditadditions_core local Vector3 = wea_c.Vector3 diff --git a/worldeditadditions_commands/commands/selectors/sshift.lua b/worldeditadditions_commands/commands/selectors/sshift.lua index 5ce1b54..e3894e2 100644 --- a/worldeditadditions_commands/commands/selectors/sshift.lua +++ b/worldeditadditions_commands/commands/selectors/sshift.lua @@ -1,4 +1,3 @@ -local wea = worldeditadditions local wea_c = worldeditadditions_core local Vector3 = worldeditadditions.Vector3 @@ -8,46 +7,26 @@ local Vector3 = worldeditadditions.Vector3 -- ██ ██ ██ ██ ██ ██ ██ -- ███████ ███████ ██ ██ ██ ██ ██ -local function parse_with_name(name,args) - local vec, tmp = Vector3.new(0, 0, 0), {} - local find, _, i = {}, 0, 0 - repeat - _, i, tmp.proc = args:find("([%l%s+-]+%d+)%s*", i) - if tmp.proc:match("[xyz]") then - tmp.ax = tmp.proc:match("[xyz]") - tmp.dir = tonumber(tmp.proc:match("[+-]?%d+")) * (tmp.proc:match("-%l+") and -1 or 1) - else - tmp.ax, _ = wea_c.dir_to_xyz(name, tmp.proc:match("%l+")) - if not tmp.ax then return false, _ end - tmp.dir = tonumber(tmp.proc:match("[+-]?%d+")) * (tmp.proc:match("-%l+") and -1 or 1) * _ - end - vec[tmp.ax] = tmp.dir - until not args:find("([%l%s+-]+%d+)%s*", i) - return true, vec -end - worldeditadditions_core.register_command("sshift", { - params = " [ [ ]]", + params = "[] [[] [...]]", description = "Shift the WorldEdit region in 3 dimensions.", privs = { worldedit = true }, require_pos = 2, parse = function(params_text) - if params_text:match("([%l%s+-]+%d+)") then return true, params_text - else return false, "No acceptable params found" end + local ret = wea_c.split(params_text) + if #ret < 1 then return false, "SSHIFT: No params found!" + else return true, ret end end, func = function(name, params_text) - local _, vec = parse_with_name(name,params_text) - if not _ then return false, vec end + local facing = wea_c.player_dir(name) + local vec, err = wea_c.parse.directions(params_text, facing, true) + if not vec then return false, err end - local pos1 = vec:add(worldedit.pos1[name]) - worldedit.pos1[name] = pos1 - worldedit.mark_pos1(name) + local pos1 = vec:add(wea_c.pos.get(name, 1)) + local pos2 = vec:add(wea_c.pos.get(name, 2)) - local pos2 = vec:add(worldedit.pos2[name]) - worldedit.pos2[name] = pos2 - worldedit.mark_pos2(name) - - return true, "Region shifted by " .. (vec.x + vec.y + vec.z) .. " nodes." + wea_c.pos.set_all(name, {pos1, pos2}) + return true, "Pos1 set to "..pos1..", Pos2 set to "..pos2 end, }) diff --git a/worldeditadditions_commands/commands/selectors/sshrink.lua b/worldeditadditions_commands/commands/selectors/sshrink.lua index db27973..923faa9 100644 --- a/worldeditadditions_commands/commands/selectors/sshrink.lua +++ b/worldeditadditions_commands/commands/selectors/sshrink.lua @@ -23,6 +23,8 @@ worldeditadditions_core.register_command("sshrink", { func = function(name, params_text) local facing = wea_c.player_dir(name) local min, max = wea_c.parse.directions(params_text, facing) + if not min then return false, max end + local pos1 = wea_c.pos.get(name, 1) local pos2 = wea_c.pos.get(name, 2)