Upgrade all selection commands

This commit is contained in:
Starbeamrainbowlabs 2022-09-18 22:20:04 +01:00
parent c3e8df3a9e
commit 4a56d45c4b
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
16 changed files with 149 additions and 96 deletions

View File

@ -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])

View File

@ -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

View File

@ -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")

View File

@ -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,
})

View File

@ -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

View File

@ -1,18 +1,20 @@
local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
-- ███████ ██████ ██████ ██
-- ██ ██ ██ ██ ██
-- ███████ ██ ██ ██ ██
-- ██ ██ ██ ██ ██
-- ███████ ██████ ██████ ███████
local wea = worldeditadditions
worldeditadditions_core.register_command("scol", {
params = "[<axis1>] <length>",
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,
})

View File

@ -1,20 +1,22 @@
local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
-- ███████ ██████ ██ ██ ██████ ███████
-- ██ ██ ██ ██ ██ ██ ██
-- ███████ ██ ██ ██ ██████ █████
-- ██ ██ ██ ██ ██ ██ ██
-- ███████ ██████ ██████ ██████ ███████
local wea = worldeditadditions
worldeditadditions_core.register_command("scube", {
params = "[<axis1> [<axis2> [<axis3>]]] <length>",
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,
})

View File

@ -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 = "<mode> <factor> [<target=xz>]",
description = "Make the length of one or more target axes of the current selection to be multiple(s) of <factor>.",
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 \"<mode> <factor> [<target>]\"."
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 <target> \""..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[<axis>] / factor) * factor
-- Equation: round(delta[<axis>] / 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
})

View File

@ -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 = "<operation:odd|even|equal> <mode:grow|shrink|average> [<target=xyz> [<base>]]",
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 \"<operation> <mode> [<target=xyz> [<base>]]\"."
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 <target> \""..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> \""..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
})

View File

@ -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"

View File

@ -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"

View File

@ -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 = "[<axis1> [<axis2>]] <length>",
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,
})

View File

@ -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,
})

View File

@ -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 = "<axis1> <distance1> [<axis2> <distance2> [<axis3> <distance3>]]",
description = "Shift the WorldEdit region in 3 dimensions.",

View File

@ -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 ")

View File

@ -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.