]> git.lizzy.rs Git - worldedit.git/commitdiff
Add //hollowcube and //cube
authorsfan5 <sfan5@live.de>
Thu, 31 Aug 2017 17:07:51 +0000 (19:07 +0200)
committersfan5 <sfan5@live.de>
Thu, 31 Aug 2017 17:08:10 +0000 (19:08 +0200)
closes #143

ChatCommands.md
WorldEdit API.md
worldedit/primitives.lua
worldedit_commands/init.lua
worldedit_shortcommands/init.lua

index 9d3f9d8901bc65348dce8685c4f3e344760230ab..2a43c0574959360e78d7f8ae39a7ee457bced39c 100644 (file)
@@ -17,6 +17,7 @@ Many commands also have shorter names that can be typed faster. For example, if
 | `//s`      | `//set`            |\r
 | `//r`      | `//replace`        |\r
 | `//ri`     | `//replaceinverse` |\r
+| `//hcube`  | `//hollowcube`     |\r
 | `//hspr`   | `//hollowsphere`   |\r
 | `//spr`    | `//sphere`         |\r
 | `//hdo`    | `//hollowdome`     |\r
@@ -143,6 +144,19 @@ Replace all nodes other than `<search node>` with `<replace node>` in the curren
     //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
index 8488305c7bac843b2cb89834be0fc0b9585a2be8..1106fc70055d5c9de6c077550ed83154e542cb2a 100644 (file)
@@ -115,6 +115,12 @@ Primitives
 ----------\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
index 9b86cd884959112965ff3fb6b514d03f4bd107c9..4a09fbae01dd4bf2fb656ac09c565843f53c5c82 100644 (file)
@@ -4,6 +4,47 @@
 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
index f423d674f5cca5b414531dc812709a84f6f26944..61231c321b3b93fc497951d30e19a13d9a93af5c 100644 (file)
@@ -455,6 +455,45 @@ minetest.register_chatcommand("/replaceinverse", {
        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
index a4350ae50a3b0d49634166893dba82e2ce1c49cf..da02b75262b0b96db6b865fda5abe67eeb8090e8 100644 (file)
@@ -25,6 +25,7 @@ worldedit.alias_chatcommand("/v", "/volume")
 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