]> git.lizzy.rs Git - worldedit.git/blobdiff - worldedit_commands/init.lua
Support negative values to make upside-down domes and pyramids (slight changes to...
[worldedit.git] / worldedit_commands / init.lua
index 0ecd0937474ef46df72f4fcb52dbc56c99a9b91c..44768a3b97ca1a1f013ae6d5920b622e5b4543c4 100644 (file)
@@ -1,6 +1,7 @@
 minetest.register_privilege("worldedit", "Can use WorldEdit commands")\r
 \r
 worldedit.set_pos = {}\r
+worldedit.inspect = {}\r
 \r
 worldedit.pos1 = {}\r
 worldedit.pos2 = {}\r
@@ -49,19 +50,17 @@ worldedit.player_axis = function(name)
        return "z", dir.z > 0 and 1 or -1\r
 end\r
 \r
-worldedit.inspect = true\r
-\r
 minetest.register_chatcommand("/inspect", {\r
        params = "on/off/1/0/true/false/yes/no/enable/disable",\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
-                       worldedit.inspect = true\r
-                       worldedit.player_notify(name, "node inspection is now on")\r
+                       worldedit.inspect[name] = true\r
+                       worldedit.player_notify(name, "node inspection enabled")\r
                elseif param == "off" or param == "0" or param == "false" or param == "no" or param == "disable" then\r
-                       worldedit.inspect = false\r
-                       worldedit.player_notify(name, "node inspection is now off")\r
+                       worldedit.inspect[name] = nil\r
+                       worldedit.player_notify(name, "node inspection disabled")\r
                else\r
                        worldedit.player_notify(name, "invalid usage: " .. param)\r
                end\r
@@ -69,9 +68,14 @@ minetest.register_chatcommand("/inspect", {
 })\r
 \r
 minetest.register_on_punchnode(function(pos, node, puncher)\r
-       if worldedit.inspect then\r
-               message = "node inspector: " .. node.name .. " at " .. minetest.pos_to_string(pos) .. " (param1=" .. node.param1 .. ", param2=" .. node.param2 .. ")"\r
-               worldedit.player_notify(puncher:get_player_name(), message)\r
+       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
+               else\r
+                       message = "inspector: worldedit privileges required"\r
+               end\r
+               worldedit.player_notify(name, message)\r
        end\r
 end)\r
 \r
@@ -408,7 +412,7 @@ minetest.register_chatcommand("/hollowdome", {
                        return\r
                end\r
 \r
-               local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")\r
+               local found, _, radius, nodename = param:find("^([+-]?%d+)%s+(.+)$")\r
                if found == nil then\r
                        worldedit.player_notify(name, "invalid usage: " .. param)\r
                        return\r
@@ -439,7 +443,7 @@ minetest.register_chatcommand("/dome", {
                        return\r
                end\r
 \r
-               local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")\r
+               local found, _, radius, nodename = param:find("^([+-]?%d+)%s+(.+)$")\r
                if found == nil then\r
                        worldedit.player_notify(name, "invalid usage: " .. param)\r
                        return\r
@@ -475,6 +479,7 @@ minetest.register_chatcommand("/hollowcylinder", {
                        worldedit.player_notify(name, "invalid usage: " .. param)\r
                        return\r
                end\r
+               length, radius = tonumber(length), tonumber(radius)\r
                if axis == "?" then\r
                        axis, sign = worldedit.player_axis(name)\r
                        length = length * sign\r
@@ -489,7 +494,7 @@ minetest.register_chatcommand("/hollowcylinder", {
                if worldedit.ENABLE_QUEUE then\r
                        tenv = worldedit.queue_aliasenv\r
                end\r
-               local count = worldedit.hollow_cylinder(pos, axis, tonumber(length), tonumber(radius), node, tenv)\r
+               local count = worldedit.hollow_cylinder(pos, axis, length, radius, node, tenv)\r
                worldedit.player_notify(name, count .. " nodes added")\r
        end,\r
 })\r
@@ -510,6 +515,7 @@ minetest.register_chatcommand("/cylinder", {
                        worldedit.player_notify(name, "invalid usage: " .. param)\r
                        return\r
                end\r
+               length, radius = tonumber(length), tonumber(radius)\r
                if axis == "?" then\r
                        axis, sign = worldedit.player_axis(name)\r
                        length = length * sign\r
@@ -524,14 +530,14 @@ minetest.register_chatcommand("/cylinder", {
                if worldedit.ENABLE_QUEUE then\r
                        tenv = worldedit.queue_aliasenv\r
                end\r
-               local count = worldedit.cylinder(pos, axis, tonumber(length), tonumber(radius), node, tenv)\r
+               local count = worldedit.cylinder(pos, axis, length, radius, node, tenv)\r
                worldedit.player_notify(name, count .. " nodes added")\r
        end,\r
 })\r
 \r
 minetest.register_chatcommand("/pyramid", {\r
-       params = "<height> <node>",\r
-       description = "Add pyramid centered at WorldEdit position 1 with height <height>, composed of <node>",\r
+       params = "x/y/z/? <height> <node>",\r
+       description = "Add pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height <height>, composed of <node>",\r
        privs = {worldedit=true},\r
        func = function(name, param)\r
                local pos = worldedit.pos1[name]\r
@@ -540,22 +546,23 @@ minetest.register_chatcommand("/pyramid", {
                        return\r
                end\r
 \r
-               local found, _, size, nodename = param:find("(%d+)%s+(.+)$")\r
+               local found, _, axis, height, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(.+)$")\r
                if found == nil then\r
                        worldedit.player_notify(name, "invalid usage: " .. param)\r
                        return\r
                end\r
+               height = tonumber(height)\r
+               if axis == "?" then\r
+                       axis, sign = worldedit.player_axis(name)\r
+                       height = height * sign\r
+               end\r
                local node = worldedit.normalize_nodename(nodename)\r
                if not node then\r
                        worldedit.player_notify(name, "invalid node name: " .. nodename)\r
                        return\r
                end\r
 \r
-               local tenv = minetest.env\r
-               if worldedit.ENABLE_QUEUE then\r
-                       tenv = worldedit.queue_aliasenv\r
-               end\r
-               local count = worldedit.pyramid(pos, tonumber(size), node, tenv)\r
+               local count = worldedit.pyramid(pos, axis, height, node)\r
                worldedit.player_notify(name, count .. " nodes added")\r
        end,\r
 })\r
@@ -571,7 +578,7 @@ minetest.register_chatcommand("/spiral", {
                        return\r
                end\r
 \r
-               local found, _, width, height, space, nodename = param:find("(%d+)%s+(%d+)%s+(%d+)%s+(.+)$")\r
+               local found, _, width, height, space, nodename = param:find("^(%d+)%s+(%d+)%s+(%d+)%s+(.+)$")\r
                if found == nil then\r
                        worldedit.player_notify(name, "invalid usage: " .. param)\r
                        return\r
@@ -607,6 +614,7 @@ minetest.register_chatcommand("/copy", {
                        worldedit.player_notify(name, "invalid usage: " .. param)\r
                        return\r
                end\r
+               amount = tonumber(amount)\r
                if axis == "?" then\r
                        axis, sign = worldedit.player_axis(name)\r
                        amount = amount * sign\r
@@ -616,7 +624,7 @@ minetest.register_chatcommand("/copy", {
                if worldedit.ENABLE_QUEUE then\r
                        tenv = worldedit.queue_aliasenv\r
                end\r
-               local count = worldedit.copy(pos1, pos2, axis, tonumber(amount), tenv)\r
+               local count = worldedit.copy(pos1, pos2, axis, amount, tenv)\r
                worldedit.player_notify(name, count .. " nodes copied")\r
        end,\r
 })\r
@@ -637,6 +645,7 @@ minetest.register_chatcommand("/move", {
                        worldedit.player_notify(name, "invalid usage: " .. param)\r
                        return\r
                end\r
+               amount = tonumber(amount)\r
                if axis == "?" then\r
                        axis, sign = worldedit.player_axis(name)\r
                        amount = amount * sign\r
@@ -646,7 +655,7 @@ minetest.register_chatcommand("/move", {
                if worldedit.ENABLE_QUEUE then\r
                        tenv = worldedit.queue_aliasenv\r
                end\r
-               local count = worldedit.move(pos1, pos2, axis, tonumber(amount), tenv)\r
+               local count = worldedit.move(pos1, pos2, axis, amount, tenv)\r
 \r
                pos1[axis] = pos1[axis] + amount\r
                pos2[axis] = pos2[axis] + amount\r
@@ -672,6 +681,7 @@ minetest.register_chatcommand("/stack", {
                        worldedit.player_notify(name, "invalid usage: " .. param)\r
                        return\r
                end\r
+               count = tonumber(count)\r
                if axis == "?" then\r
                        axis, sign = worldedit.player_axis(name)\r
                        count = count * sign\r
@@ -681,7 +691,7 @@ minetest.register_chatcommand("/stack", {
                if worldedit.ENABLE_QUEUE then\r
                        tenv = worldedit.queue_aliasenv\r
                end\r
-               local count = worldedit.stack(pos1, pos2, axis, tonumber(count), tenv)\r
+               local count = worldedit.stack(pos1, pos2, axis, count, tenv)\r
                worldedit.player_notify(name, count .. " nodes stacked")\r
        end,\r
 })\r
@@ -1125,8 +1135,8 @@ minetest.register_chatcommand("/luatransform", {
 \r
 if minetest.place_schematic then\r
 minetest.register_chatcommand("/mtschemcreate", {\r
-       params = "<filename>",\r
-       description = "Creates a Minetest schematic of the box defined by position 1 and position 2, and saves it to <filename>",\r
+       params = "<file>",\r
+       description = "Save the current WorldEdit region using the Minetest Schematic format to \"(world folder)/schems/<filename>.mts\"",\r
        privs = {worldedit=true},\r
        func = function(name, param)\r
                local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
@@ -1154,8 +1164,8 @@ minetest.register_chatcommand("/mtschemcreate", {
 })\r
 \r
 minetest.register_chatcommand("/mtschemplace", {\r
-       params = "<filename>",\r
-       description = "Places the Minetest schematic identified by <filename> at WorldEdit position 1",\r
+       params = "<file>",\r
+       description = "Load nodes from \"(world folder)/schems/<file>.mts\" with position 1 of the current WorldEdit region as the origin",\r
        privs = {worldedit=true},\r
        func = function(name, param)\r
                local pos = worldedit.pos1[name]\r
@@ -1219,3 +1229,19 @@ minetest.register_on_player_receive_fields(
        end\r
 )\r
 end\r
+\r
+minetest.register_chatcommand("/clearobjects", {\r
+       params = "",\r
+       description = "Clears all objects within the WorldEdit region",\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, "no region selected")\r
+                       return\r
+               end\r
+\r
+               local count = worldedit.clearobjects(pos1, pos2)\r
+               worldedit.player_notify(name, count .. " objects cleared")\r
+       end,\r
+})\r