| `//s` | `//set` |\r
| `//r` | `//replace` |\r
| `//ri` | `//replaceinverse` |\r
+| `//hcube` | `//hollowcube` |\r
| `//hspr` | `//hollowsphere` |\r
| `//spr` | `//sphere` |\r
| `//hdo` | `//hollowdome` |\r
//replaceinverse dirt Bronze Block\r
//replaceinverse mesecons:wire_00000000_off flowers:flower_tulip\r
\r
+### `//hollowcube <width> <height> <length> <node>`\r
+\r
+Adds a hollow cube with its ground level centered at WorldEdit position 1 with dimensions `<width>` x `<height>` x `<length>`, composed of `<node>`.\r
+\r
+ //hollowcube 6 5 6 Diamond Block\r
+\r
+### `//cube <width> <height> <length> <node>`\r
+\r
+Adds a cube with its ground level centered at WorldEdit position 1 with dimensions `<width>` x `<height>` x `<length>`, composed of `<node>`.\r
+\r
+ //cube 6 5 6 Diamond Block\r
+ //cube 7 2 1 default:cobble\r
+\r
### `//hollowsphere <radius> <node>`\r
\r
Add hollow sphere centered at WorldEdit position 1 with radius `<radius>`, composed of `<node>`.\r
----------\r
Contained in primitives.lua, this module allows the creation of several geometric primitives.\r
\r
+### count = worldedit.cube(pos, width, height, length, node_name, hollow)\r
+\r
+Adds a cube with its ground level centered at `pos`, the dimensions `width` x `height` x `length`, composed of `node_name`.\r
+\r
+Returns the number of nodes added.\r
+\r
### count = worldedit.sphere(pos, radius, node_name, hollow)\r
\r
Adds a sphere centered at `pos` with radius `radius`, composed of `node_name`.\r
local mh = worldedit.manip_helpers\r
\r
\r
+--- Adds a cube\r
+-- @param pos Position of ground level center of cube\r
+-- @param width Cube width. (x)\r
+-- @param height Cube height. (y)\r
+-- @param length Cube length. (z)\r
+-- @param node_name Name of node to make cube of.\r
+-- @param hollow Whether the cube should be hollow.\r
+-- @return The number of nodes added.\r
+function worldedit.cube(pos, width, height, length, node_name, hollow)\r
+ -- Set up voxel manipulator\r
+ local basepos = vector.subtract(pos, {x=math.floor(width/2), y=0, z=math.floor(length/2)})\r
+ local manip, area = mh.init(basepos, vector.add(basepos, {x=width, y=height, z=length}))\r
+ local data = mh.get_empty_data(area)\r
+\r
+ -- Add cube\r
+ local node_id = minetest.get_content_id(node_name)\r
+ local stride = {x=1, y=area.ystride, z=area.zstride}\r
+ local offset = vector.subtract(basepos, area.MinEdge)\r
+ local count = 0\r
+\r
+ for z = 0, length-1 do\r
+ local index_z = (offset.z + z) * stride.z + 1 -- +1 for 1-based indexing\r
+ for y = 0, height-1 do\r
+ local index_y = index_z + (offset.y + y) * stride.y\r
+ for x = 0, width-1 do\r
+ local is_wall = z == 0 or z == length-1\r
+ or y == 0 or y == height-1\r
+ or x == 0 or x == width-1\r
+ if not hollow or is_wall then\r
+ local i = index_y + (offset.x + x)\r
+ data[i] = node_id\r
+ count = count + 1\r
+ end\r
+ end\r
+ end\r
+ end\r
+\r
+ mh.finish(manip, data)\r
+ return count\r
+end\r
+\r
--- Adds a sphere of `node_name` centered at `pos`.\r
-- @param pos Position to center sphere at.\r
-- @param radius Sphere radius.\r
end, check_replace),\r
})\r
\r
+local check_cube = function(name, param)\r
+ if worldedit.pos1[name] == nil then\r
+ worldedit.player_notify(name, "no position 1 selected")\r
+ return nil\r
+ end\r
+ local found, _, w, h, l, nodename = param:find("^(%d+)%s+(%d+)%s+(%d+)%s+(.+)$")\r
+ if found == nil then\r
+ worldedit.player_notify(name, "invalid usage: " .. param)\r
+ return nil\r
+ end\r
+ local node = get_node(name, nodename)\r
+ if not node then return nil end\r
+ return tonumber(w) * tonumber(h) * tonumber(l)\r
+end\r
+\r
+minetest.register_chatcommand("/hollowcube", {\r
+ params = "<width> <height> <length> <node>",\r
+ description = "Add a hollow cube with its ground level centered at WorldEdit position 1 with dimensions <width> x <height> x <length>, composed of <node>.",\r
+ privs = {worldedit=true},\r
+ func = safe_region(function(name, param)\r
+ local found, _, w, h, l, nodename = param:find("^(%d+)%s+(%d+)%s+(%d+)%s+(.+)$")\r
+ local node = get_node(name, nodename)\r
+ local count = worldedit.cube(worldedit.pos1[name], tonumber(w), tonumber(h), tonumber(l), node, true)\r
+ worldedit.player_notify(name, count .. " nodes added")\r
+ end, check_cube),\r
+})\r
+\r
+minetest.register_chatcommand("/cube", {\r
+ params = "<width> <height> <length> <node>",\r
+ description = "Add a cube with its ground level centered at WorldEdit position 1 with dimensions <width> x <height> x <length>, composed of <node>.",\r
+ privs = {worldedit=true},\r
+ func = safe_region(function(name, param)\r
+ local found, _, w, h, l, nodename = param:find("^(%d+)%s+(%d+)%s+(%d+)%s+(.+)$")\r
+ local node = get_node(name, nodename)\r
+ local count = worldedit.cube(worldedit.pos1[name], tonumber(w), tonumber(h), tonumber(l), node)\r
+ worldedit.player_notify(name, count .. " nodes added")\r
+ end, check_cube),\r
+})\r
+\r
local check_sphere = function(name, param)\r
if worldedit.pos1[name] == nil then\r
worldedit.player_notify(name, "no position 1 selected")\r
worldedit.alias_chatcommand("/s", "/set")\r
worldedit.alias_chatcommand("/r", "/replace")\r
worldedit.alias_chatcommand("/ri", "/replaceinverse")\r
+worldedit.alias_chatcommand("/hcube", "/hollowcube")\r
worldedit.alias_chatcommand("/hspr", "/hollowsphere")\r
worldedit.alias_chatcommand("/spr", "/sphere")\r
worldedit.alias_chatcommand("/hdo", "/hollowdome")\r