summaryrefslogtreecommitdiff
path: root/worldedit
diff options
context:
space:
mode:
authorAnthony Zhang <azhang9@gmail.com>2013-04-27 18:28:20 -0400
committerAnthony Zhang <azhang9@gmail.com>2013-04-27 18:28:20 -0400
commit71b6004b928766abc3638aaca3526b80af642140 (patch)
treedf61f94df1138ae60c836f30a3a98a52b8ee3cf5 /worldedit
parent20722389bdc12359399ae2d1eab9b11f556fdb56 (diff)
New commands //hollowdome and //dome, as well as new API functions worldedit.dome and worldedit.hollow_dome. Oh, and spheres generate faster too.
Diffstat (limited to 'worldedit')
-rw-r--r--worldedit/primitives.lua62
1 files changed, 55 insertions, 7 deletions
diff --git a/worldedit/primitives.lua b/worldedit/primitives.lua
index 37e2298..8dfe88e 100644
--- a/worldedit/primitives.lua
+++ b/worldedit/primitives.lua
@@ -1,10 +1,11 @@
worldedit = worldedit or {}
--adds a hollow sphere at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added
-worldedit.hollow_sphere = function(pos, radius, nodename) --wip: use bresenham sphere for maximum speed
+worldedit.hollow_sphere = function(pos, radius, nodename)
local node = {name=nodename}
local pos1 = {x=0, y=0, z=0}
- local full_radius = radius * radius + radius
+ local min_radius = radius * (radius - 1)
+ local max_radius = radius * (radius + 1)
local count = 0
local env = minetest.env
for x = -radius, radius do
@@ -12,9 +13,9 @@ worldedit.hollow_sphere = function(pos, radius, nodename) --wip: use bresenham s
for y = -radius, radius do
pos1.y = pos.y + y
for z = -radius, radius do
- if x*x+y*y+z*z >= (radius-1) * (radius-1) + (radius-1) and x*x+y*y+z*z <= full_radius then
+ if x*x+y*y+z*z >= min_radius and x*x+y*y+z*z <= max_radius then
pos1.z = pos.z + z
- env:add_node({x=pos.x+x,y=pos.y+y,z=pos.z+z}, node)
+ env:add_node(pos1, node)
count = count + 1
end
end
@@ -24,10 +25,10 @@ worldedit.hollow_sphere = function(pos, radius, nodename) --wip: use bresenham s
end
--adds a sphere at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added
-worldedit.sphere = function(pos, radius, nodename) --wip: use bresenham sphere for maximum speed
+worldedit.sphere = function(pos, radius, nodename)
local node = {name=nodename}
local pos1 = {x=0, y=0, z=0}
- local full_radius = radius * radius + radius
+ local max_radius = radius * (radius + 1)
local count = 0
local env = minetest.env
for x = -radius, radius do
@@ -35,7 +36,54 @@ worldedit.sphere = function(pos, radius, nodename) --wip: use bresenham sphere f
for y = -radius, radius do
pos1.y = pos.y + y
for z = -radius, radius do
- if x*x+y*y+z*z <= full_radius then
+ if x*x+y*y+z*z <= max_radius then
+ pos1.z = pos.z + z
+ env:add_node(pos1, node)
+ count = count + 1
+ end
+ end
+ end
+ end
+ return count
+end
+
+--adds a hollow dome at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added
+worldedit.hollow_dome = function(pos, radius, nodename) --wip: use bresenham sphere for maximum speed
+ local node = {name=nodename}
+ local pos1 = {x=0, y=0, z=0}
+ local min_radius = radius * (radius - 1)
+ local max_radius = radius * (radius + 1)
+ local count = 0
+ local env = minetest.env
+ for x = -radius, radius do
+ pos1.x = pos.x + x
+ for y = 0, radius do
+ pos1.y = pos.y + y
+ for z = -radius, radius do
+ if x*x+y*y+z*z >= min_radius and x*x+y*y+z*z <= max_radius then
+ pos1.z = pos.z + z
+ env:add_node(pos1, node)
+ count = count + 1
+ end
+ end
+ end
+ end
+ return count
+end
+
+--adds a dome at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added
+worldedit.dome = function(pos, radius, nodename) --wip: use bresenham sphere for maximum speed
+ local node = {name=nodename}
+ local pos1 = {x=0, y=0, z=0}
+ local max_radius = radius * (radius + 1)
+ local count = 0
+ local env = minetest.env
+ for x = -radius, radius do
+ pos1.x = pos.x + x
+ for y = 0, radius do
+ pos1.y = pos.y + y
+ for z = -radius, radius do
+ if x*x+y*y+z*z <= max_radius then
pos1.z = pos.z + z
env:add_node(pos1, node)
count = count + 1