return worldedit.volume(pos1, pos2)\r
end\r
\r
---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\r
-worldedit.rotate = function(pos1, pos2, angle)\r
+--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\r
+worldedit.rotate = function(pos1, pos2, axis, angle)\r
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
\r
+ if axis == 'x' then\r
+ axes = {'z', 'y'}\r
+ elseif axis == 'y' then\r
+ axes = {'x', 'z'}\r
+ else--if axis == 'z' then\r
+ axes = {'y', 'x'}\r
+ end\r
angle = angle % 360\r
\r
local pos = {x=pos1.x, y=0, z=0}\r
local env = minetest.env\r
\r
if angle == 90 then\r
- worldedit.transpose(pos1, pos2, "x", "z")\r
- worldedit.flip(pos1, pos2, "z")\r
+ worldedit.transpose(pos1, pos2, axes[1], axes[2])\r
+ worldedit.flip(pos1, pos2, axes[2])\r
elseif angle == 180 then\r
- worldedit.flip(pos1, pos2, "x")\r
- worldedit.flip(pos1, pos2, "z")\r
+ worldedit.flip(pos1, pos2, axes[1])\r
+ worldedit.flip(pos1, pos2, axes[2])\r
elseif angle == 270 then\r
- worldedit.transpose(pos1, pos2, "x", "z")\r
- worldedit.flip(pos1, pos2, "x")\r
+ worldedit.transpose(pos1, pos2, axes[1], axes[2])\r
+ worldedit.flip(pos1, pos2, axes[1])\r
else\r
return 0\r
end\r
})\r
\r
minetest.register_chatcommand("/rotate", {\r
- params = "<angle>",\r
- description = "Rotate the current WorldEdit region around the y axis by angle <angle> (90 degree increment)",\r
+ params = "<axis> <angle>",\r
+ description = "Rotate the current WorldEdit region around the axis <axis> by angle <angle> (90 degree increment)",\r
privs = {worldedit=true},\r
func = function(name, param)\r
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
return\r
end\r
\r
- angle = tonumber(param)\r
- if angle == nil then\r
+ local found, _, axis, angle = param:find("^([xyz%?])%s+([+-]?%d+)$")\r
+ if found == nil then\r
minetest.chat_send_player(name, "Invalid usage: " .. param)\r
return\r
end\r
+ if axis == "?" then\r
+ axis = worldedit.player_axis(name)\r
+ end\r
if angle % 90 ~= 0 then\r
minetest.chat_send_player(name, "Invalid usage: angle must be multiple of 90")\r
return\r
end\r
\r
- local count = worldedit.rotate(pos1, pos2, angle)\r
+ local count = worldedit.rotate(pos1, pos2, axis, angle)\r
minetest.chat_send_player(name, count .. " nodes rotated")\r
end,\r
})\r