]> git.lizzy.rs Git - worldedit.git/commitdiff
Implement full facedir and color* in //orient
authorPedro Gimeno <pgimeno@email.fake>
Thu, 4 Apr 2019 21:50:57 +0000 (23:50 +0200)
committersfan5 <sfan5@live.de>
Thu, 4 Apr 2019 22:12:02 +0000 (00:12 +0200)
Thanks to entuland for the Rhotator facedir to matrix and matrix to facedir code, which helped creating the tables.

worldedit/manipulations.lua

index ee5156137ab780fbe131de0cad6044ecd2fcbb32..a6aad16ac88eba1b3ffca6b3ada4915f33889997 100644 (file)
@@ -529,20 +529,22 @@ end
 -- @param pos2\r
 -- @param angle Angle in degrees (90 degree increments only).\r
 -- @return The number of nodes oriented.\r
--- TODO: Support 6D facedir rotation along arbitrary axis.\r
 function worldedit.orient(pos1, pos2, angle)\r
        local pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
        local registered_nodes = minetest.registered_nodes\r
 \r
        local wallmounted = {\r
-               [90]  = {[0]=0, 1, 5, 4, 2, 3},\r
-               [180] = {[0]=0, 1, 3, 2, 5, 4},\r
-               [270] = {[0]=0, 1, 4, 5, 3, 2}\r
+               [90]  = {0, 1, 5, 4, 2, 3, 0, 0},\r
+               [180] = {0, 1, 3, 2, 5, 4, 0, 0},\r
+               [270] = {0, 1, 4, 5, 3, 2, 0, 0}\r
        }\r
        local facedir = {\r
-               [90]  = {[0]=1, 2, 3, 0},\r
-               [180] = {[0]=2, 3, 0, 1},\r
-               [270] = {[0]=3, 0, 1, 2}\r
+               [90]  = { 1,  2,  3,  0, 13, 14, 15, 12, 17, 18, 19, 16,\r
+                                 9, 10, 11,  8,  5,  6,  7,  4, 23, 20, 21, 22},\r
+               [180] = { 2,  3,  0,  1, 10, 11,  8,  9,  6,  7,  4,  5,\r
+                                18, 19, 16, 17, 14, 15, 12, 13, 22, 23, 20, 21},\r
+               [270] = { 3,  0,  1,  2, 19, 16, 17, 18, 15, 12, 13, 14,\r
+                                 7,  4,  5,  6, 11,  8,  9, 10, 21, 22, 23, 20}\r
        }\r
 \r
        angle = angle % 360\r
@@ -558,8 +560,7 @@ function worldedit.orient(pos1, pos2, angle)
        worldedit.keep_loaded(pos1, pos2)\r
 \r
        local count = 0\r
-       local set_node, get_node, get_meta, swap_node = minetest.set_node,\r
-                       minetest.get_node, minetest.get_meta, minetest.swap_node\r
+       local get_node, swap_node = minetest.get_node, minetest.swap_node\r
        local pos = {x=pos1.x, y=0, z=0}\r
        while pos.x <= pos2.x do\r
                pos.y = pos1.y\r
@@ -569,17 +570,20 @@ function worldedit.orient(pos1, pos2, angle)
                                local node = get_node(pos)\r
                                local def = registered_nodes[node.name]\r
                                if def then\r
-                                       if def.paramtype2 == "wallmounted" then\r
-                                               node.param2 = wallmounted_substitution[node.param2]\r
-                                               local meta = get_meta(pos):to_table()\r
-                                               set_node(pos, node)\r
-                                               get_meta(pos):from_table(meta)\r
+                                       local paramtype2 = def.paramtype2\r
+                                       if paramtype2 == "wallmounted" or\r
+                                                       paramtype2 == "colorwallmounted" then\r
+                                               local orient = node.param2 % 8\r
+                                               node.param2 = node.param2 - orient +\r
+                                                               wallmounted_substitution[orient + 1]\r
+                                               swap_node(pos, node)\r
                                                count = count + 1\r
-                                       elseif def.paramtype2 == "facedir" then\r
-                                               node.param2 = facedir_substitution[node.param2]\r
-                                               local meta = get_meta(pos):to_table()\r
-                                               set_node(pos, node)\r
-                                               get_meta(pos):from_table(meta)\r
+                                       elseif paramtype2 == "facedir" or\r
+                                                       paramtype2 == "colorfacedir" then\r
+                                               local orient = node.param2 % 32\r
+                                               node.param2 = node.param2 - orient +\r
+                                                               facedir_substitution[orient + 1]\r
+                                               swap_node(pos, node)\r
                                                count = count + 1\r
                                        end\r
                                end\r