]> git.lizzy.rs Git - worldedit.git/commitdiff
New command: //orient, that rotates oriented nodes such as furnaces around the Y...
authorAnthony Zhang <azhang9@gmail.com>
Sat, 12 Jan 2013 21:46:40 +0000 (16:46 -0500)
committerAnthony Zhang <azhang9@gmail.com>
Sat, 12 Jan 2013 21:46:40 +0000 (16:46 -0500)
Chat Commands.md
WorldEdit API.md
worldedit/manipulations.lua
worldedit_commands/init.lua

index 861f4ae338fd921699c8f8ab757ec819c1f7fb5f..bfca8bfd714ca3ad3e1963bd0d9657dadf12f20f 100644 (file)
@@ -155,18 +155,27 @@ Flip the current WorldEdit region along the x/y/z/? axis.
 \r
 ### //rotate x/y/z/? <angle>\r
 \r
-Rotate the current WorldEdit positions and region along the x/y/z/? axis by angle <angle> (integer multiple of 90 degrees).\r
+Rotate the current WorldEdit positions and region along the x/y/z/? axis by angle <angle> (90 degree increment).\r
 \r
     //rotate x 90\r
     //rotate y 180\r
     //rotate z 270\r
     //rotate ? -90\r
 \r
+### //orient <angle>\r
+\r
+Rotate oriented nodes in the current WorldEdit region around the Y axis by angle <angle> (90 degree increment)\r
+\r
+    //orient 90\r
+    //orient 180\r
+    //orient 270\r
+    //orient -90\r
+\r
 ### //fixlight\r
 \r
 Fixes the lighting in the current WorldEdit region.\r
 \r
-    //dig\r
+    //fixlight\r
 \r
 ## //hide\r
 \r
index be2270d02fd390e7e1b00a8e951351b096f49943..a0a1a60666736cb099e2870f23004ff6493e8efe 100644 (file)
@@ -56,6 +56,12 @@ Rotates a region defined by the positions `pos1` and `pos2` by `angle` degrees c
 \r
 Returns the number of nodes rotated, the new position 1, and the new position 2.\r
 \r
+### count = worldedit.orient(pos1, pos2, angle)\r
+\r
+Rotates all oriented nodes in a region defined by the positions `pos1` and `pos2` by `angle` degrees clockwise (90 degree increment) around the Y axis.\r
+\r
+Returns the number of nodes oriented.\r
+\r
 ### count = worldedit.fixlight(pos1, pos2)\r
 \r
 Fixes the lighting in a region defined by positions `pos1` and `pos2`.\r
index 190308486cc1f76f5f671130398d3a870c796935..253456cfefccd81d7b23239e89dd53f2810dc348 100644 (file)
@@ -304,6 +304,62 @@ worldedit.rotate = function(pos1, pos2, axis, angle)
        return count, pos1, pos2\r
 end\r
 \r
+--rotates all oriented nodes in a region defined by the positions `pos1` and `pos2` by `angle` degrees clockwise (90 degree increment) around the Y axis, returning the number of nodes oriented\r
+worldedit.orient = function(pos1, pos2, angle)\r
+       local pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
+       local nodes = minetest.registered_nodes\r
+       local env = minetest.env\r
+       local wallmounted = {\r
+               [90]={[0]=0, [1]=1, [2]=5, [3]=4, [4]=2, [5]=3},\r
+               [180]={[0]=0, [1]=1, [2]=3, [3]=2, [4]=5, [5]=4},\r
+               [270]={[0]=0, [1]=1, [2]=4, [3]=5, [4]=3, [5]=2}\r
+       }\r
+       local facedir = {\r
+               [90]={[0]=1, [1]=2, [2]=3, [3]=0},\r
+               [180]={[0]=2, [1]=3, [2]=0, [3]=1},\r
+               [270]={[0]=3, [1]=0, [2]=1, [3]=2}\r
+       }\r
+\r
+       angle = angle % 360\r
+       if angle == 0 then\r
+               return 0\r
+       end\r
+       local wallmounted_substitution = wallmounted[angle]\r
+       local facedir_substitution = facedir[angle]\r
+\r
+       local count = 0\r
+       local pos = {x=pos1.x, y=0, z=0}\r
+       while pos.x <= pos2.x do\r
+               pos.y = pos1.y\r
+               while pos.y <= pos2.y do\r
+                       pos.z = pos1.z\r
+                       while pos.z <= pos2.z do\r
+                               local node = env:get_node(pos)\r
+                               local def = nodes[node.name]\r
+                               if def then\r
+                                       if def.paramtype2 == "wallmounted" then\r
+                                               node.param2 = wallmounted_substitution[node.param2]\r
+                                               local meta = env:get_meta(pos):to_table()\r
+                                               env:add_node(pos, node)\r
+                                               env:get_meta(pos):from_table(meta)\r
+                                               count = count + 1\r
+                                       elseif def.paramtype2 == "facedir" then\r
+                                               node.param2 = facedir_substitution[node.param2]\r
+                                               local meta = env:get_meta(pos):to_table()\r
+                                               env:add_node(pos, node)\r
+                                               env:get_meta(pos):from_table(meta)\r
+                                               count = count + 1\r
+                                       end\r
+                               end\r
+                               pos.z = pos.z + 1\r
+                       end\r
+                       pos.y = pos.y + 1\r
+               end\r
+               pos.x = pos.x + 1\r
+       end\r
+       return count\r
+end\r
+\r
 --fixes the lighting in a region defined by positions `pos1` and `pos2`, returning the number of nodes updated\r
 worldedit.fixlight = function(pos1, pos2)\r
        local pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
index b0e15b32fb446b9169d0d364d82a3e44ee422663..15220c6fe971071ac8e8b74143c5d1c9e2d9da31 100644 (file)
@@ -544,6 +544,33 @@ minetest.register_chatcommand("/rotate", {
        end,\r
 })\r
 \r
+minetest.register_chatcommand("/orient", {\r
+       params = "<angle>",\r
+       description = "Rotate oriented nodes in the current WorldEdit region around the Y 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
+               if pos1 == nil or pos2 == nil then\r
+                       minetest.chat_send_player(name, "No WorldEdit region selected")\r
+                       return\r
+               end\r
+\r
+               local found, _, angle = param:find("^([+-]?%d+)$")\r
+               if found == nil then\r
+                       minetest.chat_send_player(name, "Invalid usage: " .. param)\r
+                       return\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.orient(pos1, pos2, angle)\r
+\r
+               minetest.chat_send_player(name, count .. " nodes oriented")\r
+       end,\r
+})\r
+\r
 minetest.register_chatcommand("/fixlight", {\r
        params = "",\r
        description = "Fix the lighting in the current WorldEdit region",\r