scube and vector population

This commit is contained in:
VorTechnix 2021-03-10 13:21:33 -08:00
parent 234e0a1325
commit cbd07aee4f
6 changed files with 84 additions and 8 deletions

View file

@ -4,7 +4,7 @@ It's about time I started a changelog! This will serve from now on as the main c
Note to self: See the bottom of this file for the release template text. Note to self: See the bottom of this file for the release template text.
## v1.12 (unreleased) ## v1.12 (unreleased)
- Add `//srect` (_select rectangle_) - thanks, @VorTechnix! - Add `//srect` (_select rectangle_), `//scol` (_select column_), `//scube` (_select cube_) - thanks, @VorTechnix!
- Add `//spush`, `//spop`, and `//sstack` - Add `//spush`, `//spop`, and `//sstack`
- `//overlay`: Don't place nodes above water - `//overlay`: Don't place nodes above water

View file

@ -482,6 +482,14 @@ Executes the given command, and then clips the result to the largest ellipsoid t
//ellipsoidapply layers desert_sand sand 2 desert_sandstone 4 sandstone 10 //ellipsoidapply layers desert_sand sand 2 desert_sandstone 4 sandstone 10
``` ```
## `//scol [<axis1> ] <length>`
Short for _select column_. Sets the pos2 at a set distance along 1 axis from pos1. If the axis isn't specified, defaults the direction you are facing. Implementation thanks to @VorTechnix.
```
//scol 10
//scol x 3
```
## `//srect [<axis1> [<axis2>]] <length>` ## `//srect [<axis1> [<axis2>]] <length>`
Short for _select rectangle_. Sets the pos2 at a set distance along 2 axes from pos1. If the axes aren't specified, defaults to positive y and the direction you are facing. Implementation thanks to @VorTechnix. Short for _select rectangle_. Sets the pos2 at a set distance along 2 axes from pos1. If the axes aren't specified, defaults to positive y and the direction you are facing. Implementation thanks to @VorTechnix.
@ -491,6 +499,16 @@ Short for _select rectangle_. Sets the pos2 at a set distance along 2 axes from
//srect -z y 25 //srect -z y 25
``` ```
## `//scube [<axis1> [<axis2> [<axis3>]]] <length>`
Short for _select cube_. Sets the pos2 at a set distance along 3 axes from pos1. If the axes aren't specified, defaults to positive y, the direction you are facing and the axis to the left of facing. Implementation thanks to @VorTechnix.
```
//scube 5
//scube z a y 12
//scube x z 3
//scube -z 12
```
## `//sstack` ## `//sstack`
Displays the contents of your per-user selection stack. This stack can be pushed to and popped from rather like a stack of plates. See also `//spush` (for pushing to the selection stack) and `//spop` (for popping from the selection stack). Displays the contents of your per-user selection stack. This stack can be pushed to and popped from rather like a stack of plates. See also `//spush` (for pushing to the selection stack) and `//spop` (for popping from the selection stack).

View file

@ -15,7 +15,7 @@ worldedit.register_command("scol", {
tmp.len = tonumber(len) tmp.len = tonumber(len)
-- If len == nill cancel the operation -- If len == nill cancel the operation
if tmp.len == nil then return false, "No length specified." end if not tmp.len then return false, "No length specified." end
-- If ax1 is bad send "get" order -- If ax1 is bad send "get" order
if ax1 == "g" then tmp.get = true if ax1 == "g" then tmp.get = true
else vec[ax1] = sn1 * tmp.len end else vec[ax1] = sn1 * tmp.len end

View file

@ -0,0 +1,55 @@
-- ███████ ██████ ██ ██ ██████ ███████
-- ██ ██ ██ ██ ██ ██ ██
-- ███████ ██ ██ ██ ██████ █████
-- ██ ██ ██ ██ ██ ██ ██
-- ███████ ██████ ██████ ██████ ███████
worldedit.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 wea, vec, tmp = worldeditadditions, vector.new(0, 0, 0), {}
local find = wea.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)]
tmp.len = tonumber(len)
-- If len is nill cancel the operation
if not tmp.len then return false, "No length specified." end
-- If axis is bad send "get" order
if ax1 == "g" then tmp.get = true
else vec[ax1] = sn1 * tmp.len end
if ax2 == "g" then tmp.get = true
else vec[ax2] = sn2 * tmp.len end
if ax3 == "g" then tmp.get = true
else vec[ax3] = sn3 * tmp.len end
tmp.axes = ax1..","..ax2..","..ax3
return true, vec, tmp
end,
func = function(name, vec, tmp)
if tmp.get then
local ax, dir = worldeditadditions.player_axis2d(name)
local _, left, sn = worldeditadditions.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
worldedit.mark_pos2(name)
return true, "position 2 set to " .. minetest.pos_to_string(p2)
end,
})
-- Tests
-- /multi //fp set1 -63 19 -20 //scube 5
-- /multi //fp set1 -63 19 -20 //scube z 5
-- /multi //fp set1 -63 19 -20 //scube a z 5
-- /multi //fp set1 -63 19 -20 //scube z a y 5
-- /multi //fp set1 -63 19 -20 //scube -z y a 5
-- /multi //fp set1 -63 19 -20 //scube z z 5
-- /lua print()

View file

@ -11,23 +11,26 @@ worldedit.register_command("srect", {
parse = function(params_text) parse = function(params_text)
local wea, vec, tmp = worldeditadditions, vector.new(0, 0, 0), {} local wea, vec, tmp = worldeditadditions, vector.new(0, 0, 0), {}
local find = wea.split(params_text, "%s", false) local find = wea.split(params_text, "%s", false)
local ax1, ax2 = (tostring(find[1]):match('[xyz]') or "g"):sub(1,1), (tostring(find[2]):match('[xyz]') or "y"):sub(1,1) 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.getsign(find[1]), wea.getsign(find[2]), find[table.maxn(find)]
tmp.len = tonumber(len) tmp.len = tonumber(len)
-- If len == nill cancel the operation -- If len == nill cancel the operation
if tmp.len == nil then return false, "No length specified." end if not tmp.len then return false, "No length specified." end
-- If ax1 is bad send "get" order -- If axis is bad send "get" order
if ax1 == "g" then tmp.get = true if ax1 == "g" then tmp.get = true
else vec[ax1] = sn1 * tmp.len end else vec[ax1] = sn1 * tmp.len end
vec[ax2] = sn2 * tmp.len if ax2 == "g" then tmp.get = true
else vec[ax2] = sn2 * tmp.len end
tmp.axes = ax1..","..ax2
return true, vec, tmp return true, vec, tmp
end, end,
func = function(name, vec, tmp) func = function(name, vec, tmp)
if tmp.get then if tmp.get then
local ax, dir = worldeditadditions.player_axis2d(name) local ax, dir = worldeditadditions.player_axis2d(name)
vec[ax] = tmp.len * dir 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 end
local p2 = vector.add(vec,worldedit.pos1[name]) local p2 = vector.add(vec,worldedit.pos1[name])

View file

@ -43,7 +43,7 @@ dofile(we_c.modpath.."/commands/meta/ellipsoidapply.lua")
dofile(we_c.modpath.."/commands/selectors/scol.lua") dofile(we_c.modpath.."/commands/selectors/scol.lua")
dofile(we_c.modpath.."/commands/selectors/srect.lua") dofile(we_c.modpath.."/commands/selectors/srect.lua")
-- dofile(we_c.modpath.."/commands/selectors/scube.lua") dofile(we_c.modpath.."/commands/selectors/scube.lua")
dofile(we_c.modpath.."/commands/selectors/sstack.lua") dofile(we_c.modpath.."/commands/selectors/sstack.lua")
dofile(we_c.modpath.."/commands/selectors/spush.lua") dofile(we_c.modpath.."/commands/selectors/spush.lua")
dofile(we_c.modpath.."/commands/selectors/spop.lua") dofile(we_c.modpath.."/commands/selectors/spop.lua")