From 4a56d45c4b953ef3edb2db75534a446d6277160c Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Sun, 18 Sep 2022 22:20:04 +0100 Subject: [PATCH] Upgrade all selection commands --- .../lib/selection/selection.lua | 12 ++++++--- worldeditadditions/lib/selection/stack.lua | 9 +++++-- .../commands/selectors/init.lua | 26 +++++++++---------- .../commands/selectors/scentre.lua | 20 ++++++++------ .../commands/selectors/scloud.lua | 7 +++-- .../commands/selectors/scol.lua | 18 +++++++------ .../commands/selectors/scube.lua | 20 +++++++------- .../commands/selectors/sfactor.lua | 26 +++++++++++-------- .../commands/selectors/smake.lua | 26 +++++++++++-------- .../commands/selectors/spop.lua | 9 ++++--- .../commands/selectors/spush.lua | 12 ++++++--- .../commands/selectors/srect.lua | 17 +++++++----- .../commands/selectors/srel.lua | 20 ++++++++------ .../commands/selectors/sshift.lua | 12 ++++++--- .../commands/selectors/sstack.lua | 9 ++++--- worldeditadditions_core/utils/player.lua | 2 +- 16 files changed, 149 insertions(+), 96 deletions(-) diff --git a/worldeditadditions/lib/selection/selection.lua b/worldeditadditions/lib/selection/selection.lua index c4fdc0c..7d526d8 100644 --- a/worldeditadditions/lib/selection/selection.lua +++ b/worldeditadditions/lib/selection/selection.lua @@ -1,3 +1,5 @@ +local wea_c = worldeditadditions_core +local Vector3 = wea_c.Vector3 -- ███████ ███████ ██ ███████ ██████ ████████ ██ ██████ ███ ██ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ -- ███████ █████ ██ █████ ██ ██ ██ ██ ██ ██ ██ ██ @@ -15,14 +17,18 @@ function selection.add_point(name, pos) if pos ~= nil then local created_new = not worldedit.pos1[name] or not worldedit.pos2[name] -- print("[set_pos1]", name, "("..pos.x..", "..pos.y..", "..pos.z..")") - if not worldedit.pos1[name] then worldedit.pos1[name] = vector.new(pos) end - if not worldedit.pos2[name] then worldedit.pos2[name] = vector.new(pos) end + if not worldedit.pos1[name] then worldedit.pos1[name] = Vector3.new(pos) end + if not worldedit.pos2[name] then worldedit.pos2[name] = Vector3.new(pos) end worldedit.marker_update(name) local volume_before = worldedit.volume(worldedit.pos1[name], worldedit.pos2[name]) - worldedit.pos1[name], worldedit.pos2[name] = worldeditadditions.vector.expand_region(worldedit.pos1[name], worldedit.pos2[name], pos) + worldedit.pos1[name], worldedit.pos2[name] = Vector3.expand_region( + Vector3.new(worldedit.pos1[name]), + Vector3.new(worldedit.pos2[name]), + pos + ) local volume_after = worldedit.volume(worldedit.pos1[name], worldedit.pos2[name]) diff --git a/worldeditadditions/lib/selection/stack.lua b/worldeditadditions/lib/selection/stack.lua index 7ef7a0d..af6ff6c 100644 --- a/worldeditadditions/lib/selection/stack.lua +++ b/worldeditadditions/lib/selection/stack.lua @@ -1,3 +1,6 @@ +local wea_c = worldeditadditions_core +local Vector3 = wea_c.Vector3 + --- Holds the per-user selection stacks. worldeditadditions.sstack = {} @@ -17,9 +20,11 @@ end --- Inserts a selection region onto the stack for the user with the given name. -- Stacks are per-user. -- @param name string The name of the user to insert onto. --- @param pos1 Vector Position 1 --- @param pos2 Vector Position 2 +-- @param pos1 Vector3 Position 1 +-- @param pos2 Vector3 Position 2 function worldeditadditions.spush(name, pos1, pos2) + pos1 = Vector3.clon(pos1) + pos2 = Vector3.clon(pos2) if not worldeditadditions.sstack[name] then worldeditadditions.sstack[name] = {} end diff --git a/worldeditadditions_commands/commands/selectors/init.lua b/worldeditadditions_commands/commands/selectors/init.lua index fd60556..5a82a5d 100644 --- a/worldeditadditions_commands/commands/selectors/init.lua +++ b/worldeditadditions_commands/commands/selectors/init.lua @@ -6,20 +6,20 @@ -- Chat commands that operate on selections. -local we_cm = worldeditadditions_commands.modpath .. "/commands/selectors/" +local we_cmdpath = worldeditadditions_commands.modpath .. "/commands/selectors/" -dofile(we_cm.."srel.lua") -dofile(we_cm.."scentre.lua") -dofile(we_cm.."scloud.lua") -dofile(we_cm.."scol.lua") -dofile(we_cm.."scube.lua") -dofile(we_cm.."sfactor.lua") -dofile(we_cm.."smake.lua") -dofile(we_cm.."spop.lua") -dofile(we_cm.."spush.lua") -dofile(we_cm.."srect.lua") -dofile(we_cm.."sshift.lua") -dofile(we_cm.."sstack.lua") +dofile(we_cmdpath.."srel.lua") +dofile(we_cmdpath.."scentre.lua") +dofile(we_cmdpath.."scloud.lua") +dofile(we_cmdpath.."scol.lua") +dofile(we_cmdpath.."scube.lua") +dofile(we_cmdpath.."sfactor.lua") +dofile(we_cmdpath.."smake.lua") +dofile(we_cmdpath.."spop.lua") +dofile(we_cmdpath.."spush.lua") +dofile(we_cmdpath.."srect.lua") +dofile(we_cmdpath.."sshift.lua") +dofile(we_cmdpath.."sstack.lua") -- Aliases worldedit.alias_command("sfac", "sfactor") diff --git a/worldeditadditions_commands/commands/selectors/scentre.lua b/worldeditadditions_commands/commands/selectors/scentre.lua index 3588c2e..d677c7c 100644 --- a/worldeditadditions_commands/commands/selectors/scentre.lua +++ b/worldeditadditions_commands/commands/selectors/scentre.lua @@ -1,9 +1,11 @@ +local wea_c = worldeditadditions_core +local Vector3 = wea_c.Vector3 + -- ███████ ██████ ███████ ███ ██ ████████ ███████ ██████ -- ██ ██ ██ ████ ██ ██ ██ ██ ██ -- ███████ ██ █████ ██ ██ ██ ██ █████ ██████ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ███████ ██████ ███████ ██ ████ ██ ███████ ██ ██ -local wea = worldeditadditions worldeditadditions_core.register_command("scentre", { params = "", description = "Set WorldEdit region positions 1 and 2 to the centre of the current selection.", @@ -13,15 +15,17 @@ worldeditadditions_core.register_command("scentre", { return true end, func = function(name) - local vecs = {} - vecs.mean = wea.vector.mean(worldedit.pos1[name],worldedit.pos2[name]) - vecs.p1, vecs.p2 = vector.new(vecs.mean), vector.new(vecs.mean) - wea.vector.floor(vecs.p1) - wea.vector.ceil(vecs.p2) - worldedit.pos1[name], worldedit.pos2[name] = vecs.p1, vecs.p2 + local mean = wea_c.vector.mean(worldedit.pos1[name],worldedit.pos2[name]) + local pos1, pos2 = Vector3.new(mean), Vector3.new(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 " .. minetest.pos_to_string(vecs.p1) .. ", position 2 set to " .. minetest.pos_to_string(vecs.p2) + + return true, "position 1 set to "..pos1..", position 2 set to "..pos2 end, }) diff --git a/worldeditadditions_commands/commands/selectors/scloud.lua b/worldeditadditions_commands/commands/selectors/scloud.lua index 6bbe23f..07289b1 100644 --- a/worldeditadditions_commands/commands/selectors/scloud.lua +++ b/worldeditadditions_commands/commands/selectors/scloud.lua @@ -1,14 +1,17 @@ +local wea = worldeditadditions +local wea_c = worldeditadditions_core +local Vector3 = wea_c.Vector3 + -- ██████ ██████ ██ ██████ ██ ██ ██████ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ███████ ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██████ ██████ ███████ ██████ ██████ ██████ -local wea = worldeditadditions minetest.register_on_punchnode(function(pos, node, puncher) local name = puncher:get_player_name() if name ~= "" and wea.add_pos[name] ~= nil then if wea.add_pos[name] > 0 then - wea.selection.add_point(name,pos) + wea.selection.add_point(name, pos) wea.add_pos[name] = wea.add_pos[name] - 1 worldedit.player_notify(name, "You have "..wea.add_pos[name].." nodes left to punch") else wea.add_pos[name] = nil end diff --git a/worldeditadditions_commands/commands/selectors/scol.lua b/worldeditadditions_commands/commands/selectors/scol.lua index 051472c..1ada5ac 100644 --- a/worldeditadditions_commands/commands/selectors/scol.lua +++ b/worldeditadditions_commands/commands/selectors/scol.lua @@ -1,18 +1,20 @@ +local wea_c = worldeditadditions_core +local Vector3 = wea_c.Vector3 + -- ███████ ██████ ██████ ██ -- ██ ██ ██ ██ ██ -- ███████ ██ ██ ██ ██ -- ██ ██ ██ ██ ██ -- ███████ ██████ ██████ ███████ -local wea = worldeditadditions worldeditadditions_core.register_command("scol", { params = "[] ", description = "Set WorldEdit region position 2 at a set distance along 1 axis.", privs = {worldedit=true}, require_pos = 1, parse = function(params_text) - local vec, tmp = vector.new(0, 0, 0), {} - local find = wea.split(params_text, "%s", false) - local ax1, sn1, len = (tostring(find[1]):match('[xyz]') or "g"):sub(1,1), wea.getsign(find[1]), find[table.maxn(find)] + local vec, tmp = Vector3.new(0, 0, 0), {} + local find = wea_c.split(params_text, "%s", false) + local ax1, sn1, len = (tostring(find[1]):match('[xyz]') or "g"):sub(1,1), wea_c.getsign(find[1]), find[table.maxn(find)] tmp.len = tonumber(len) -- If len == nil cancel the operation @@ -28,14 +30,14 @@ worldeditadditions_core.register_command("scol", { end, func = function(name, vec, tmp) if tmp.get then - local ax, dir = wea.player_axis2d(name) + local ax, dir = wea_c.player_axis2d(name) vec[ax] = tmp.len * dir end - local p2 = vector.add(vec,worldedit.pos1[name]) - worldedit.pos2[name] = p2 + local pos2 = vec + Vector3.clone(worldedit.pos1[name]) + worldedit.pos2[name] = pos2 worldedit.mark_pos2(name) - return true, "position 2 set to " .. minetest.pos_to_string(p2) + return true, "position 2 set to "..pos2 end, }) diff --git a/worldeditadditions_commands/commands/selectors/scube.lua b/worldeditadditions_commands/commands/selectors/scube.lua index 8f4ac8b..0c7df3e 100644 --- a/worldeditadditions_commands/commands/selectors/scube.lua +++ b/worldeditadditions_commands/commands/selectors/scube.lua @@ -1,20 +1,22 @@ +local wea_c = worldeditadditions_core +local Vector3 = wea_c.Vector3 + -- ███████ ██████ ██ ██ ██████ ███████ -- ██ ██ ██ ██ ██ ██ ██ -- ███████ ██ ██ ██ ██████ █████ -- ██ ██ ██ ██ ██ ██ ██ -- ███████ ██████ ██████ ██████ ███████ -local wea = worldeditadditions worldeditadditions_core.register_command("scube", { params = "[ [ []]] ", description = "Set WorldEdit region position 2 at a set distance along 3 axes.", privs = { worldedit = true }, require_pos = 1, parse = function(params_text) - local vec, tmp = vector.new(0, 0, 0), {} - local find = wea.split(params_text, "%s", false) + local vec, tmp = Vector3.new(0, 0, 0), {} + local find = wea_c.split(params_text, "%s", false) local ax1, ax2, ax3 = (tostring(find[1]):match('[xyz]') or "g"):sub(1,1), (tostring(find[2]):match('[xyz]') or "g"):sub(1,1), (tostring(find[3]):match('[xyz]') or "g"):sub(1,1) - local sn1, sn2, sn3, len = wea.getsign(find[1]), wea.getsign(find[2]), wea.getsign(find[3]), find[table.maxn(find)] + local sn1, sn2, sn3, len = wea_c.getsign(find[1]), wea_c.getsign(find[2]), wea_c.getsign(find[3]), find[table.maxn(find)] tmp.len = tonumber(len) -- If len is nill cancel the operation @@ -36,17 +38,17 @@ worldeditadditions_core.register_command("scube", { end, func = function(name, vec, tmp) if tmp.get then - local ax, dir = wea.player_axis2d(name) - local _, left, sn = wea.axis_left(ax,dir) + local ax, dir = wea_c.player_axis2d(name) + local _, left, sn = wea_c.axis_left(ax,dir) if not tmp.axes:find("x") then vec.x = tmp.len * (ax == "x" and dir or sn) end if not tmp.axes:find("z") then vec.z = tmp.len * (ax == "z" and dir or sn) end if not tmp.axes:find("y") then vec.y = tmp.len end end - local p2 = vector.add(vec,worldedit.pos1[name]) - worldedit.pos2[name] = p2 + local pos2 = vec + Vector3.clone(worldedit.pos1[name]) + worldedit.pos2[name] = pos2 worldedit.mark_pos2(name) - return true, "position 2 set to " .. minetest.pos_to_string(p2) + return true, "position 2 set to "..pos2 end, }) diff --git a/worldeditadditions_commands/commands/selectors/sfactor.lua b/worldeditadditions_commands/commands/selectors/sfactor.lua index a70f017..4c86408 100644 --- a/worldeditadditions_commands/commands/selectors/sfactor.lua +++ b/worldeditadditions_commands/commands/selectors/sfactor.lua @@ -1,22 +1,26 @@ +local wea = worldeditadditions +local wea_c = worldeditadditions_core +local Vector3 = wea_c.Vector3 + + -- ███████ ███████ █████ ██████ ████████ ██████ ██████ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ███████ █████ ███████ ██ ██ ██ ██ ██████ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ███████ ██ ██ ██ ██████ ██ ██████ ██ ██ -local wea = worldeditadditions 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 }, require_pos = 2, parse = function(params_text) - local parts = wea.split(params_text, "%s+", false) + local parts = wea_c.split(params_text, "%s+", false) if #parts < 2 then return false, "Error: Not enough arguments. Expected \" []\"." end - local mode, fac, targ = unpack(parts) - local modeSet = wea.table.makeset {"grow", "shrink", "avg"} + local mode, fac, targ = wea_c.table.unpack(parts) + local modeSet = wea_c.table.makeset {"grow", "shrink", "avg"} -- Mode parsing if mode == "average" then -- If mode is average set to avg @@ -39,7 +43,7 @@ worldeditadditions_core.register_command("sfactor", { if not targ then -- If no target set to default (xz) targ = "xz" elseif targ:match("[xyz]+") then -- ensure correct target syntax - targ = table.concat(wea.tochars(targ:match("[xyz]+"),true,true)) + targ = table.concat(wea_c.tochars(targ:match("[xyz]+"),true,true)) else return false, "Error: Invalid \""..targ.."\". Expected \"x\" and or \"y\" and or \"z\"." end @@ -47,10 +51,10 @@ worldeditadditions_core.register_command("sfactor", { return true, mode, fac, targ end, func = function(name, mode, fac, targ) - local p1, p2 = vector.new(worldedit.pos1[name]), vector.new(worldedit.pos2[name]) - local delta = vector.subtract(p2,p1) -- local delta equation: Vd(a) = V2(a) - V1(a) + local pos1, pos2 = Vector3.clone(worldedit.pos1[name]), Vector3.clone(worldedit.pos2[name]) + local delta = pos2 - pos1 -- local delta equation: Vd(a) = V2(a) - V1(a) local _tl = #targ -- Get targ length as a variable incase mode is "average"/"avg" - local targ = wea.tocharset(targ) -- Break up targ string into set table + local targ = wea_c.tocharset(targ) -- Break up targ string into set table local _m = 0 -- _m is the container to hold the average of the axes in targ -- set _m to the max, min or mean of the target axes depending on mode (_tl is the length of targ) or base if it exists @@ -59,7 +63,7 @@ worldeditadditions_core.register_command("sfactor", { _m = _m / _tl end - -- Equasion: round(delta[] / factor) * factor + -- Equation: round(delta[] / factor) * factor local eval = function(int,fac_inner) local tmp, abs, neg = int / fac_inner, math.abs(int), int < 0 @@ -76,8 +80,8 @@ worldeditadditions_core.register_command("sfactor", { for k,v in pairs(targ) do delta[k] = eval(delta[k],fac) end - worldedit.pos2[name] = vector.add(p1,delta) + worldedit.pos2[name] = pos1 + delta worldedit.mark_pos2(name) - return true, "position 2 set to " .. minetest.pos_to_string(p2) + return true, "position 2 set to "..pos2 end }) diff --git a/worldeditadditions_commands/commands/selectors/smake.lua b/worldeditadditions_commands/commands/selectors/smake.lua index dfc99f1..91ba3e0 100644 --- a/worldeditadditions_commands/commands/selectors/smake.lua +++ b/worldeditadditions_commands/commands/selectors/smake.lua @@ -1,9 +1,13 @@ +local wea = worldeditadditions +local wea_c = worldeditadditions_core +local Vector3 = wea_c.Vector3 + + -- ███████ ███ ███ █████ ██ ██ ███████ -- ██ ████ ████ ██ ██ ██ ██ ██ -- ███████ ██ ████ ██ ███████ █████ █████ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ███████ ██ ██ ██ ██ ██ ██ ███████ -local wea = worldeditadditions worldeditadditions_core.register_command("smake", { params = " [ []]", description = "Make one or more axes of the current selection odd, even, or equal to another.", @@ -11,7 +15,7 @@ worldeditadditions_core.register_command("smake", { require_pos = 2, parse = function(params_text) -- Split params_text, check for missing arguments and fill in empty spots - local parts = wea.split(params_text, "%s+", false) + local parts = wea_c.split(params_text, "%s+", false) if #parts < 2 then return false, "Error: Not enough arguments. Expected \" [ []]\"." else @@ -19,8 +23,8 @@ worldeditadditions_core.register_command("smake", { end -- Initialize local variables and sets - local oper, mode, targ, base = wea.table.unpack(parts) - local operSet, modeSet = wea.table.makeset {"equal", "odd", "even"}, wea.table.makeset {"grow", "shrink", "avg"} + local oper, mode, targ, base = wea_c.table.unpack(parts) + local operSet, modeSet = wea_c.table.makeset {"equal", "odd", "even"}, wea_c.table.makeset {"grow", "shrink", "avg"} -- Main Logic -- Check base if base is present and if so valid. @@ -36,7 +40,7 @@ worldeditadditions_core.register_command("smake", { if not targ then -- If no target set to default (xz) targ = "xz" elseif targ:match("[xyz]+") then -- ensure correct target syntax - targ = table.concat(wea.tochars(targ:match("[xyz]+"),true,true)) + targ = table.concat(wea_c.tochars(targ:match("[xyz]+"),true,true)) else return false, "Error: Invalid \""..targ.."\". Expected \"x\" and or \"y\" and or \"z\"." end @@ -44,7 +48,7 @@ worldeditadditions_core.register_command("smake", { if mode == "average" then -- If mode is average set to avg mode = "avg" elseif mode:match("[xyz]+") then -- If target is actually base set vars to correct values. - base, targ, mode = targ:sub(1,1), table.concat(wea.tochars(mode:match("[xyz]+"),true,true)), false + base, targ, mode = targ:sub(1,1), table.concat(wea_c.tochars(mode:match("[xyz]+"),true,true)), false elseif not modeSet[mode] and not base then -- If mode is invalid and base isn't present throw error return false, "Error: Invalid \""..mode.."\". Expected \"grow\", \"shrink\", or \"average\"/\"avg\"." end @@ -64,12 +68,12 @@ worldeditadditions_core.register_command("smake", { return true, oper, mode, targ, base end, func = function(name, oper, mode, targ, base) - local p1, p2 = vector.new(worldedit.pos1[name]), vector.new(worldedit.pos2[name]) + local pos1, pos2 = Vector3.clone(worldedit.pos1[name]), Vector3.clone(worldedit.pos2[name]) local eval -- Declare eval placeholder function to edit later - local delta = vector.subtract(p2,p1) -- local delta equation: Vd(a) = V2(a) - V1(a) + local delta = pos2 - pos1 -- local delta equation: Vd(a) = V2(a) - V1(a) local _tl = #targ -- Get targ length as a variable incase mode is "average"/"avg" - local targ = wea.tocharset(targ) -- Break up targ string into set table + local targ = wea_c.tocharset(targ) -- Break up targ string into set table local _m = 0 -- _m is the container to hold the max, min or average (depending on the mode) of the axes in targ -- set _m to the max, min or mean of the target axes depending on mode or base if it exists @@ -122,8 +126,8 @@ worldeditadditions_core.register_command("smake", { for k,v in pairs(targ) do delta[k] = eval(delta[k]) end - worldedit.pos2[name] = vector.add(p1,delta) + worldedit.pos2[name] = pos1 + delta worldedit.mark_pos2(name) - return true, "position 2 set to " .. minetest.pos_to_string(p2) + return true, "position 2 set to "..pos2 end }) diff --git a/worldeditadditions_commands/commands/selectors/spop.lua b/worldeditadditions_commands/commands/selectors/spop.lua index a982367..231a5b4 100644 --- a/worldeditadditions_commands/commands/selectors/spop.lua +++ b/worldeditadditions_commands/commands/selectors/spop.lua @@ -1,3 +1,6 @@ +local wea = worldeditadditions + + -- ███████ ██████ ██████ ██████ -- ██ ██ ██ ██ ██ ██ ██ -- ███████ ██████ ██ ██ ██████ @@ -14,18 +17,18 @@ worldeditadditions_core.register_command("spop", { return 0 end, func = function(name) - local success, pos1, pos2 = worldeditadditions.spop(name) + local success, pos1, pos2 = wea.spop(name) if not success then return success, pos1 end worldedit.pos1[name] = pos1 worldedit.pos2[name] = pos2 worldedit.marker_update(name) - local new_count = worldeditadditions.scount(name) + local new_count = wea.scount(name) local plural = "s are" if new_count == 1 then plural = " is" end - local region_text = worldeditadditions.vector.tostring(worldedit.pos1[name]).." - "..worldeditadditions.vector.tostring(worldedit.pos2[name]) + local region_text = pos1.." - "..pos2 minetest.log("action", name .. " used //spopped at "..region_text..". Stack height is now " .. new_count.." regions") return true, "Region "..region_text.." popped from selection stack; "..new_count.." region"..plural.." now in the stack" diff --git a/worldeditadditions_commands/commands/selectors/spush.lua b/worldeditadditions_commands/commands/selectors/spush.lua index 52cd62f..99cdf00 100644 --- a/worldeditadditions_commands/commands/selectors/spush.lua +++ b/worldeditadditions_commands/commands/selectors/spush.lua @@ -1,3 +1,7 @@ +local wea = worldeditadditions +local wea_c = worldeditadditions_core +local Vector3 = wea_c.Vector3 + -- ███████ ██████ ██ ██ ███████ ██ ██ -- ██ ██ ██ ██ ██ ██ ██ ██ -- ███████ ██████ ██ ██ ███████ ███████ @@ -15,16 +19,18 @@ worldeditadditions_core.register_command("spush", { return 0 end, func = function(name) - local success, msg = worldeditadditions.spush(name, worldedit.pos1[name], worldedit.pos2[name]) + local pos1 = Vector3.clone(worldedit.pos1[name]) + local pos2 = Vector3.clone(worldedit.pos2[name]) + local success, msg = wea.spush(name, pos1, pos2) if not success then return success, msg end - local new_count = worldeditadditions.scount(name) + local new_count = wea.scount(name) local plural = "s are" if new_count == 1 then plural = " is" end - local region_text = worldeditadditions.vector.tostring(worldedit.pos1[name]).." - "..worldeditadditions.vector.tostring(worldedit.pos2[name]) + local region_text = pos1.." - "..pos2 minetest.log("action", name .. " used //spush at "..region_text..". Stack height is now " .. new_count.." regions") return true, "Region "..region_text.." pushed onto selection stack; "..new_count.." region"..plural.." now in the stack" diff --git a/worldeditadditions_commands/commands/selectors/srect.lua b/worldeditadditions_commands/commands/selectors/srect.lua index 85534cc..a4209d9 100644 --- a/worldeditadditions_commands/commands/selectors/srect.lua +++ b/worldeditadditions_commands/commands/selectors/srect.lua @@ -1,19 +1,22 @@ +local wea = worldeditadditions +local wea_c = worldeditadditions_core +local Vector3 = wea_c.Vector3 + -- ███████ ██████ ███████ ██████ ████████ -- ██ ██ ██ ██ ██ ██ -- ███████ ██████ █████ ██ ██ -- ██ ██ ██ ██ ██ ██ -- ███████ ██ ██ ███████ ██████ ██ -local wea = worldeditadditions worldeditadditions_core.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 vec, tmp = vector.new(0, 0, 0), {} - local find = wea.split(params_text, "%s", false) + local vec, tmp = Vector3.new(0, 0, 0), {} + local find = wea_c.split(params_text, "%s", false) local ax1, ax2 = (tostring(find[1]):match('[xyz]') or "g"):sub(1,1), (tostring(find[2]):match('[xyz]') or "g"):sub(1,1) - local sn1, sn2, len = wea.getsign(find[1]), wea.getsign(find[2]), find[table.maxn(find)] + local sn1, sn2, len = wea_c.getsign(find[1]), wea_c.getsign(find[2]), find[table.maxn(find)] tmp.len = tonumber(len) -- If len == nill cancel the operation @@ -33,15 +36,15 @@ worldeditadditions_core.register_command("srect", { end, func = function(name, vec, tmp) if tmp.get then - local ax, dir = wea.player_axis2d(name) + local ax, dir = wea_c.player_axis2d(name) if not tmp.axes:find("[xz]") then vec[ax] = tmp.len * dir end if not tmp.axes:find("y") then vec.y = tmp.len end end - local p2 = vector.add(vec,worldedit.pos1[name]) + local p2 = vec + Vector3.clone(worldedit.pos1[name]) worldedit.pos2[name] = p2 worldedit.mark_pos2(name) - return true, "position 2 set to " .. minetest.pos_to_string(p2) + return true, "position 2 set to "..p2 end, }) diff --git a/worldeditadditions_commands/commands/selectors/srel.lua b/worldeditadditions_commands/commands/selectors/srel.lua index 1a01e42..75d30d3 100644 --- a/worldeditadditions_commands/commands/selectors/srel.lua +++ b/worldeditadditions_commands/commands/selectors/srel.lua @@ -1,11 +1,15 @@ +local wea = worldeditadditions +local wea_c = worldeditadditions_core +local Vector3 = wea_c.Vector3 + + -- ███████ ██████ ███████ ██ -- ██ ██ ██ ██ ██ -- ███████ ██████ █████ ██ -- ██ ██ ██ ██ ██ -- ███████ ██ ██ ███████ ███████ -local wea = worldeditadditions local function parse_with_name(name,args) - local vec, tmp = vector.new(0, 0, 0), {} + local vec, tmp = Vector3.new(0, 0, 0), {} local find, _, i = {}, 0, 0 repeat _, i, tmp.proc = args:find("([%l%s+-]+%d+)%s*", i) @@ -13,7 +17,7 @@ local function parse_with_name(name,args) 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.dir_to_xyz(name, tmp.proc:match("%l+")) + 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 @@ -36,17 +40,17 @@ worldeditadditions_core.register_command("srel", { if not _ then return false, vec end if not worldedit.pos1[name] then - local pos = vector.add(wea.player_vector(name), vector.new(0.5,-0.5,0.5)) - wea.vector.floor(pos) + local pos = wea_c.player_vector(name) + Vector3.new(0.5, -0.5, 0.5) + pos = pos:floor() worldedit.pos1[name] = pos worldedit.mark_pos1(name) - ret = "position 1 set to " .. minetest.pos_to_string(pos) .. ", " + ret = "position 1 set to "..pos..", " end - local p2 = vector.add(vec,worldedit.pos1[name]) + local p2 = vec + Vector3.clone(worldedit.pos1[name]) worldedit.pos2[name] = p2 worldedit.mark_pos2(name) - return true, ret .. "position 2 set to " .. minetest.pos_to_string(p2) + return true, ret.."position 2 set to "..p2 end, }) diff --git a/worldeditadditions_commands/commands/selectors/sshift.lua b/worldeditadditions_commands/commands/selectors/sshift.lua index 82bc138..5ce1b54 100644 --- a/worldeditadditions_commands/commands/selectors/sshift.lua +++ b/worldeditadditions_commands/commands/selectors/sshift.lua @@ -1,12 +1,15 @@ +local wea = worldeditadditions +local wea_c = worldeditadditions_core +local Vector3 = worldeditadditions.Vector3 + -- ███████ ███████ ██ ██ ██ ███████ ████████ -- ██ ██ ██ ██ ██ ██ ██ -- ███████ ███████ ███████ ██ █████ ██ -- ██ ██ ██ ██ ██ ██ ██ -- ███████ ███████ ██ ██ ██ ██ ██ -local wea = worldeditadditions -local v3 = worldeditadditions.Vector3 + local function parse_with_name(name,args) - local vec, tmp = v3.new(0, 0, 0), {} + local vec, tmp = Vector3.new(0, 0, 0), {} local find, _, i = {}, 0, 0 repeat _, i, tmp.proc = args:find("([%l%s+-]+%d+)%s*", i) @@ -14,7 +17,7 @@ local function parse_with_name(name,args) 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.dir_to_xyz(name, tmp.proc:match("%l+")) + 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 @@ -22,6 +25,7 @@ local function parse_with_name(name,args) until not args:find("([%l%s+-]+%d+)%s*", i) return true, vec end + worldeditadditions_core.register_command("sshift", { params = " [ [ ]]", description = "Shift the WorldEdit region in 3 dimensions.", diff --git a/worldeditadditions_commands/commands/selectors/sstack.lua b/worldeditadditions_commands/commands/selectors/sstack.lua index 82d486c..bec6a66 100644 --- a/worldeditadditions_commands/commands/selectors/sstack.lua +++ b/worldeditadditions_commands/commands/selectors/sstack.lua @@ -1,3 +1,5 @@ +local wea_c = worldeditadditions_core + -- ███████ ███████ ████████ █████ ██████ ██ ██ -- ██ ██ ██ ██ ██ ██ ██ ██ -- ███████ ███████ ██ ███████ ██ █████ @@ -20,8 +22,9 @@ worldeditadditions_core.register_command("sstack", { table.insert(result, "(empty)") else for i,item in ipairs(worldeditadditions.sstack[name]) do + -- TODO: Implement a volume command.... local volume = worldedit.volume(item[1], item[2]) - local volume_text = worldeditadditions.format.human_size(volume, 2) + local volume_text = wea_c.format.human_size(volume, 2) if volume > 1000 then volume_text = "~"..volume_text end table.insert(result, i) @@ -29,9 +32,9 @@ worldeditadditions_core.register_command("sstack", { table.insert(result, volume_text) table.insert(result, " nodes - ") - table.insert(result, worldeditadditions.vector.tostring(item[1])) + table.insert(result, tostring(item[1])) -- Vector3 instance table.insert(result, " - ") - table.insert(result, worldeditadditions.vector.tostring(item[2])) + table.insert(result, tostring(item[2])) -- Vector3 instance table.insert(result, "\n") end table.insert(result, "========================\nTotal ") diff --git a/worldeditadditions_core/utils/player.lua b/worldeditadditions_core/utils/player.lua index af2b6e5..bf215c7 100644 --- a/worldeditadditions_core/utils/player.lua +++ b/worldeditadditions_core/utils/player.lua @@ -4,7 +4,7 @@ local v3 = worldeditadditions_core.Vector3 -- @param name string The name of the player to return facing direction of. -- @return vector Returns position. function wea_c.player_vector(name) - return minetest.get_player_by_name(name):get_pos() + return v3.clone(minetest.get_player_by_name(name):get_pos()) end --- Returns the player's facing info including relative DIRs.