From 5f9efb1205fe9802f859548fc9220f98dd0fd12e Mon Sep 17 00:00:00 2001 From: Sebastien Ponce Date: Sun, 13 Sep 2015 11:31:47 +0200 Subject: Added hollow pyramids --- worldedit_commands/init.lua | 50 ++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 16 deletions(-) (limited to 'worldedit_commands') 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,9 +516,25 @@ minetest.register_chatcommand("/cylinder", { end, check_cylinder), }) -minetest.register_chatcommand("/pyramid", { +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 pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height , composed of ", + 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+(.+)$") @@ -528,24 +544,26 @@ minetest.register_chatcommand("/pyramid", { height = height * sign end local node = get_node(name, nodename) - local count = worldedit.pyramid(worldedit.pos1[name], axis, height, node) + local count = worldedit.pyramid(worldedit.pos1[name], axis, height, node, true) 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 + 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 ", + privs = {worldedit=true}, + func = safe_region(function(name, param) local found, _, axis, height, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(.+)$") - if found == nil then - worldedit.player_notify(name, "invalid usage: " .. param) - return nil + height = tonumber(height) + if axis == "?" then + axis, sign = worldedit.player_axis(name) + height = height * sign 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), + local count = worldedit.pyramid(worldedit.pos1[name], axis, height, node) + worldedit.player_notify(name, count .. " nodes added") + end, check_pyramid), }) minetest.register_chatcommand("/spiral", { -- cgit v1.2.3