Changes: fixed rotation and transposition of non-sqaure regions, makers are now moved to the new region boundaries after rotation/transposition, small consistency fixes, finally fix the /hide command.
\r
### //transpose x/y/z/? x/y/z/?\r
\r
-Transpose the current WorldEdit region along the x/y/z/? and x/y/z/? axes.\r
+Transpose the current WorldEdit positions and region along the x/y/z/? and x/y/z/? axes.\r
\r
//transpose x y\r
//transpose x z\r
\r
### //rotate x/y/z/? <angle>\r
\r
-Rotate the current WorldEdit region along the x/y/z/? axis by angle <angle> (90 degree increment).\r
+Rotate the current WorldEdit positions and region along the x/y/z/? axis by angle <angle> (integer multiple of 90 degrees).\r
\r
//rotate x 90\r
//rotate y 180\r
\r
Returns the number of nodes stacked.\r
\r
-### count = worldedit.transpose(pos1, pos2, axis1, axis2)\r
+### count, newpos1, newpos2 = worldedit.transpose(pos1, pos2, axis1, axis2)\r
\r
Transposes a region defined by the positions `pos1` and `pos2` between the `axis1` and `axis2` axes ("x" or "y" or "z").\r
\r
-Returns the number of nodes transposed.\r
+Returns the number of nodes transposed, the new position 1, and the new position 2.\r
\r
### count = worldedit.flip(pos1, pos2, axis)\r
\r
\r
Returns the number of nodes flipped.\r
\r
-### count = worldedit.rotate(pos1, pos2, angle)\r
+### count, newpos2, newpos2 = worldedit.rotate(pos1, pos2, angle)\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).\r
\r
-Returns the number of nodes rotated.\r
+Returns the number of nodes rotated, the new position 1, and the new position 2.\r
\r
### count = worldedit.dig(pos1, pos2)\r
\r
\r
Adds a spiral at `pos` with width `width`, height `height`, space between walls `spacer`, composed of `nodename`.\r
\r
+Returns the number of nodes added.\r
+\r
Visualization\r
-------------\r
Contained in visualization.lua, this module allows nodes to be visualized in different ways.\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
+--transposes a region defined by the positions `pos1` and `pos2` between the `axis1` and `axis2` axes, returning the number of nodes transposed, the new position 1, and the new position 2\r
worldedit.transpose = function(pos1, pos2, axis1, axis2)\r
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
\r
+ local compare\r
+ local extent1, extent2 = pos2[axis1] - pos1[axis1], pos2[axis2] - pos1[axis2]\r
+\r
+ if extent1 > extent2 then\r
+ compare = function(extent1, extent2)\r
+ return extent1 > extent2\r
+ end\r
+ else\r
+ compare = function(extent1, extent2)\r
+ return extent1 < extent2\r
+ end\r
+ end\r
+\r
+ --calculate the new position 2 after transposition\r
+ local newpos2 = {x=pos1.x, y=pos1.y, z=pos1.z}\r
+ newpos2[axis1] = pos1[axis1] + extent2\r
+ newpos2[axis2] = pos1[axis2] + extent1\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.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
+ if compare(extent1, extent2) then --transpose only if below the diagonal\r
local node1 = env:get_node(pos)\r
local meta1 = env:get_meta(pos):to_table()\r
- local value1, value2 = pos[axis1], pos[axis2]\r
- pos[axis1], pos[axis2] = value1 + extent2, value2 + extent1\r
+ local value1, value2 = pos[axis1], pos[axis2] --save position values\r
+ pos[axis1], pos[axis2] = pos1[axis1] + extent2, pos1[axis2] + extent1 --swap axis extents\r
local node2 = env:get_node(pos)\r
local meta2 = env:get_meta(pos):to_table()\r
env:add_node(pos, node1)\r
env:get_meta(pos):from_table(meta1)\r
- pos[axis1], pos[axis2] = value1, value2\r
+ pos[axis1], pos[axis2] = value1, value2 --restore position values\r
env:add_node(pos, node2)\r
env:get_meta(pos):from_table(meta2)\r
end\r
end\r
pos.x = pos.x + 1\r
end\r
- return worldedit.volume(pos1, pos2)\r
+ return worldedit.volume(pos1, pos2), pos1, newpos2\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
end\r
angle = angle % 360\r
\r
+ local count\r
if angle == 90 then\r
- worldedit.transpose(pos1, pos2, axis1, axis2)\r
- worldedit.flip(pos1, pos2, axis2)\r
+ worldedit.flip(pos1, pos2, axis1)\r
+ count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2)\r
elseif angle == 180 then\r
worldedit.flip(pos1, pos2, axis1)\r
- worldedit.flip(pos1, pos2, axis2)\r
+ count = worldedit.flip(pos1, pos2, axis2)\r
elseif angle == 270 then\r
- worldedit.transpose(pos1, pos2, axis1, axis2)\r
- worldedit.flip(pos1, pos2, axis1)\r
+ worldedit.flip(pos1, pos2, axis2)\r
+ count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2)\r
end\r
- return worldedit.volume(pos1, pos2)\r
+ return count, pos1, pos2\r
end\r
\r
--digs a region defined by positions `pos1` and `pos2`, returning the number of nodes dug\r
worldedit.pos1[name] = pos\r
worldedit.mark_pos1(name)\r
worldedit.set_pos[name] = "pos2" --set position 2 on the next invocation\r
- minetest.chat_send_player(name, "WorldEdit region position 1 set to " .. minetest.pos_to_string(pos))\r
+ minetest.chat_send_player(name, "WorldEdit position 1 set to " .. minetest.pos_to_string(pos))\r
elseif worldedit.set_pos[name] == "pos1only" then --setting position 1 only\r
worldedit.pos1[name] = pos\r
worldedit.mark_pos1(name)\r
worldedit.set_pos[name] = nil --finished setting positions\r
- minetest.chat_send_player(name, "WorldEdit region position 1 set to " .. minetest.pos_to_string(pos))\r
+ minetest.chat_send_player(name, "WorldEdit position 1 set to " .. minetest.pos_to_string(pos))\r
elseif worldedit.set_pos[name] == "pos2" then --setting position 2\r
worldedit.pos2[name] = pos\r
worldedit.mark_pos2(name)\r
worldedit.set_pos[name] = nil --finished setting positions\r
- minetest.chat_send_player(name, "WorldEdit region position 2 set to " .. minetest.pos_to_string(pos))\r
+ minetest.chat_send_player(name, "WorldEdit position 2 set to " .. minetest.pos_to_string(pos))\r
end\r
end\r
end)\r
return\r
end\r
\r
- local count = worldedit.transpose(pos1, pos2, axis1, axis2)\r
+ local count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2)\r
+\r
+ --reset markers to transposed positions\r
+ worldedit.pos1[name] = pos1\r
+ worldedit.pos2[name] = pos2\r
+ worldedit.mark_pos1(name)\r
+ worldedit.mark_pos2(name)\r
+\r
minetest.chat_send_player(name, count .. " nodes transposed")\r
end,\r
})\r
return\r
end\r
\r
- local count = worldedit.rotate(pos1, pos2, axis, angle)\r
+ local count, pos1, pos2 = worldedit.rotate(pos1, pos2, axis, angle)\r
+\r
+ --reset markers to rotated positions\r
+ worldedit.pos1[name] = pos1\r
+ worldedit.pos2[name] = pos2\r
+ worldedit.mark_pos1(name)\r
+ worldedit.mark_pos2(name)\r
+\r
minetest.chat_send_player(name, count .. " nodes rotated")\r
end,\r
})\r
})\r
\r
minetest.register_chatcommand("/hide", {\r
+ params = "",\r
+ description = "Hide all nodes in the current WorldEdit region non-destructively",\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 count = worldedit.hide(pos1, pos2)\r
+ minetest.chat_send_player(name, count .. " nodes hidden")\r
+ end,\r
+})\r
+\r
+minetest.register_chatcommand("/suppress", {\r
params = "<node>",\r
- description = "Hide all <node> in the current WorldEdit region non-destructively",\r
+ description = "Suppress all <node> in the current WorldEdit region non-destructively",\r
privs = {worldedit=true},\r
func = function(name, param)\r
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
return\r
end\r
\r
- local count = worldedit.hide(pos1, pos2, param)\r
- minetest.chat_send_player(name, count .. " nodes hidden")\r
+ local count = worldedit.suppress(pos1, pos2, param)\r
+ minetest.chat_send_player(name, count .. " nodes suppressed")\r
end,\r
})\r
\r