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