]> git.lizzy.rs Git - worldedit.git/blobdiff - init.lua
Merge pull request #5 from khonkhortisan/master
[worldedit.git] / init.lua
index 6820bbfacc7ec7bc018d7008d44f4b984b7333fc..dcac7567fc28c5f14b4763ea84fe0fc495e1a262 100644 (file)
--- a/init.lua
+++ b/init.lua
@@ -16,16 +16,18 @@ worldedit.node_is_valid = function(temp_pos, nodename)
        or minetest.registered_nodes["default:" .. nodename] ~= nil\r
 end\r
 \r
+--determines the axis in which a player is facing, returning an axis ("x", "y", or "z") and the sign (1 or -1)\r
 worldedit.player_axis = function(name)\r
        local dir = minetest.env:get_player_by_name(name):get_look_dir()\r
-       if dir.x > dir.y then\r
-               if dir.x > dir.z then\r
-                       return "x"\r
+       local x, y, z = math.abs(dir.x), math.abs(dir.y), math.abs(dir.z)\r
+       if x > y then\r
+               if x > z then\r
+                       return "x", dir.x > 0 and 1 or -1\r
                end\r
-       elseif dir.y > dir.z then\r
-               return "y"\r
+       elseif y > z then\r
+               return "y", dir.y > 0 and 1 or -1\r
        end\r
-       return "z"\r
+       return "z", dir.z > 0 and 1 or -1\r
 end\r
 \r
 minetest.register_chatcommand("/reset", {\r
@@ -204,7 +206,8 @@ minetest.register_chatcommand("/hollowcylinder", {
                        return\r
                end\r
                if axis == "?" then\r
-                       axis = worldedit.player_axis(name)\r
+                       axis, sign = worldedit.player_axis(name)\r
+                       length = length * sign\r
                end\r
                if not worldedit.node_is_valid(pos, nodename) then\r
                        minetest.chat_send_player(name, "Invalid node name: " .. param)\r
@@ -216,10 +219,9 @@ minetest.register_chatcommand("/hollowcylinder", {
        end,\r
 })\r
 \r
-\r
 minetest.register_chatcommand("/spiral", {\r
        params = "<size> <node>",\r
-       description = "Add Spiral at WorldEdit position 1 with size <size>, composed of <node>",\r
+       description = "Add spiral at WorldEdit position 1 with size <size>, composed of <node>",\r
        privs = {worldedit=true},\r
        func = function(name, param)\r
                local pos = worldedit.pos1[name]\r
@@ -260,7 +262,8 @@ minetest.register_chatcommand("/cylinder", {
                        return\r
                end\r
                if axis == "?" then\r
-                       axis = worldedit.player_axis(name)\r
+                       axis, sign = worldedit.player_axis(name)\r
+                       length = length * sign\r
                end\r
                if not worldedit.node_is_valid(pos, nodename) then\r
                        minetest.chat_send_player(name, "Invalid node name: " .. param)\r
@@ -289,7 +292,8 @@ minetest.register_chatcommand("/copy", {
                        return\r
                end\r
                if axis == "?" then\r
-                       axis = worldedit.player_axis(name)\r
+                       axis, sign = worldedit.player_axis(name)\r
+                       amount = amount * sign\r
                end\r
 \r
                local count = worldedit.copy(pos1, pos2, axis, tonumber(amount))\r
@@ -314,7 +318,8 @@ minetest.register_chatcommand("/move", {
                        return\r
                end\r
                if axis == "?" then\r
-                       axis = worldedit.player_axis(name)\r
+                       axis, sign = worldedit.player_axis(name)\r
+                       amount = amount * sign\r
                end\r
 \r
                local count = worldedit.move(pos1, pos2, axis, tonumber(amount))\r
@@ -339,7 +344,8 @@ minetest.register_chatcommand("/stack", {
                        return\r
                end\r
                if axis == "?" then\r
-                       axis = worldedit.player_axis(name)\r
+                       axis, sign = worldedit.player_axis(name)\r
+                       count = count * sign\r
                end\r
 \r
                local count = worldedit.stack(pos1, pos2, axis, tonumber(count))\r