//replace dirt flowers:flower_waterlily
//replace flowers:flower_rose flowers:flower_tulip
+### //hollowcylinder x/y/z <length> <radius> <node>
+
+Add hollow cylinder at WorldEdit position 1 along the x/y/z axis with length <length> and radius <radius>, composed of <node>.
+
+ //hollowcylinder x +5 8 dirt
+ //hollowcylinder y 28 10 default:glass
+ //hollowcylinder z -12 3 mesecons:mesecon
+
+### //cylinder x/y/z <length> <radius> <node>
+
+Add cylinder at WorldEdit position 1 along the x/y/z axis with length <length> and radius <radius>, composed of <node>.
+
+ //cylinder x +5 8 dirt
+ //cylinder y 28 10 default:glass
+ //cylinder z -12 3 mesecons:mesecon
+
### //copy x/y/z <amount>
Copy the current WorldEdit region along the x/y/z axis by <amount> nodes.
Returns the number of nodes replaced.
+### worldedit.hollow_cylinder(pos, axis, length, radius, nodename)
+
+Adds a hollow cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `length` and radius `radius`.
+
+Returns the number of nodes added.
+
+### worldedit.cylinder(pos, axis, length, radius, nodename)
+
+Adds a cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `length` and radius `radius`.
+
+Returns the number of nodes added.
+
### worldedit.copy(pos1, pos2, axis, amount)
Copies the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes.
return count\r
end\r
\r
+--adds a hollow cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `length` and radius `radius`, returning the number of nodes added\r
+worldedit.hollow_cylinder = function(pos, axis, length, radius, nodename)\r
+ local other1, other2\r
+ if axis == "x" then\r
+ other1, other2 = "y", "z"\r
+ elseif axis == "y" then\r
+ other1, other2 = "x", "z"\r
+ else --axis == "z"\r
+ other1, other2 = "x", "y"\r
+ end\r
+\r
+ local env = minetest.env\r
+ local currentpos = {x=pos.x, y=pos.y, z=pos.z}\r
+ local node = {name=nodename}\r
+ local count = 0\r
+ for i = 1, length do\r
+ local offset1, offset2 = 0, radius\r
+ local delta = -radius\r
+ while offset1 <= offset2 do\r
+ --add node at each octant\r
+ local first1, first2 = pos[other1] + offset1, pos[other1] - offset1\r
+ local second1, second2 = pos[other2] + offset2, pos[other2] - offset2\r
+ currentpos[other1], currentpos[other2] = first1, second1\r
+ env:add_node(currentpos, node) --octant 1\r
+ currentpos[other1] = first2\r
+ env:add_node(currentpos, node) --octant 4\r
+ currentpos[other2] = second2\r
+ env:add_node(currentpos, node) --octant 5\r
+ currentpos[other1] = first1\r
+ env:add_node(currentpos, node) --octant 8\r
+ local first1, first2 = pos[other1] + offset2, pos[other1] - offset2\r
+ local second1, second2 = pos[other2] + offset1, pos[other2] - offset1\r
+ currentpos[other1], currentpos[other2] = first1, second1\r
+ env:add_node(currentpos, node) --octant 2\r
+ currentpos[other1] = first2\r
+ env:add_node(currentpos, node) --octant 3\r
+ currentpos[other2] = second2\r
+ env:add_node(currentpos, node) --octant 6\r
+ currentpos[other1] = first1\r
+ env:add_node(currentpos, node) --octant 7\r
+\r
+ count = count + 8 --wip: broken\r
+\r
+ --move to next location\r
+ delta = delta + (offset1 * 2) + 1\r
+ if delta >= 0 then\r
+ offset2 = offset2 - 1\r
+ delta = delta - (offset2 * 2)\r
+ end\r
+ offset1 = offset1 + 1\r
+ end\r
+ currentpos[axis] = currentpos[axis] + 1\r
+ end\r
+ return count\r
+end\r
+\r
+--adds a cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `length` and radius `radius`, returning the number of nodes added\r
+worldedit.cylinder = function(pos, axis, length, radius, nodename)\r
+ local other1, other2\r
+ if axis == "x" then\r
+ other1, other2 = "y", "z"\r
+ elseif axis == "y" then\r
+ other1, other2 = "x", "z"\r
+ else --axis == "z"\r
+ other1, other2 = "x", "y"\r
+ end\r
+\r
+ local env = minetest.env\r
+ local currentpos = {x=pos.x, y=pos.y, z=pos.z}\r
+ local node = {name=nodename}\r
+ local count = 0\r
+ for i = 1, length do\r
+ local offset1, offset2 = 0, radius\r
+ local delta = -radius\r
+ while offset1 <= offset2 do\r
+ --connect each pair of octants\r
+ currentpos[other1] = pos[other1] - offset1\r
+ local second1, second2 = pos[other2] + offset2, pos[other2] - offset2\r
+ for i = 0, offset1 * 2 do\r
+ currentpos[other2] = second1\r
+ env:add_node(currentpos, node) --octant 1 to 4\r
+ currentpos[other2] = second2\r
+ env:add_node(currentpos, node) --octant 5 to 8\r
+ currentpos[other1] = currentpos[other1] + 1\r
+ end\r
+ currentpos[other1] = pos[other1] - offset2\r
+ local second1, second2 = pos[other2] + offset1, pos[other2] - offset1\r
+ for i = 0, offset2 * 2 do\r
+ currentpos[other2] = second1\r
+ env:add_node(currentpos, node) --octant 2 to 3\r
+ currentpos[other2] = second2\r
+ env:add_node(currentpos, node) --octant 6 to 7\r
+ currentpos[other1] = currentpos[other1] + 1\r
+ end\r
+\r
+ count = count + (offset1 * 4) + (offset2 * 4) + 4 --wip: broken\r
+\r
+ --move to next location\r
+ delta = delta + (offset1 * 2) + 1\r
+ offset1 = offset1 + 1\r
+ if delta >= 0 then\r
+ offset2 = offset2 - 1\r
+ delta = delta - (offset2 * 2)\r
+ end\r
+ end\r
+ currentpos[axis] = currentpos[axis] + 1\r
+ end\r
+ return count\r
+end\r
+\r
--copies the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes, returning the number of nodes copied\r
worldedit.copy = function(pos1, pos2, axis, amount)\r
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
\r
--determines whether `nodename` is a valid node name, returning a boolean\r
worldedit.node_is_valid = function(temp_pos, nodename)\r
- local originalnode = minetest.env:get_node(temp_pos) --save the original node to restore later\r
- minetest.env:add_node(temp_pos, {name=nodename}) --attempt to add the node\r
- local value = minetest.env:get_node(temp_pos).name --obtain the name of the newly added node\r
- if value == nodename or value == "default:" .. nodename then --successfully added node\r
- minetest.env:add_node(temp_pos, originalnode) --restore the original node\r
- return true --node is valid\r
- end\r
- return false --node is not valid\r
+ return minetest.registered_nodes[nodename] ~= nil\r
+ or minetest.registered_nodes["default:" .. nodename] ~= nil\r
end\r
\r
minetest.register_chatcommand("/reset", {\r
end,\r
})\r
\r
+minetest.register_chatcommand("/hollowcylinder", {\r
+ params = "x/y/z <length> <radius> <node>",\r
+ description = "Add hollow cylinder at WorldEdit position 1 along the x/y/z axis with length <length> and radius <radius>, composed of <node>",\r
+ privs = {worldedit=true},\r
+ func = function(name, param)\r
+ local pos = worldedit.pos1[name]\r
+ if pos == nil then\r
+ minetest.chat_send_player(name, "No WorldEdit region selected")\r
+ return\r
+ end\r
+\r
+ local found, _, axis, length, radius, nodename = param:find("^([xyz])%s+([+-]?%d+)%s+(%d+)%s+([^%s]+)$")\r
+ if found == nil then\r
+ minetest.chat_send_player(name, "Invalid usage: " .. param)\r
+ return\r
+ end\r
+ if not worldedit.node_is_valid(pos, nodename) then\r
+ minetest.chat_send_player(name, "Invalid node name: " .. param)\r
+ return\r
+ end\r
+\r
+ local count = worldedit.hollow_cylinder(pos, axis, tonumber(length), tonumber(radius), nodename)\r
+ minetest.chat_send_player(name, count .. " nodes added")\r
+ end,\r
+})\r
+\r
+minetest.register_chatcommand("/cylinder", {\r
+ params = "x/y/z <length> <radius> <node>",\r
+ description = "Add cylinder at WorldEdit position 1 along the x/y/z axis with length <length> and radius <radius>, composed of <node>",\r
+ privs = {worldedit=true},\r
+ func = function(name, param)\r
+ local pos = worldedit.pos1[name]\r
+ if pos == nil then\r
+ minetest.chat_send_player(name, "No WorldEdit region selected")\r
+ return\r
+ end\r
+\r
+ local found, _, axis, length, radius, nodename = param:find("^([xyz])%s+([+-]?%d+)%s+(%d+)%s+([^%s]+)$")\r
+ if found == nil then\r
+ minetest.chat_send_player(name, "Invalid usage: " .. param)\r
+ return\r
+ end\r
+ if not worldedit.node_is_valid(pos, nodename) then\r
+ minetest.chat_send_player(name, "Invalid node name: " .. param)\r
+ return\r
+ end\r
+\r
+ local count = worldedit.cylinder(pos, axis, tonumber(length), tonumber(radius), nodename)\r
+ minetest.chat_send_player(name, count .. " nodes added")\r
+ end,\r
+})\r
+\r
minetest.register_chatcommand("/copy", {\r
params = "x/y/z <amount>",\r
description = "Copy the current WorldEdit region along the x/y/z axis by <amount> nodes",\r