summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md9
-rw-r--r--functions.lua23
-rw-r--r--init.lua13
3 files changed, 28 insertions, 17 deletions
diff --git a/README.md b/README.md
index a83f2f4..72f75fb 100644
--- a/README.md
+++ b/README.md
@@ -165,11 +165,12 @@ Flip the current WorldEdit region along the x/y/z/? axis.
### //rotate
-Rotate the current WorldEdit region around the y axis by angle <angle> (90 degree increment).
+Rotate the current WorldEdit region around the axis <axis> by angle <angle> (90 degree increment).
- //rotate 90
- //rotate 180
- //rotate 270
+ //rotate x 90
+ //rotate y 180
+ //rotate z 270
+ //rotate ? -90
### //dig
diff --git a/functions.lua b/functions.lua
index ea10760..15eea49 100644
--- a/functions.lua
+++ b/functions.lua
@@ -395,10 +395,17 @@ worldedit.flip = function(pos1, pos2, axis)
return worldedit.volume(pos1, pos2)
end
---rotates a region defined by the positions `pos1` and `pos2` by `angle` degrees clockwise around the y axis (supporting 90 degree increments only), returning the number of nodes rotated
-worldedit.rotate = function(pos1, pos2, angle)
+--rotates a region defined by the positions `pos1` and `pos2` by `angle` degrees clockwise (if you are looking in the negative direction) around the `axis` (supporting 90 degree increments only), returning the number of nodes rotated
+worldedit.rotate = function(pos1, pos2, axis, angle)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
+ if axis == 'x' then
+ axes = {'z', 'y'}
+ elseif axis == 'y' then
+ axes = {'x', 'z'}
+ else--if axis == 'z' then
+ axes = {'y', 'x'}
+ end
angle = angle % 360
local pos = {x=pos1.x, y=0, z=0}
@@ -407,14 +414,14 @@ worldedit.rotate = function(pos1, pos2, angle)
local env = minetest.env
if angle == 90 then
- worldedit.transpose(pos1, pos2, "x", "z")
- worldedit.flip(pos1, pos2, "z")
+ worldedit.transpose(pos1, pos2, axes[1], axes[2])
+ worldedit.flip(pos1, pos2, axes[2])
elseif angle == 180 then
- worldedit.flip(pos1, pos2, "x")
- worldedit.flip(pos1, pos2, "z")
+ worldedit.flip(pos1, pos2, axes[1])
+ worldedit.flip(pos1, pos2, axes[2])
elseif angle == 270 then
- worldedit.transpose(pos1, pos2, "x", "z")
- worldedit.flip(pos1, pos2, "x")
+ worldedit.transpose(pos1, pos2, axes[1], axes[2])
+ worldedit.flip(pos1, pos2, axes[1])
else
return 0
end
diff --git a/init.lua b/init.lua
index 7bd79be..6820bbf 100644
--- a/init.lua
+++ b/init.lua
@@ -404,8 +404,8 @@ minetest.register_chatcommand("/flip", {
})
minetest.register_chatcommand("/rotate", {
- params = "<angle>",
- description = "Rotate the current WorldEdit region around the y axis by angle <angle> (90 degree increment)",
+ params = "<axis> <angle>",
+ description = "Rotate the current WorldEdit region around the axis <axis> by angle <angle> (90 degree increment)",
privs = {worldedit=true},
func = function(name, param)
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
@@ -414,17 +414,20 @@ minetest.register_chatcommand("/rotate", {
return
end
- angle = tonumber(param)
- if angle == nil then
+ local found, _, axis, angle = param:find("^([xyz%?])%s+([+-]?%d+)$")
+ if found == nil then
minetest.chat_send_player(name, "Invalid usage: " .. param)
return
end
+ if axis == "?" then
+ axis = worldedit.player_axis(name)
+ end
if angle % 90 ~= 0 then
minetest.chat_send_player(name, "Invalid usage: angle must be multiple of 90")
return
end
- local count = worldedit.rotate(pos1, pos2, angle)
+ local count = worldedit.rotate(pos1, pos2, axis, angle)
minetest.chat_send_player(name, count .. " nodes rotated")
end,
})