]> git.lizzy.rs Git - worldedit.git/blobdiff - functions.lua
Add //spiral and worldedit.spiral API function
[worldedit.git] / functions.lua
index 270b50e130a4bedadd0babafbc05b122c27a0e5f..ee549deb4c1126002b78e7f135925b0ea59c3133 100644 (file)
@@ -1,3 +1,4 @@
+dofile(minetest.get_modpath("worldedit") .. "/spirals.lua")\r
 --modifies positions `pos1` and `pos2` so that each component of `pos1` is less than or equal to its corresponding conent of `pos2`, returning two new positions\r
 worldedit.sort_pos = function(pos1, pos2)\r
        pos1 = {x=pos1.x, y=pos1.y, z=pos1.z}\r
@@ -182,6 +183,26 @@ worldedit.cylinder = function(pos, axis, length, radius, nodename)
        return count\r
 end\r
 \r
+--adds a spiral at `pos` with size `size`, returning the number of nodes changed\r
+worldedit.spiral = function(pos, size, nodename)\r
+    local shift_x,shift_y\r
+       sa = spiralt(size)\r
+    shift_y = #sa -- "Height" of the Array\r
+    local fe = sa[1]\r
+    shift_x = #fe -- "Width" of the Array\r
+    fe = nil\r
+    \r
+    local count = 0\r
+    for x,v in ipairs(sa) do\r
+        for y, z in ipairs(v) do\r
+            minetest.env:add_node({x=pos.x-shift_x+x,y=pos.y-shift_y+y,z=pos.z+z}, {name=nodename})\r
+            count = count + 1\r
+        end\r
+    end\r
+       \r
+       return count\r
+end\r
+\r
 --copies the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes, returning the number of nodes copied\r
 worldedit.copy = function(pos1, pos2, axis, amount)\r
        local pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
@@ -476,4 +497,4 @@ worldedit.deserialize_old = function(originpos, value)
                count = count + 1\r
        end\r
        return count\r
-end
\ No newline at end of file
+end\r