]> git.lizzy.rs Git - worldedit.git/blobdiff - worldedit_commands/init.lua
Improve node inspector to show player axis, replace //scale with //stretch, which...
[worldedit.git] / worldedit_commands / init.lua
index f2bd1187f7897e9fc514146a38c91bc5f6d7378d..ab585728fa6a6b3410937d9ee8e7aa1ed9b49489 100644 (file)
@@ -61,16 +61,18 @@ minetest.register_chatcommand("/about", {
 })\r
 \r
 minetest.register_chatcommand("/inspect", {\r
-       params = "on/off/1/0/true/false/yes/no/enable/disable",\r
+       params = "on/off/1/0/true/false/yes/no/enable/disable/<blank>",\r
        description = "Enable or disable node inspection",\r
        privs = {worldedit=true},\r
        func = function(name, param)\r
-               if param == "on" or param == "1" or param == "true" or param == "yes" or param == "enable" then\r
+               if param == "on" or param == "1" or param == "true" or param == "yes" or param == "enable" or param == "" then\r
                        worldedit.inspect[name] = true\r
-                       worldedit.player_notify(name, "node inspection enabled")\r
+                       local axis, sign = worldedit.player_axis(name)\r
+                       worldedit.player_notify(name, string.format("inspector: inspection enabled for %s, currently facing the %s axis",\r
+                               name, axis .. (sign > 0 and "+" or "-")))\r
                elseif param == "off" or param == "0" or param == "false" or param == "no" or param == "disable" then\r
                        worldedit.inspect[name] = nil\r
-                       worldedit.player_notify(name, "node inspection disabled")\r
+                       worldedit.player_notify(name, "inspector: inspection disabled")\r
                else\r
                        worldedit.player_notify(name, "invalid usage: " .. param)\r
                end\r
@@ -81,7 +83,9 @@ minetest.register_on_punchnode(function(pos, node, puncher)
        local name = puncher:get_player_name()\r
        if worldedit.inspect[name] then\r
                if minetest.check_player_privs(name, {worldedit=true}) then\r
-                       message = "inspector: " .. node.name .. " at " .. minetest.pos_to_string(pos) .. " (param1=" .. node.param1 .. ", param2=" .. node.param2 .. ")"\r
+                       local axis, sign = worldedit.player_axis(name)\r
+                       message = string.format("inspector: %s at %s (param1=%d, param2=%d) punched by %s facing the %s axis",\r
+                               node.name, minetest.pos_to_string(pos), node.param1, node.param2, name, axis .. (sign > 0 and "+" or "-"))\r
                else\r
                        message = "inspector: worldedit privileges required"\r
                end\r
@@ -658,9 +662,9 @@ minetest.register_chatcommand("/stack", {
        end,\r
 })\r
 \r
-minetest.register_chatcommand("/scale", {\r
-       params = "<factor>",\r
-       description = "Scale the current WorldEdit positions and region by a factor of positive integer <factor> with position 1 as the origin",\r
+minetest.register_chatcommand("/stretch", {\r
+       params = "<stretchx> <stretchy> <stretchz>",\r
+       description = "Scale the current WorldEdit positions and region by a factor of <stretchx>, <stretchy>, <stretchz> along the X, Y, and Z axes, repectively, with position 1 as the origin",\r
        privs = {worldedit=true},\r
        func = function(name, param)\r
                local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
@@ -669,12 +673,17 @@ minetest.register_chatcommand("/scale", {
                        return\r
                end\r
 \r
-               local factor = tonumber(param)\r
-               if not factor or factor ~= math.floor(factor) or factor <= 0 then\r
+               local found, _, stretchx, stretchy, stretchz = param:find("^(%d+)%s+(%d+)%s+(%d+)$")\r
+               if found == nil then\r
+                       worldedit.player_notify(name, "invalid usage: " .. param)\r
+                       return\r
+               end\r
+               stretchx, stretchy, stretchz = tonumber(stretchx), tonumber(stretchy), tonumber(stretchz)\r
+               if stretchx == 0 or stretchy == 0 or stretchz == 0 then\r
                        worldedit.player_notify(name, "invalid scaling factor: " .. param)\r
                end\r
 \r
-               local count, pos1, pos2 = worldedit.scale(pos1, pos2, factor)\r
+               local count, pos1, pos2 = worldedit.stretch(pos1, pos2, stretchx, stretchy, stretchz)\r
 \r
                --reset markers to scaled positions\r
                worldedit.pos1[name] = pos1\r
@@ -682,7 +691,7 @@ minetest.register_chatcommand("/scale", {
                worldedit.mark_pos1(name)\r
                worldedit.mark_pos2(name)\r
 \r
-               worldedit.player_notify(name, count .. " nodes scaled")\r
+               worldedit.player_notify(name, count .. " nodes stretched")\r
        end,\r
 })\r
 \r
@@ -919,6 +928,10 @@ minetest.register_chatcommand("/save", {
                        worldedit.player_notify(name, "invalid usage: " .. param)\r
                        return\r
                end\r
+               if not string.find(param, "^[%w \t.,+-_=!@#$%%^&*()%[%]{};'\"]+$") then\r
+                       worldedit.player_notify(name, "invalid file name: " .. param)\r
+                       return\r
+               end\r
 \r
                local result, count = worldedit.serialize(pos1, pos2)\r
 \r
@@ -953,6 +966,10 @@ minetest.register_chatcommand("/allocate", {
                        worldedit.player_notify(name, "invalid usage: " .. param)\r
                        return\r
                end\r
+               if not string.find(param, "^[%w \t.,+-_=!@#$%%^&*()%[%]{};'\"]+$") then\r
+                       worldedit.player_notify(name, "invalid file name: " .. param)\r
+                       return\r
+               end\r
 \r
                local filename = minetest.get_worldpath() .. "/schems/" .. param .. ".we"\r
                local file, err = io.open(filename, "rb")\r
@@ -993,6 +1010,10 @@ minetest.register_chatcommand("/load", {
                        worldedit.player_notify(name, "invalid usage: " .. param)\r
                        return\r
                end\r
+               if not string.find(param, "^[%w \t.,+-_=!@#$%%^&*()%[%]{};'\"]+$") then\r
+                       worldedit.player_notify(name, "invalid file name: " .. param)\r
+                       return\r
+               end\r
 \r
                --find the file in the world path\r
                local testpaths = {\r