]> git.lizzy.rs Git - worldedit.git/commitdiff
Clean up command code for //stack, //stack2
authorsfan5 <sfan5@live.de>
Sun, 8 Sep 2019 20:13:35 +0000 (22:13 +0200)
committersfan5 <sfan5@live.de>
Sun, 8 Sep 2019 20:14:07 +0000 (22:14 +0200)
worldedit_commands/init.lua

index 66fb264cc69576c682bcf99f609a02e93ed05d67..9cd5eeb2bf9467ad5d3aec2abf44c4efb618f9db 100644 (file)
@@ -819,8 +819,12 @@ minetest.register_chatcommand("/stack", {
                        axis, sign = worldedit.player_axis(name)\r
                        repetitions = repetitions * sign\r
                end\r
-               local count = worldedit.stack(worldedit.pos1[name], worldedit.pos2[name], axis, repetitions)\r
-               worldedit.player_notify(name, count .. " nodes stacked")\r
+\r
+               local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
+               local count = worldedit.volume(pos1, pos2) * math.abs(repetitions)\r
+               worldedit.stack(pos1, pos2, axis, repetitions, function()\r
+                       worldedit.player_notify(name, count .. " nodes stacked")\r
+               end)\r
        end,\r
        function(name, param)\r
                local found, _, axis, repetitions = param:find("^([xyz%?])%s+([+-]?%d+)$")\r
@@ -828,8 +832,9 @@ minetest.register_chatcommand("/stack", {
                        worldedit.player_notify(name, "invalid usage: " .. param)\r
                        return\r
                end\r
+\r
                local count = check_region(name, param)\r
-               if count then return (tonumber(repetitions) + 1) * count end\r
+               if count then return tonumber(repetitions) * count end\r
                return nil\r
        end),\r
 })\r
@@ -838,15 +843,9 @@ minetest.register_chatcommand("/stack2", {
        params = "<count> <x> <y> <z>",\r
        description = "Stack the current WorldEdit region <count> times by offset <x>, <y>, <z>",\r
        privs = {worldedit=true},\r
-       func = function(name, param)\r
-               local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
-               if pos1 == nil or pos2 == nil then\r
-                       worldedit.player_notify(name, "Select a position first!")\r
-                       return\r
-               end\r
+       func = safe_region(function(name, param)\r
                local repetitions, incs = param:match("(%d+)%s*(.+)")\r
                if repetitions == nil then\r
-                       worldedit.player_notify(name, "invalid count: " .. param)\r
                        return\r
                end\r
                repetitions = tonumber(repetitions)\r
@@ -858,15 +857,24 @@ minetest.register_chatcommand("/stack2", {
                end\r
                x, y, z = tonumber(x), tonumber(y), tonumber(z)\r
 \r
+               local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
                local count = worldedit.volume(pos1, pos2) * repetitions\r
+               worldedit.stack2(pos1, pos2, {x=x, y=y, z=z}, repetitions, function()\r
+                       worldedit.player_notify(name, count .. " nodes stacked")\r
+               end)\r
+       end,\r
+       function(name, param)\r
+               local repetitions, incs = param:match("(%d+)%s*(.+)")\r
+               if repetitions == nil then\r
+                       worldedit.player_notify(name, "invalid count: " .. param)\r
+                       return\r
+               end\r
+               repetitions = tonumber(repetitions)\r
 \r
-               return safe_region(function()\r
-                       worldedit.stack2(pos1, pos2, {x=x, y=y, z=z}, repetitions,\r
-                               function() worldedit.player_notify(name, count .. " nodes stacked") end)\r
-               end, function()\r
-                       return count\r
-               end)(name,param) -- more hax --wip: clean this up a little bit\r
-       end\r
+               local count = check_region(name, param)\r
+               if count then return repetitions * count end\r
+               return nil\r
+       end),\r
 })\r
 \r
 \r