//cylinder z -12 3 mesecons:mesecon
//cylinder ? 2 4 stone
-### //spiral <size> <node>
+### //pyramid <height> <node>
-Add spiral at WorldEdit position 1 with size <size>, composed of <node>.
+Add pyramid at WorldEdit position 1 with height <height>, composed of <node>.
- //spiral 8 dirt
- //spiral 5 default:glass
- //spiral 2 stone
+ //pyramid 8 dirt
+ //pyramid 5 default:glass
+ //pyramid 2 stone
### //copy x/y/z/? <amount>
Returns the number of nodes added.
-### worldedit.spiral(pos, size, nodename)
+### worldedit.pyramid(pos, height, nodename)
-Adds a spiral at `pos` with size `size`.
+Adds a pyramid at `pos` with height `height`.
-Returns the number of nodes changed.
+Returns the number of nodes added.
### worldedit.copy(pos1, pos2, axis, amount)
end\r
\r
--adds a hollow sphere at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added\r
-worldedit.hollow_sphere = function(pos, radius, nodename)\r
+worldedit.hollow_sphere = function(pos, radius, nodename) --wip: use bresenham sphere for maximum speed\r
local node = {name=nodename}\r
local pos1 = {x=0, y=0, z=0}\r
local full_radius = radius * radius + radius\r
end\r
\r
--adds a sphere at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added\r
-worldedit.sphere = function(pos, radius, nodename)\r
+worldedit.sphere = function(pos, radius, nodename) --wip: use bresenham sphere for maximum speed\r
local node = {name=nodename}\r
local pos1 = {x=0, y=0, z=0}\r
local full_radius = radius * radius + radius\r
local node = {name=nodename}\r
local count = 0\r
local step = 1\r
- if length < 0\r
+ if length < 0 then\r
length = -length\r
step = -1\r
end\r
local node = {name=nodename}\r
local count = 0\r
local step = 1\r
- if length < 0\r
+ if length < 0 then\r
length = -length\r
step = -1\r
end\r
return count\r
end\r
\r
---adds a spiral at `pos` with size `size`, composed of `nodename`, 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
+--adds a pyramid at `pos` with height `height`, composed of `nodename`, returning the number of nodes added\r
+worldedit.pyramid = function(pos, height, nodename)\r
+ local pos1x, pos1y, pos1z = pos.x - height, pos.y, pos.z - height\r
+ local pos2x, pos2y, pos2z = pos.x + height, pos.y + height, pos.z + height\r
+ local pos = {x=0, y=pos1y, z=0}\r
\r
local count = 0\r
local node = {name=nodename}\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}, node)\r
- count = count + 1\r
+ local env = minetest.env\r
+ while pos.y <= pos2y do --each vertical level of the pyramid\r
+ pos.x = pos1x\r
+ while pos.x <= pos2x do\r
+ pos.z = pos1z\r
+ while pos.z <= pos2z do\r
+ env:add_node(pos, node)\r
+ pos.z = pos.z + 1\r
+ end\r
+ pos.x = pos.x + 1\r
end\r
- end\r
- return count\r
-end\r
+ count = count + ((pos2y - pos.y) * 2 + 1) ^ 2\r
+ pos.y = pos.y + 1\r
\r
---wip: \r
-sign = function(s)\r
- if s > 0 then\r
- return 1\r
- end\r
- if s < 0 then\r
- return -1\r
- end\r
- return 0\r
-end\r
+ pos1x, pos2x = pos1x + 1, pos2x - 1\r
+ pos1z, pos2z = pos1z + 1, pos2z - 1\r
\r
---wip: needs to be faster\r
-function spiral_index(y, x) -- returns the value at (x, y) in a spiral that starts at 1 and goes outwards\r
- if y == -x and y >= x then\r
- return (2 * y + 1) ^ 2\r
- end\r
- local l = math.max(math.abs(y), math.abs(x))\r
- local value\r
- if math.abs(y) == l then\r
- value = x\r
- if y < 0 then\r
- value = -value\r
- end\r
- else\r
- value = y\r
- if x < 0 then\r
- value = -value\r
- end\r
- end\r
- t1 = l * 2\r
- if x + y < 0 then\r
- t1 = -t1\r
- end\r
- t2 = y ^ 2 - x ^ 2\r
- if t2 < 0 then\r
- t2 = -t2\r
end\r
- return ((2 * l - 1) ^ 2) + (l * 4) + t1 + (t2 * (l - value))\r
-end\r
-\r
---wip: needs to be faster\r
-function spiralt(side)\r
- local spiral = {}\r
- local start, stop = math.floor((-side+1)/2), math.floor((side-1)/2)\r
- for i = 1, side do\r
- spiral[i] = {}\r
- for j = 1, side do\r
- spiral[i][j] = side ^ 2 - spiral_index(stop - i + 1,start + j - 1) --moves the coordinates so (0,0) is at the center of the spiral\r
- end\r
- end\r
- return spiral\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
end\r
\r
--saves the nodes and meta defined by positions `pos1` and `pos2` into a file, returning the number of nodes saved\r
-worldedit.metasave = function(pos1, pos2, file)\r
+worldedit.metasave = function(pos1, pos2, file) --wip: simply work with strings instead of doing IO\r
local path = minetest.get_worldpath() .. "/schems"\r
local filename = path .. "/" .. file .. ".wem"\r
os.execute("mkdir \"" .. path .. "\"") --create directory if it does not already exist\r
end\r
\r
--loads the nodes and meta from `file` to position `pos1`, returning the number of nodes loaded\r
-worldedit.metaload = function(pos1, file)\r
+worldedit.metaload = function(pos1, file) --wip: simply work with strings instead of doing IO\r
local filename = minetest.get_worldpath() .. "/schems/" .. file .. ".wem"\r
local rows, err = table.load(filename)\r
if err then return _,err end\r
end,\r
})\r
\r
-minetest.register_chatcommand("/spiral", {\r
- params = "<size> <node>",\r
- description = "Add spiral at WorldEdit position 1 with size <size>, composed of <node>",\r
+minetest.register_chatcommand("/pyramid", {\r
+ params = "<height> <node>",\r
+ description = "Add pyramid at WorldEdit position 1 with height <height>, composed of <node>",\r
privs = {worldedit=true},\r
func = function(name, param)\r
local pos = worldedit.pos1[name]\r
return\r
end\r
\r
- local count = worldedit.spiral(pos, tonumber(size), nodename)\r
- minetest.chat_send_player(name, count .. " nodes changed")\r
+ local count = worldedit.pyramid(pos, tonumber(size), nodename)\r
+ minetest.chat_send_player(name, count .. " nodes added")\r
end,\r
})\r
\r