From e39493e789d77f98af4cdc17de21ca1ef0547571 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 19 Aug 2012 09:36:11 +0200 Subject: Add //spiral and worldedit.spiral API function --- functions.lua | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'functions.lua') diff --git a/functions.lua b/functions.lua index 270b50e..ee549de 100644 --- a/functions.lua +++ b/functions.lua @@ -1,3 +1,4 @@ +dofile(minetest.get_modpath("worldedit") .. "/spirals.lua") --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 worldedit.sort_pos = function(pos1, pos2) pos1 = {x=pos1.x, y=pos1.y, z=pos1.z} @@ -182,6 +183,26 @@ worldedit.cylinder = function(pos, axis, length, radius, nodename) return count end +--adds a spiral at `pos` with size `size`, returning the number of nodes changed +worldedit.spiral = function(pos, size, nodename) + local shift_x,shift_y + sa = spiralt(size) + shift_y = #sa -- "Height" of the Array + local fe = sa[1] + shift_x = #fe -- "Width" of the Array + fe = nil + + local count = 0 + for x,v in ipairs(sa) do + for y, z in ipairs(v) do + minetest.env:add_node({x=pos.x-shift_x+x,y=pos.y-shift_y+y,z=pos.z+z}, {name=nodename}) + count = count + 1 + end + end + + return count +end + --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 worldedit.copy = function(pos1, pos2, axis, amount) local pos1, pos2 = worldedit.sort_pos(pos1, pos2) @@ -476,4 +497,4 @@ worldedit.deserialize_old = function(originpos, value) count = count + 1 end return count -end \ No newline at end of file +end -- cgit v1.2.3