]> git.lizzy.rs Git - worldedit.git/commitdiff
Support negative values to make upside-down domes and pyramids (slight changes to...
authorAnthony Zhang <azhang9@gmail.com>
Mon, 29 Jul 2013 16:43:24 +0000 (12:43 -0400)
committerAnthony Zhang <azhang9@gmail.com>
Mon, 29 Jul 2013 16:43:24 +0000 (12:43 -0400)
Chat Commands.md
WorldEdit API.md
worldedit/manipulations.lua
worldedit/primitives.lua
worldedit/visualization.lua
worldedit_commands/init.lua

index f661b8d3372c4dbd5a15c4669037e574d5c9cdcd..d27ebfcc9d9f03f4a312f4bdef2f4d2810988023 100644 (file)
@@ -118,7 +118,7 @@ Add sphere centered at WorldEdit position 1 with radius <radius>, composed of <n
 Add hollow dome centered at WorldEdit position 1 with radius <radius>, composed of <node>.\r
 \r
     //hollowdome 5 Diamond Block\r
-    //hollowdome 12 glass\r
+    //hollowdome -12 glass\r
     //hollowdome 17 mesecons:wire_00000000_off\r
 \r
 ### //dome <radius> <node>\r
@@ -126,7 +126,7 @@ Add hollow dome centered at WorldEdit position 1 with radius <radius>, composed
 Add dome centered at WorldEdit position 1 with radius <radius>, composed of <node>.\r
 \r
     //dome 5 Diamond Block\r
-    //dome 12 glass\r
+    //dome -12 glass\r
     //dome 17 mesecons:wire_00000000_off\r
 \r
 ### //hollowcylinder x/y/z/? <length> <radius> <node>\r
@@ -147,9 +147,9 @@ Add cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length>
     //cylinder z -12 3 mesecons:wire_00000000_off\r
     //cylinder ? 2 4 default:stone\r
     \r
-### //pyramid <height> <node>\r
+### //pyramid x/y/z? <height> <node>\r
 \r
-Add pyramid centered at WorldEdit position 1 with height <height>, composed of <node>.\r
+Add pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height <height>, composed of <node>.\r
 \r
     //pyramid 8 Diamond Block\r
     //pyramid 5 glass\r
@@ -323,3 +323,9 @@ After using //mtschemprob start all nodes punched will bring up a text field whe
 This mode can be left with //mtschemprob finish. //mtschemprob get will display the probabilities saved for the nodes.\r
 \r
     //mtschemprob get\r
+\r
+### //clearobjects\r
+\r
+Clears all objects within the WorldEdit region.\r
+\r
+    //clearobjects\r
index 1006932ab7a6c5f2132a843048ec9dd9abd41d3f..5d7e6d9e8361e2dea46ad16253d912ba54edbb66 100644 (file)
@@ -82,6 +82,12 @@ Fixes the lighting in a region defined by positions `pos1` and `pos2`.
 \r
 Returns the number of nodes updated.\r
 \r
+### count = worldedit.clearobjects(pos1, pos2)\r
+\r
+Clears all objects in a region defined by the positions `pos1` and `pos2`.\r
+\r
+Returns the number of objects cleared.\r
+\r
 Primitives\r
 ----------\r
 Contained in primitives.lua, this module allows the creation of several geometric primitives.\r
@@ -122,9 +128,9 @@ Adds a cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `
 \r
 Returns the number of nodes added.\r
 \r
-### count = worldedit.pyramid(pos, height, nodename)\r
+### count = worldedit.pyramid(pos, axis, height, nodename)\r
 \r
-Adds a pyramid centered at `pos` with height `height`.\r
+Adds a pyramid centered at `pos` along the `axis` axis ("x" or "y" or "z") with height `height`.\r
 \r
 Returns the number of nodes added.\r
 \r
index 2180cb6f0dc56501fd91e78a9f86c3cbfc488934..2b34e3cca08ae6381ddf9a46d854786146028ad2 100644 (file)
@@ -1,7 +1,6 @@
 worldedit = worldedit or {}\r
 local minetest = minetest --local copy of global\r
 \r
---wip: test the entire API again to make sure it works\r
 --wip: remove env parameter where no longer needed in chat commands module\r
 --wip: fix the queue\r
 \r
@@ -492,3 +491,28 @@ worldedit.fixlight = function(pos1, pos2, env)
        end\r
        return #nodes\r
 end\r
+\r
+--clears all objects in a region defined by the positions `pos1` and `pos2`, returning the number of objects cleared\r
+worldedit.clearobjects = function(pos1, pos2)\r
+       local pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
+\r
+       --set up voxel manipulator\r
+       local manip = minetest.get_voxel_manip()\r
+       manip:read_from_map(pos1, pos2)\r
+\r
+       local pos1x, pos1y, pos1z = pos1.x, pos1.y, pos1.z\r
+       local pos2x, pos2y, pos2z = pos2.x, pos2.y, pos2.z\r
+       local center = {x=(pos1x + pos2x + 1) / 2, y=(pos1y + pos2y + 1) / 2, z=(pos1z + pos2z + 1) / 2}\r
+       local radius = ((center.x - pos1x + 0.5) + (center.y - pos1y + 0.5) + (center.z - pos1z + 0.5)) ^ 0.5\r
+       local count = 0\r
+       for _, obj in pairs(minetest.get_objects_inside_radius(center, radius)) do\r
+               local pos = obj:getpos()\r
+               if pos.x >= pos1x and pos.x <= pos2x\r
+               and pos.y >= pos1y and pos.y <= pos2y\r
+               and pos.z >= pos1z and pos.z <= pos2z then\r
+                       obj:remove()\r
+                       count = count + 1\r
+               end\r
+       end\r
+       return count\r
+end\r
index cdb6e0f328f0a1fca7613c86c6fe62dbae5ef9f2..d11596a812056f31d67301c2d498eccb0576a0c7 100644 (file)
@@ -106,6 +106,12 @@ worldedit.hollow_dome = function(pos, radius, nodename)
                nodes[i] = ignore\r
        end\r
 \r
+       local miny, maxy = 0, radius\r
+       if radius < 0 then\r
+               radius = -radius\r
+               miny, maxy = -radius, 0\r
+       end\r
+\r
        --fill selected area with node\r
        local node_id = minetest.get_content_id(nodename)\r
        local min_radius, max_radius = radius * (radius - 1), radius * (radius + 1)\r
@@ -114,7 +120,7 @@ worldedit.hollow_dome = function(pos, radius, nodename)
        local count = 0\r
        for z = -radius, radius do\r
                local newz = (z + offsetz) * zstride + 1 --offset contributed by z plus 1 to make it 1-indexed\r
-               for y = 0, radius do\r
+               for y = miny, maxy do\r
                        local newy = newz + (y + offsety) * ystride\r
                        for x = -radius, radius do\r
                                local squared = x * x + y * y + z * z\r
@@ -151,6 +157,12 @@ worldedit.dome = function(pos, radius, nodename)
                nodes[i] = ignore\r
        end\r
 \r
+       local miny, maxy = 0, radius\r
+       if radius < 0 then\r
+               radius = -radius\r
+               miny, maxy = -radius, 0\r
+       end\r
+\r
        --fill selected area with node\r
        local node_id = minetest.get_content_id(nodename)\r
        local max_radius = radius * (radius + 1)\r
@@ -159,7 +171,7 @@ worldedit.dome = function(pos, radius, nodename)
        local count = 0\r
        for z = -radius, radius do\r
                local newz = (z + offsetz) * zstride + 1 --offset contributed by z plus 1 to make it 1-indexed\r
-               for y = 0, radius do\r
+               for y = miny, maxy do\r
                        local newy = newz + (y + offsety) * ystride\r
                        for x = -radius, radius do\r
                                if x * x + y * y + z * z <= max_radius then --position is inside sphere\r
@@ -248,7 +260,7 @@ worldedit.hollow_cylinder = function(pos, axis, length, radius, nodename) --wip:
 end\r
 \r
 --adds a cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `length` and radius `radius`, composed of `nodename`, returning the number of nodes added\r
-worldedit.cylinder = function(pos, axis, length, radius, nodename, env)\r
+worldedit.cylinder = function(pos, axis, length, radius, nodename)\r
        local other1, other2\r
        if axis == "x" then\r
                other1, other2 = "y", "z"\r
@@ -317,7 +329,7 @@ worldedit.cylinder = function(pos, axis, length, radius, nodename, env)
 end\r
 \r
 --adds a pyramid centered at `pos` with height `height`, composed of `nodename`, returning the number of nodes added\r
-worldedit.pyramid = function(pos, height, nodename, env)\r
+worldedit.pyramid = function(pos, axis, height, nodename)\r
        local pos1 = {x=pos.x - height, y=pos.y, z=pos.z - height}\r
        local pos2 = {x=pos.x + height, y=pos.y + height, z=pos.z + height}\r
 \r
@@ -333,22 +345,30 @@ worldedit.pyramid = function(pos, height, nodename, env)
                nodes[i] = ignore\r
        end\r
 \r
+       --handle inverted pyramids\r
+       height = height - 1\r
+       local size = height\r
+       local step = -1\r
+       if height < 0 then\r
+               size = 0\r
+               step = 1\r
+       end\r
+--wip: support arbitrary axes\r
        --fill selected area with node\r
        local node_id = minetest.get_content_id(nodename)\r
-       height = height - 1\r
        local offsetx, offsety, offsetz = pos.x - emerged_pos1.x, pos.y - emerged_pos1.y, pos.z - emerged_pos1.z\r
        local zstride, ystride = area.zstride, area.ystride\r
        local count = 0\r
        for y = 0, height do --go through each level of the pyramid\r
                local newy = (y + offsety) * ystride + 1 --offset contributed by y plus 1 to make it 1-indexed\r
-               for z = -height, height do\r
+               for z = -size, size do\r
                        local newz = newy + (z + offsetz) * zstride\r
-                       for x = -height, height do\r
+                       for x = -size, size do\r
                                local i = newz + (x + offsetx)\r
                                nodes[i] = node_id\r
                        end\r
                end\r
-               height = height - 1\r
+               size = size + step\r
                count = count + ((height - y) * 2 + 1) ^ 2\r
        end\r
 \r
index 7b600d5cb770a5e28025fc132032a1525d16756d..dbee5d087029c680bbaa7b2b9bb8ffbeb70f3f8d 100644 (file)
@@ -88,7 +88,7 @@ worldedit.suppress = function(pos1, pos2, nodename)
 end\r
 \r
 --highlights all instances of `nodename` in a region defined by positions `pos1` and `pos2` by non-destructively hiding all other nodes, returning the number of nodes found\r
-worldedit.highlight = function(pos1, pos2, nodename) --wip: speed this up with voxmanip get_data to speed up searching\r
+worldedit.highlight = function(pos1, pos2, nodename)\r
        --make area stay loaded\r
        local manip = minetest.get_voxel_manip()\r
        manip:read_from_map(pos1, pos2)\r
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