sgrow, srel, sshrink UNSTABLE

This commit is contained in:
VorTechnix 2024-09-12 15:05:57 -07:00
parent 78c418cb24
commit 4dacd10597
No known key found for this signature in database
GPG key ID: 091E91A69545D5BA
4 changed files with 118 additions and 59 deletions

View file

@ -9,13 +9,15 @@
local wea_cmdpath = worldeditadditions_commands.modpath .. "/commands/selectors/"
local weac = worldeditadditions_core
dofile(wea_cmdpath.."srel.lua")
dofile(wea_cmdpath.."scentre.lua")
dofile(wea_cmdpath.."scloud.lua")
dofile(wea_cmdpath.."sgrow.lua")
dofile(wea_cmdpath.."smake.lua")
dofile(wea_cmdpath.."spop.lua")
dofile(wea_cmdpath.."spush.lua")
dofile(wea_cmdpath.."srel.lua")
dofile(wea_cmdpath.."sshift.lua")
dofile(wea_cmdpath.."sshrink.lua")
dofile(wea_cmdpath.."sstack.lua")
--- DEPRECATED ---

View file

@ -0,0 +1,40 @@
-- local wea = worldeditadditions
local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
-- ███████ ██████ ██████ ██████ ██ ██
-- ██ ██ ██ ██ ██ ██ ██ ██
-- ███████ ██ ███ ██████ ██ ██ ██ █ ██
-- ██ ██ ██ ██ ██ ██ ██ ██ ███ ██
-- ███████ ██████ ██ ██ ██████ ███ ███
worldeditadditions_core.register_command("srel", {
params = "[<axis1>] <length1> [[<axis2>] <length2> [...]]",
description = "Set WorldEdit region position 2 relative to position 1 and player facing.",
privs = { worldedit = true },
require_pos = 0,
parse = function(params_text)
local ret = wea_c.split(params_text)
if #ret < 1 then return false, "SREL: No params found!"
else return true, ret end
end,
func = function(name, params_text)
local facing = wea_c.player_dir(name)
local min, max = wea_c.parse.directions(params_text, facing)
local pos1 = wea_c.pos.get(name, 1)
local pos2 = wea_c.pos.get(name, 2)
if not pos2 then wea_c.pos.set(name, 2, pos1)
else pos1, pos2 = Vector3.sort(pos1, pos2) end
pos1, pos2 = pos1:add(min), pos1:add(max)
wea_c.pos.set_all(name, {pos1, pos2})
return true, "Pos1 set to "..pos1..", Pos2 set to "..pos2
end,
})
-- Tests
-- //srel front 5 left 3 y 2

View file

@ -1,4 +1,4 @@
local wea = worldeditadditions
-- local wea = worldeditadditions
local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
@ -8,49 +8,26 @@ local Vector3 = wea_c.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("srel", {
params = "<axis1> <length1> [<axis2> <length2> [<axis3> <length3>]]",
description = "Set WorldEdit region position 2 at set distances along 3 axes.",
params = "[<axis1>] <length1> [[<axis2>] <length2> [...]]",
description = "Set WorldEdit region position 2 relative to position 1 and player facing.",
privs = { worldedit = true },
require_pos = 0,
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, "SREL: No params found!"
else return true, ret end
end,
func = function(name, params_text)
local ret = ""
local _, vec = parse_with_name(name,params_text)
if not _ then return false, vec end
local facing = wea_c.player_dir(name)
local vec = wea_c.parse.directions(params_text, facing, true)
local pos1 = wea_c.pos.get(name, 1)
local pos2 = pos1:add(vec)
if not worldedit.pos1[name] then
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 "..pos..", "
end
local p2 = vec + Vector3.clone(worldedit.pos1[name])
worldedit.pos2[name] = p2
worldedit.mark_pos2(name)
return true, ret.."position 2 set to "..p2
wea_c.pos.set_all(name, {pos1, pos2})
return true, "Pos1 set to "..pos1..", Pos2 set to "..pos2
end,
})

View file

@ -0,0 +1,40 @@
-- local wea = worldeditadditions
local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
-- ███████ ███████ ██ ██ ██████ ██ ███ ██ ██ ██
-- ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██
-- ███████ ███████ ███████ ██████ ██ ██ ██ ██ █████
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ███████ ███████ ██ ██ ██ ██ ██ ██ ████ ██ ██
worldeditadditions_core.register_command("srel", {
params = "[<axis1>] <length1> [[<axis2>] <length2> [...]]",
description = "Set WorldEdit region position 2 relative to position 1 and player facing.",
privs = { worldedit = true },
require_pos = 0,
parse = function(params_text)
local ret = wea_c.split(params_text)
if #ret < 1 then return false, "SREL: No params found!"
else return true, ret end
end,
func = function(name, params_text)
local facing = wea_c.player_dir(name)
local min, max = wea_c.parse.directions(params_text, facing)
local pos1 = wea_c.pos.get(name, 1)
local pos2 = wea_c.pos.get(name, 2)
if not pos2 then wea_c.pos.set(name, 2, pos1)
else pos1, pos2 = Vector3.sort(pos1, pos2) end
pos1, pos2 = pos1:add(max), pos1:add(min)
wea_c.pos.set_all(name, {pos1, pos2})
return true, "Pos1 set to "..pos1..", Pos2 set to "..pos2
end,
})
-- Tests
-- //srel front 5 left 3 y 2