]> git.lizzy.rs Git - worldedit.git/commitdiff
Added hollow pyramids
authorSebastien Ponce <Sebastien.Ponce@cern.ch>
Sun, 13 Sep 2015 09:31:47 +0000 (11:31 +0200)
committerSebastien Ponce <Sebastien.Ponce@cern.ch>
Sun, 13 Sep 2015 20:08:04 +0000 (22:08 +0200)
ChatCommands.md
WorldEdit API.md
worldedit/primitives.lua
worldedit_commands/init.lua
worldedit_gui/functionality.lua
worldedit_shortcommands/init.lua

index 0c8b3a111886b68afe2c59b0fbc9fee751dbd54e..5b6c0c4fe07db8c1813a72f4fbbea19be12dbd67 100644 (file)
@@ -22,6 +22,9 @@ Many commands also have shorter names that can be typed faster. For example, if
 | `//hdo`    | `//hollowdome`     |\r
 | `//do`     | `//dome`           |\r
 | `//hcyl`   | `//hollowcylinder` |\r
+| `//cyl`    | `//cylinder`       |\r
+| `//hpyr`   | `//hollowpyramid`  |\r
+| `//pyr`    | `//pyramid`        |\r
 \r
 ### `//about`\r
 \r
@@ -190,6 +193,15 @@ Add cylinder at WorldEdit position 1 along the x/y/z/? axis with length `<length
     //cylinder z -12 3 mesecons:wire_00000000_off\r
     //cylinder ? 2 4 default:stone\r
     \r
+### `//hollowpyramid x/y/z? <height> <node>`\r
+\r
+Add hollow pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height `<height>`, composed of `<node>`.\r
+\r
+    //hollowpyramid x 8 Diamond Block\r
+    //hollowpyramid y -5 glass\r
+    //hollowpyramid z 2 mesecons:wire_00000000_off\r
+    //hollowpyramid ? 12 mesecons:wire_00000000_off\r
+\r
 ### `//pyramid x/y/z? <height> <node>`\r
 \r
 Add pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height `<height>`, composed of `<node>`.\r
index f50b5062c8dd192df55051758ee2eb83c24430c6..d1cd7d0f7a114dc8cf432da2ced6c8fb36ac6c79 100644 (file)
@@ -127,9 +127,9 @@ Adds a cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `
 \r
 Returns the number of nodes added.\r
 \r
-### count = worldedit.pyramid(pos, axis, height, node_name)\r
+### count = worldedit.pyramid(pos, axis, height, node_name, hollow)\r
 \r
-Adds a pyramid centered at `pos` along the `axis` axis ("x" or "y" or "z") with height `height`.\r
+Adds a pyramid centered at `pos` along the `axis` axis ("x" or "y" or "z") with height `height`, composed of `node_name`.\r
 \r
 Returns the number of nodes added.\r
 \r
index 6d3b026eb614e5af238a95c2eb6a409721c05a31..edb7db6935db1973f3e5ca6ca6de2dec3ce0b8fb 100644 (file)
@@ -150,8 +150,9 @@ end
 -- @param axis Axis ("x", "y", or "z")\r
 -- @param height Pyramid height.\r
 -- @param node_name Name of node to make pyramid of.\r
+-- @param hollow Whether the pyramid should be hollow.\r
 -- @return The number of nodes added.\r
-function worldedit.pyramid(pos, axis, height, node_name)\r
+function worldedit.pyramid(pos, axis, height, node_name, hollow)\r
        local other1, other2 = worldedit.get_axis_others(axis)\r
 \r
        -- Set up voxel manipulator\r
@@ -187,10 +188,12 @@ function worldedit.pyramid(pos, axis, height, node_name)
                        local new_index2 = new_index1 + (index2 + offset[other1]) * stride[other1]\r
                        for index3 = -size, size do\r
                                local i = new_index2 + (index3 + offset[other2]) * stride[other2]\r
-                               data[i] = node_id\r
+                               if (not hollow or size - math.abs(index2) < 2 or size - math.abs(index3) < 2) then\r
+                                      data[i] = node_id\r
+                                      count = count + 1\r
+                               end\r
                        end\r
                end\r
-               count = count + (size * 2 + 1) ^ 2\r
                size = size - 1\r
        end\r
 \r
index 83a127eaa73ba5f77fdc4117319461846b38cd92..08a9811ef2db72383f7d66fa9085d15cd04d24d9 100644 (file)
@@ -516,9 +516,25 @@ minetest.register_chatcommand("/cylinder", {
        end, check_cylinder),\r
 })\r
 \r
-minetest.register_chatcommand("/pyramid", {\r
+local check_pyramid = 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, _, axis, height, nodename = param:find("^([xyz%?])%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
+       height = tonumber(height)\r
+       return math.ceil(((height * 2 + 1) ^ 2) * height / 3)\r
+end\r
+     \r
+minetest.register_chatcommand("/hollowpyramid", {\r
        params = "x/y/z/? <height> <node>",\r
-       description = "Add pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height <height>, composed of <node>",\r
+       description = "Add hollow pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height <height>, composed of <node>",\r
        privs = {worldedit=true},\r
        func = safe_region(function(name, param)\r
                local found, _, axis, height, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(.+)$")\r
@@ -528,24 +544,26 @@ minetest.register_chatcommand("/pyramid", {
                        height = height * sign\r
                end\r
                local node = get_node(name, nodename)\r
-               local count = worldedit.pyramid(worldedit.pos1[name], axis, height, node)\r
+               local count = worldedit.pyramid(worldedit.pos1[name], axis, height, node, true)\r
                worldedit.player_notify(name, count .. " nodes added")\r
-       end,\r
-       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
+       end, check_pyramid),\r
+})\r
+\r
+minetest.register_chatcommand("/pyramid", {\r
+       params = "x/y/z/? <height> <node>",\r
+       description = "Add pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height <height>, composed of <node>",\r
+       privs = {worldedit=true},\r
+       func = safe_region(function(name, param)\r
                local found, _, axis, height, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(.+)$")\r
-               if found == nil then\r
-                       worldedit.player_notify(name, "invalid usage: " .. param)\r
-                       return nil\r
+               height = tonumber(height)\r
+               if axis == "?" then\r
+                       axis, sign = worldedit.player_axis(name)\r
+                       height = height * sign\r
                end\r
                local node = get_node(name, nodename)\r
-               if not node then return nil end\r
-               height = tonumber(height)\r
-               return math.ceil(((height * 2 + 1) ^ 2) * height / 3)\r
-       end),\r
+               local count = worldedit.pyramid(worldedit.pos1[name], axis, height, node)\r
+               worldedit.player_notify(name, count .. " nodes added")\r
+       end, check_pyramid),\r
 })\r
 \r
 minetest.register_chatcommand("/spiral", {\r
index 989c9eb2b11642f9944e7d9acd33ceca9ae39cf9..d3b78f61b55fa4db60317975c80591e50f0db95a 100644 (file)
@@ -295,18 +295,21 @@ worldedit.register_gui_function("worldedit_gui_pyramid", {
                                or "image[5.5,1.1;1,1;unknown_node.png]") ..\r
                        string.format("field[0.5,2.5;4,0.8;worldedit_gui_pyramid_length;Length;%s]", minetest.formspec_escape(length)) ..\r
                        string.format("dropdown[4,2.18;2.5;worldedit_gui_pyramid_axis;X axis,Y axis,Z axis,Look direction;%d]", axis) ..\r
-                       "button_exit[0,3.5;3,0.8;worldedit_gui_pyramid_submit;Pyramid]"\r
+                       "button_exit[0,3.5;3,0.8;worldedit_gui_pyramid_submit_hollow;Hollow Pyramid]" ..\r
+                       "button_exit[3.5,3.5;3,0.8;worldedit_gui_pyramid_submit_solid;Solid Pyramid]"\r
        end,\r
 })\r
 \r
 worldedit.register_gui_handler("worldedit_gui_pyramid", function(name, fields)\r
-       if fields.worldedit_gui_pyramid_search or fields.worldedit_gui_pyramid_submit then\r
+       if fields.worldedit_gui_pyramid_search or fields.worldedit_gui_pyramid_submit_solid or fields.worldedit_gui_pyramid_submit_hollow or fields.worldedit_gui_pyramid_axis then\r
                gui_nodename1[name] = tostring(fields.worldedit_gui_pyramid_node)\r
                gui_axis1[name] = axis_indices[fields.worldedit_gui_pyramid_axis]\r
                gui_distance1[name] = tostring(fields.worldedit_gui_pyramid_length)\r
                worldedit.show_page(name, "worldedit_gui_pyramid")\r
-               if fields.worldedit_gui_pyramid_submit then\r
+               if fields.worldedit_gui_pyramid_submit_solid then\r
                        minetest.chatcommands["/pyramid"].func(name, string.format("%s %s %s", axis_values[gui_axis1[name]], gui_distance1[name], gui_nodename1[name]))\r
+               elseif fields.worldedit_gui_pyramid_submit_hollow then\r
+                       minetest.chatcommands["/hollowpyramid"].func(name, string.format("%s %s %s", axis_values[gui_axis1[name]], gui_distance1[name], gui_nodename1[name]))\r
                end\r
                return true\r
        end\r
index a3cbb675d80bdf543d18fdd0f73cad953c1b0d2b..a4350ae50a3b0d49634166893dba82e2ce1c49cf 100644 (file)
@@ -31,6 +31,7 @@ worldedit.alias_chatcommand("/hdo", "/hollowdome")
 worldedit.alias_chatcommand("/do", "/dome")\r
 worldedit.alias_chatcommand("/hcyl", "/hollowcylinder")\r
 worldedit.alias_chatcommand("/cyl", "/cylinder")\r
+worldedit.alias_chatcommand("/hpyr", "/hollowpyramid")\r
 worldedit.alias_chatcommand("/pyr", "/pyramid")\r
 worldedit.alias_chatcommand("/spl", "/spiral")\r
 worldedit.alias_chatcommand("/m", "/move")\r
@@ -47,4 +48,4 @@ worldedit.alias_chatcommand("/hlt", "/highlight")
 worldedit.alias_chatcommand("/rsr", "/restore")\r
 worldedit.alias_chatcommand("/l", "/lua")\r
 worldedit.alias_chatcommand("/lt", "/luatransform")\r
-worldedit.alias_chatcommand("/clro", "/clearobjects")
\ No newline at end of file
+worldedit.alias_chatcommand("/clro", "/clearobjects")\r