]> git.lizzy.rs Git - worldedit.git/commitdiff
Rotate now works with x/y/z/? instead of just y: "//rotate x 90"
authorKyle <kyle.kylina@gmail.com>
Tue, 28 Aug 2012 22:57:45 +0000 (15:57 -0700)
committerKyle <kyle.kylina@gmail.com>
Tue, 28 Aug 2012 22:57:45 +0000 (15:57 -0700)
README.md
functions.lua
init.lua

index a83f2f44317cbbb96d4aba9497a3711811da08f4..72f75fb7450379ce44c85bbb62960fcaa0eb6b32 100644 (file)
--- 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
 
index ea10760aecd17bbd0967f2cae43db3fd9bf4331c..15eea49ed9758db25ef105c2da137e9729f6e295 100644 (file)
@@ -395,10 +395,17 @@ worldedit.flip = function(pos1, pos2, axis)
        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
@@ -407,14 +414,14 @@ worldedit.rotate = function(pos1, pos2, angle)
        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
index 7bd79beaeeafb2a83f2cbd722662c60f4083eb6f..6820bbfacc7ec7bc018d7008d44f4b984b7333fc 100644 (file)
--- a/init.lua
+++ b/init.lua
@@ -404,8 +404,8 @@ minetest.register_chatcommand("/flip", {
 })\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
@@ -414,17 +414,20 @@ minetest.register_chatcommand("/rotate", {
                        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