]> git.lizzy.rs Git - worldedit.git/commitdiff
Improve node inspector to show player axis, replace //scale with //stretch, which...
authorUberi <azhang9@gmail.com>
Fri, 20 Dec 2013 23:41:13 +0000 (18:41 -0500)
committerUberi <azhang9@gmail.com>
Fri, 20 Dec 2013 23:41:13 +0000 (18:41 -0500)
Chat Commands.md
README.md
WorldEdit API.md
worldedit/compatibility.lua
worldedit/manipulations.lua
worldedit_commands/init.lua

index 1524dfe1b53f34b103fd26706c47a690addef957..04c8116f478470fccfe94eb2f98195d36f8609cc 100644 (file)
@@ -22,6 +22,7 @@ Enable or disable node inspection.
     //inspect no\r
     //inspect enable\r
     //inspect disable\r
+    //inspect\r
 \r
 ### //reset\r
 \r
index 9827e0748068f06087910ee89d65333e3f411b8b..e94bcdff6c2523b92b526845c026f4455967b7d7 100644 (file)
--- a/README.md
+++ b/README.md
@@ -37,7 +37,7 @@ WorldEdit works primarily through the WorldEdit GUI and chat commands. Depending
 
 WorldEdit has a huge potential for abuse by untrusted players. Therefore, users will not be able to use WorldEdit unless they have the `worldedit` privelege. This is available by default in single player, but in multiplayer the permission must be explicitly given by someone with the right credentials, using the follwoing chat command: `/grant <player name> worldedit`. This privelege can later be removed using the following chat command: `/revoke <player name> worldedit`.
 
-Certain functions/commands such as WorldEdit GUI's "Run Lua" (equivalent to the `//lua` chat command) additionally require the `server` privilege. This is because it is extremely dangerous to give access to these commands to untrusted players, since they essentially are able to control the computer the server is running on. Give this privilege only to people you trust with your computer.
+Certain functions/commands such as WorldEdit GUI's "Run Lua" function (equivalent to the `//lua` and `//luatransform` chat command) additionally require the `server` privilege. This is because it is extremely dangerous to give access to these commands to untrusted players, since they essentially are able to control the computer the server is running on. Give this privilege only to people you trust with your computer.
 
 For in-game information about these commands, type `/help <command name>` in the chat. For example, to learn more about the `//copy` command, simply type `/help /copy` to display information relevant to copying a region.
 
index 4169cbe5d91e745b31e64d15aa454c34297e6aa0..c05958e84ac6df76c0572ebb7c0469344d6cb751 100644 (file)
@@ -57,11 +57,11 @@ Duplicates the region defined by positions `pos1` and `pos2` along the `axis` ax
 \r
 Returns the number of nodes stacked.\r
 \r
-### count, newpos1, newpos2 = worldedit.scale(pos1, pos2, factor)\r
+### count, newpos1, newpos2 = worldedit.stretch(pos1, pos2, stretchx, stretchy, stretchz)\r
 \r
-Scales the region defined by positions `pos1` and `pos2` by an factor of positive integer `factor` with `pos1` as the origin.\r
+Stretches the region defined by positions `pos1` and `pos2` by an factor of positive integers `stretchx`, `stretchy`. and `stretchz` along the X, Y, and Z axes, respectively, with `pos1` as the origin.\r
 \r
-Returns the number of nodes scaled, the new scaled position 1, and the new scaled position 2.\r
+Returns the number of nodes stretched, the new scaled position 1, and the new scaled position 2.\r
 \r
 ### count, newpos1, newpos2 = worldedit.transpose(pos1, pos2, axis1, axis2)\r
 \r
index eb81eeacaaaccd76898b3a4f1cf97ba908dd1d05..ff3447ff9327fde301295eb3b6bc5e779562f46c 100644 (file)
@@ -18,3 +18,6 @@ worldedit.metaload = function(originpos, filename)
        local data = file:read("*a")\r
        return worldedit.deserialize(originpos, data)\r
 end\r
+worldedit.scale = function(pos1, pos2, factor)\r
+       return worldedit.stretch(pos1, pos2, factor, factor, factor)\r
+end
\ No newline at end of file
index eee0bb8f2583d1d2ac0aff11c98cfb5eb21b27c9..1d4c6dc2096a1c04e3ff387513be56eb7d9eaf3a 100644 (file)
@@ -109,7 +109,7 @@ worldedit.replaceinverse = function(pos1, pos2, searchnode, replacenode)
        return count\r
 end\r
 \r
-worldedit.copy = function(pos1, pos2, axis, amount)\r
+worldedit.copy = function(pos1, pos2, axis, amount) --wip: replace the old version below\r
        local pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
 \r
        if amount == 0 then\r
@@ -291,24 +291,28 @@ worldedit.stack = function(pos1, pos2, axis, count)
        return worldedit.volume(pos1, pos2) * count\r
 end\r
 \r
---scales the region defined by positions `pos1` and `pos2` by an factor of positive integer `factor` with `pos1` as the origin, returning the number of nodes scaled, the new scaled position 1, and the new scaled position 2\r
-worldedit.scale = function(pos1, pos2, factor)\r
+--stretches the region defined by positions `pos1` and `pos2` by an factor of positive integers `stretchx`, `stretchy`. and `stretchz` along the X, Y, and Z axes, respectively, with `pos1` as the origin, returning the number of nodes scaled, the new scaled position 1, and the new scaled position 2\r
+worldedit.stretch = function(pos1, pos2, stretchx, stretchy, stretchz) --wip: test this\r
        local pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
 \r
        --prepare schematic of large node\r
        local get_node, get_meta, place_schematic = minetest.get_node, minetest.get_meta, minetest.place_schematic\r
        local placeholder_node = {name="", param1=255, param2=0}\r
        local nodes = {}\r
-       for i = 1, factor ^ 3 do\r
+       for i = 1, stretchx * stretchy * stretchz do\r
                nodes[i] = placeholder_node\r
        end\r
-       local schematic = {size={x=factor, y=factor, z=factor}, data=nodes}\r
+       local schematic = {size={x=stretchx, y=stretchy, z=stretchz}, data=nodes}\r
 \r
-       local size = factor - 1\r
+       local sizex, sizey, sizez = stretchx - 1, stretchy - 1, stretchz - 1\r
 \r
        --make area stay loaded\r
        local manip = minetest.get_voxel_manip()\r
-       local new_pos2 = {x=pos1.x + (pos2.x - pos1.x) * factor + size, y=pos1.y + (pos2.y - pos1.y) * factor + size, z=pos1.z + (pos2.z - pos1.z) * factor + size}\r
+       local new_pos2 = {\r
+               x=pos1.x + (pos2.x - pos1.x) * stretchx + sizex,\r
+               y=pos1.y + (pos2.y - pos1.y) * stretchy + sizey,\r
+               z=pos1.z + (pos2.z - pos1.z) * stretchz + sizez,\r
+       }\r
        manip:read_from_map(pos1, new_pos2)\r
 \r
        local pos = {x=pos2.x, y=0, z=0}\r
@@ -321,8 +325,10 @@ worldedit.scale = function(pos1, pos2, factor)
                                local node = get_node(pos) --obtain current node\r
                                local meta = get_meta(pos):to_table() --get meta of current node\r
 \r
-                               local value = pos[axis] --store current position\r
-                               local posx, posy, posz = pos1.x + (pos.x - pos1.x) * factor, pos1.y + (pos.y - pos1.y) * factor, pos1.z + (pos.z - pos1.z) * factor\r
+                               --calculate far corner of the big node\r
+                               local posx = pos1.x + (pos.x - pos1.x) * stretchx\r
+                               local posy = pos1.y + (pos.y - pos1.y) * stretchy\r
+                               local posz = pos1.z + (pos.z - pos1.z) * stretchz\r
 \r
                                --create large node\r
                                placeholder_node.name = node.name\r
@@ -331,10 +337,10 @@ worldedit.scale = function(pos1, pos2, factor)
                                place_schematic(bigpos, schematic)\r
 \r
                                --fill in large node meta\r
-                               if next(meta.fields) ~= nil and next(meta.inventory) ~= nil then --node has meta fields\r
-                                       for x = 0, size do\r
-                                               for y = 0, size do\r
-                                                       for z = 0, size do\r
+                               if next(meta.fields) ~= nil or next(meta.inventory) ~= nil then --node has meta fields\r
+                                       for x = 0, sizex do\r
+                                               for y = 0, sizey do\r
+                                                       for z = 0, sizez do\r
                                                                bigpos.x, bigpos.y, bigpos.z = posx + x, posy + y, posz + z\r
                                                                get_meta(bigpos):from_table(meta) --set metadata of new node\r
                                                        end\r
@@ -347,7 +353,7 @@ worldedit.scale = function(pos1, pos2, factor)
                end\r
                pos.x = pos.x - 1\r
        end\r
-       return worldedit.volume(pos1, pos2) * (factor ^ 3), pos1, new_pos2\r
+       return worldedit.volume(pos1, pos2) * stretchx * stretchy * stretchz, pos1, new_pos2\r
 end\r
 \r
 --transposes a region defined by the positions `pos1` and `pos2` between the `axis1` and `axis2` axes, returning the number of nodes transposed, the new transposed position 1, and the new transposed position 2\r
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