//stack y -1
//stack z +5
+### //transpose x/y/z x/y/z
+
+Transpose the current WorldEdit region along the x/y/z and x/y/z axes.
+
+ //transpose x y
+ //transpose x z
+ //transpose y z
+
+### //flip x/y/z
+
+Flip the current WorldEdit region along the x/y/z axis.
+
+ //flip x
+ //flip y
+ //flip z
+
+### //rotate
+
+Rotate the current WorldEdit region around the y axis by angle <angle> (90 degree increment).
+
+ //rotate 90
+ //rotate 180
+ //rotate 270
+
### //dig
Dig the current WorldEdit region.
### worldedit.stack(pos1, pos2, axis, count)
-duplicates the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") `count` times.
+Duplicates the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") `count` times.
Returns the number of nodes stacked.
+### worldedit.transpose(pos1, pos2, axis1, axis2)
+
+Transposes a region defined by the positions `pos1` and `pos2` between the `axis1` and `axis2` axes ("x" or "y" or "z").
+
+Returns the number of nodes transposed.
+
+### worldedit.flip(pos1, pos2, axis)
+
+Flips a region defined by the positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z").
+
+Returns the number of nodes flipped.
+
+### worldedit.rotate(pos1, pos2, angle)
+
+Rotates a region defined by the positions `pos1` and `pos2` by `angle` degrees clockwise around the y axis (supporting 90 degree increments only).
+
+Returns the number of nodes rotated.
+
### worldedit.dig(pos1, pos2)
Digs a region defined by positions `pos1` and `pos2`.
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, node)\r
+ local node = env:get_node(pos)\r
local value = pos[axis]\r
pos[axis] = value - amount\r
env:add_node(pos, node)\r
while pos.y >= pos1.y do\r
pos.z = pos2.z\r
while pos.z >= pos1.z do\r
- local node = minetest.env:get_node(pos, node)\r
+ local node = minetest.env:get_node(pos)\r
local value = pos[axis]\r
pos[axis] = value + amount\r
minetest.env:add_node(pos, node)\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, node)\r
+ local node = env:get_node(pos)\r
env:remove_node(pos)\r
local value = pos[axis]\r
pos[axis] = value - amount\r
while pos.y >= pos1.y do\r
pos.z = pos2.z\r
while pos.z >= pos1.z do\r
- local node = minetest.env:get_node(pos, node)\r
+ local node = minetest.env:get_node(pos)\r
env:remove_node(pos)\r
local value = pos[axis]\r
pos[axis] = value + amount\r
return worldedit.volume(pos1, pos2)\r
end\r
\r
+--transposes a region defined by the positions `pos1` and `pos2` between the `axis1` and `axis2` axes, returning the number of nodes transposed\r
+worldedit.transpose = function(pos1, pos2, axis1, axis2)\r
+ local pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
+\r
+ local pos = {x=pos1.x, y=0, z=0}\r
+ local env = minetest.env\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 extent1, extent2 = pos[axis1] - pos1[axis1], pos[axis2] - pos1[axis2]\r
+ if extent1 < extent2 then\r
+ local node1 = env:get_node(pos)\r
+ local value1, value2 = pos[axis1], pos[axis2]\r
+ pos[axis1], pos[axis2] = pos1[axis1] + extent1, pos1[axis2] + extent2\r
+ local node2 = env:get_node(pos)\r
+ env:add_node(pos, node1)\r
+ pos[axis1], pos[axis2] = value1, value2\r
+ env:add_node(pos, node2)\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 worldedit.volume(pos1, pos2)\r
+end\r
+\r
+--flips a region defined by the positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z"), returning the number of nodes flipped\r
+worldedit.flip = function(pos1, pos2, axis)\r
+ local pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
+\r
+ local pos = {x=pos1.x, y=0, z=0}\r
+ local start = pos1[axis] + pos2[axis]\r
+ pos2[axis] = pos1[axis] + math.floor((pos2[axis] - pos1[axis]) / 2)\r
+ local env = minetest.env\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 node1 = env:get_node(pos)\r
+ local value = pos[axis]\r
+ pos[axis] = start - value\r
+ local node2 = env:get_node(pos)\r
+ env:add_node(pos, node1)\r
+ pos[axis] = value\r
+ env:add_node(pos, node2)\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 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
+ local pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
+\r
+ angle = angle % 360\r
+\r
+ local pos = {x=pos1.x, y=0, z=0}\r
+ local newpos = {x=0, y=0, z=0}\r
+ local offsetx, offsetz\r
+ local env = minetest.env\r
+\r
+ if angle == 90 then\r
+ worldedit.transpose(pos1, pos2, "x", "z")\r
+ pos1.x, pos1.z = pos1.z, pos1.x\r
+ pos2.x, pos2.z = pos2.z, pos2.x\r
+ worldedit.flip(pos1, pos2, "z")\r
+ elseif angle == 180 then\r
+ worldedit.flip(pos1, pos2, "x")\r
+ worldedit.flip(pos1, pos2, "z")\r
+ elseif angle == 270 then\r
+ worldedit.transpose(pos1, pos2, "x", "z")\r
+ pos1.x, pos1.z = pos1.z, pos1.x\r
+ pos2.x, pos2.z = pos2.z, pos2.x\r
+ worldedit.flip(pos1, pos2, "x")\r
+ else\r
+ return 0\r
+ end\r
+ return worldedit.volume(pos1, pos2)\r
+end\r
+\r
--digs a region defined by positions `pos1` and `pos2`, returning the number of nodes dug\r
worldedit.dig = function(pos1, pos2)\r
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
return\r
end\r
\r
- local found, _, searchnode, replacenode = param:find("([^%s]+)%s+([^%s]+)")\r
+ local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+([^%s]+)$")\r
if found == nil then\r
minetest.chat_send_player(name, "Invalid usage: " .. param)\r
return\r
return\r
end\r
\r
- local found, _, axis, amount = param:find("([xyz])%s+([+-]?%d+)")\r
+ local found, _, axis, amount = param:find("^([xyz])%s+([+-]?%d+)$")\r
if found == nil then\r
minetest.chat_send_player(name, "Invalid usage: " .. param)\r
return\r
return\r
end\r
\r
- local found, _, axis, amount = param:find("([xyz])%s+([+-]?%d+)")\r
+ local found, _, axis, amount = param:find("^([xyz])%s+([+-]?%d+)$")\r
if found == nil then\r
minetest.chat_send_player(name, "Invalid usage: " .. param)\r
return\r
return\r
end\r
\r
- local found, _, axis, count = param:find("([xyz])%s+([+-]?%d+)")\r
+ local found, _, axis, count = param:find("^([xyz])%s+([+-]?%d+)$")\r
if found == nil then\r
minetest.chat_send_player(name, "Invalid usage: " .. param)\r
return\r
end,\r
})\r
\r
+minetest.register_chatcommand("/transpose", {\r
+ params = "x/y/z x/y/z",\r
+ description = "Transpose the current WorldEdit region along the x/y/z and x/y/z axes",\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, _, axis1, axis2 = param:find("^([xyz])%s+([xyz])$")\r
+ if found == nil then\r
+ minetest.chat_send_player(name, "Invalid usage: " .. param)\r
+ return\r
+ end\r
+ if axis1 == axis2 then\r
+ minetest.chat_send_player(name, "Invalid usage: axes are the same")\r
+ return\r
+ end\r
+\r
+ local count = worldedit.transpose(pos1, pos2, axis1, axis2)\r
+ minetest.chat_send_player(name, count .. " nodes transposed")\r
+ end,\r
+})\r
+\r
+minetest.register_chatcommand("/flip", {\r
+ params = "x/y/z",\r
+ description = "Flip the current WorldEdit region along the x/y/z axis",\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
+ if param ~= "x" and param ~= "y" and param ~= "z" then\r
+ minetest.chat_send_player(name, "Invalid usage: " .. param)\r
+ return\r
+ end\r
+\r
+ local count = worldedit.flip(pos1, pos2, param)\r
+ minetest.chat_send_player(name, count .. " nodes flipped")\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
+ 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
+ angle = tonumber(param)\r
+ if angle == 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.rotate(pos1, pos2, angle)\r
+ minetest.chat_send_player(name, count .. " nodes rotated")\r
+ end,\r
+})\r
+\r
minetest.register_chatcommand("/dig", {\r
params = "",\r
description = "Dig the current WorldEdit region",\r