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
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