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

@ -1,35 +1,33 @@
local wea_c = worldeditadditions_core local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3 local Vector3 = wea_c.Vector3
-- ███████ ██████ ███████ ███ ██ ████████ ███████ ██████ -- ███████ ██████ ███████ ███ ██ ████████ ███████ ██████
-- ██ ██ ██ ████ ██ ██ ██ ██ ██ -- ██ ██ ██ ████ ██ ██ ██ ██ ██
-- ███████ ██ █████ ██ ██ ██ ██ █████ ██████ -- ███████ ██ █████ ██ ██ ██ ██ █████ ██████
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ███████ ██████ ███████ ██ ████ ██ ███████ ██ ██ -- ███████ ██████ ███████ ██ ████ ██ ███████ ██ ██
worldeditadditions_core.register_command("scentre", { worldeditadditions_core.register_command("scentre", {
params = "", params = "",
description = "Set WorldEdit region positions 1 and 2 to the centre of the current selection.", description = "Set WorldEdit region positions 1 and 2 to the centre of the current selection.",
privs = {worldedit=true}, privs = {worldedit=true},
require_pos = 2, require_pos = 2,
parse = function(params_text) parse = function(params_text)
return true return true
end, end,
func = function(name) func = function(name)
local mean = Vector3.mean( local mean = Vector3.mean(
Vector3.clone(worldedit.pos1[name]), Vector3.clone(wea_c.pos.get(name, 1)),
Vector3.clone(worldedit.pos2[name]) Vector3.clone(wea_c.pos.get(name, 2))
) )
local pos1, pos2 = Vector3.clone(mean), Vector3.clone(mean) local pos1, pos2 = Vector3.clone(mean), Vector3.clone(mean)
pos1 = pos1:floor() pos1 = pos1:floor()
pos2 = pos2:ceil() pos2 = pos2:ceil()
worldedit.pos1[name], worldedit.pos2[name] = pos1, pos2 wea_c.pos.set_all(name, {pos1, pos2})
worldedit.mark_pos1(name)
worldedit.mark_pos2(name) return true, "Pos1 set to "..pos1..", Pos2 set to "..pos2
end,
return true, "position 1 set to "..pos1..", position 2 set to "..pos2 })
end,
}) -- lua print(vecs.mean.x..", "..vecs.mean.y..", "..vecs.mean.z)
-- lua print(vecs.mean.x..", "..vecs.mean.y..", "..vecs.mean.z)

@ -23,6 +23,8 @@ worldeditadditions_core.register_command("sgrow", {
func = function(name, params_text) func = function(name, params_text)
local facing = wea_c.player_dir(name) local facing = wea_c.player_dir(name)
local min, max = wea_c.parse.directions(params_text, facing) 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 pos1 = wea_c.pos.get(name, 1)
local pos2 = wea_c.pos.get(name, 2) local pos2 = wea_c.pos.get(name, 2)

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

@ -1,4 +1,3 @@
local wea = worldeditadditions
local wea_c = worldeditadditions_core local wea_c = worldeditadditions_core
local Vector3 = worldeditadditions.Vector3 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", { 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.", description = "Shift the WorldEdit region in 3 dimensions.",
privs = { worldedit = true }, privs = { worldedit = true },
require_pos = 2, require_pos = 2,
parse = function(params_text) parse = function(params_text)
if params_text:match("([%l%s+-]+%d+)") then return true, params_text local ret = wea_c.split(params_text)
else return false, "No acceptable params found" end if #ret < 1 then return false, "SSHIFT: No params found!"
else return true, ret end
end, end,
func = function(name, params_text) func = function(name, params_text)
local _, vec = parse_with_name(name,params_text) local facing = wea_c.player_dir(name)
if not _ then return false, vec end 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]) local pos1 = vec:add(wea_c.pos.get(name, 1))
worldedit.pos1[name] = pos1 local pos2 = vec:add(wea_c.pos.get(name, 2))
worldedit.mark_pos1(name)
local pos2 = vec:add(worldedit.pos2[name]) wea_c.pos.set_all(name, {pos1, pos2})
worldedit.pos2[name] = pos2 return true, "Pos1 set to "..pos1..", Pos2 set to "..pos2
worldedit.mark_pos2(name)
return true, "Region shifted by " .. (vec.x + vec.y + vec.z) .. " nodes."
end, end,
}) })

@ -23,6 +23,8 @@ worldeditadditions_core.register_command("sshrink", {
func = function(name, params_text) func = function(name, params_text)
local facing = wea_c.player_dir(name) local facing = wea_c.player_dir(name)
local min, max = wea_c.parse.directions(params_text, facing) 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 pos1 = wea_c.pos.get(name, 1)
local pos2 = wea_c.pos.get(name, 2) local pos2 = wea_c.pos.get(name, 2)