scentre, sshift stable + housekeeping

This commit is contained in:
VorTechnix 2024-09-15 09:15:22 -07:00
parent d1c4f9bd19
commit 38b55712cc
No known key found for this signature in database
GPG key ID: 091E91A69545D5BA
5 changed files with 48 additions and 68 deletions

View file

@ -16,19 +16,17 @@ worldeditadditions_core.register_command("scentre", {
end,
func = function(name)
local mean = Vector3.mean(
Vector3.clone(worldedit.pos1[name]),
Vector3.clone(worldedit.pos2[name])
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()
worldedit.pos1[name], worldedit.pos2[name] = pos1, pos2
worldedit.mark_pos1(name)
worldedit.mark_pos2(name)
wea_c.pos.set_all(name, {pos1, pos2})
return true, "position 1 set to "..pos1..", position 2 set to "..pos2
return true, "Pos1 set to "..pos1..", Pos2 set to "..pos2
end,
})

View file

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

View file

@ -1,4 +1,3 @@
local wea = worldeditadditions
local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3

View file

@ -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 = "<axis1> <distance1> [<axis2> <distance2> [<axis3> <distance3>]]",
params = "[<axis1>] <distance1> [[<axis2>] <distance2> [...]]",
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,
})

View file

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