diff options
author | Anthony Zhang <azhang9@gmail.com> | 2013-04-27 18:28:20 -0400 |
---|---|---|
committer | Anthony Zhang <azhang9@gmail.com> | 2013-04-27 18:28:20 -0400 |
commit | 71b6004b928766abc3638aaca3526b80af642140 (patch) | |
tree | df61f94df1138ae60c836f30a3a98a52b8ee3cf5 | |
parent | 20722389bdc12359399ae2d1eab9b11f556fdb56 (diff) |
New commands //hollowdome and //dome, as well as new API functions worldedit.dome and worldedit.hollow_dome. Oh, and spheres generate faster too.
-rw-r--r-- | Chat Commands.md | 16 | ||||
-rw-r--r-- | WorldEdit API.md | 12 | ||||
-rw-r--r-- | worldedit/primitives.lua | 62 | ||||
-rw-r--r-- | worldedit_commands/init.lua | 52 |
4 files changed, 135 insertions, 7 deletions
diff --git a/Chat Commands.md b/Chat Commands.md index 7f6eeb0..1e26586 100644 --- a/Chat Commands.md +++ b/Chat Commands.md @@ -83,6 +83,22 @@ Add sphere at WorldEdit position 1 with radius <radius>, composed of <node>. //sphere 12 default:glass
//sphere 17 mesecons:mesecon
+### //hollowdome <radius> <node>
+
+Add hollow dome at WorldEdit position 1 with radius <radius>, composed of <node>.
+
+ //hollowdome 5 dirt
+ //hollowdome 12 default:glass
+ //hollowdome 17 mesecons:mesecon
+
+### //dome <radius> <node>
+
+Add dome at WorldEdit position 1 with radius <radius>, composed of <node>.
+
+ //dome 5 dirt
+ //dome 12 default:glass
+ //dome 17 mesecons:mesecon
+
### //hollowcylinder x/y/z/? <length> <radius> <node>
Add hollow cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length> and radius <radius>, composed of <node>.
diff --git a/WorldEdit API.md b/WorldEdit API.md index a69062f..6008a9f 100644 --- a/WorldEdit API.md +++ b/WorldEdit API.md @@ -92,6 +92,18 @@ Adds a sphere at `pos` with radius `radius`, composed of `nodename`. Returns the number of nodes added.
+### count = worldedit.hollow_dome(pos, radius, nodename)
+
+Adds a hollow dome at `pos` with radius `radius`, composed of `nodename`.
+
+Returns the number of nodes added.
+
+### count = worldedit.dome(pos, radius, nodename)
+
+Adds a dome at `pos` with radius `radius`, composed of `nodename`.
+
+Returns the number of nodes added.
+
### count = worldedit.hollow_cylinder(pos, axis, length, radius, nodename)
Adds a hollow cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `length` and radius `radius`, composed of `nodename`.
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
diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua index da24747..fb01ce7 100644 --- a/worldedit_commands/init.lua +++ b/worldedit_commands/init.lua @@ -279,6 +279,58 @@ minetest.register_chatcommand("/sphere", { end,
})
+minetest.register_chatcommand("/hollowdome", {
+ params = "<radius> <node>",
+ description = "Add hollow dome at WorldEdit position 1 with radius <radius>, composed of <node>",
+ privs = {worldedit=true},
+ func = function(name, param)
+ local pos = worldedit.pos1[name]
+ if pos == nil then
+ minetest.chat_send_player(name, "No WorldEdit region selected", false)
+ return
+ end
+
+ local found, _, radius, nodename = param:find("^(%d+)%s+([^%s]+)$")
+ if found == nil then
+ minetest.chat_send_player(name, "Invalid usage: " .. param, false)
+ return
+ end
+ if not worldedit.node_is_valid(nodename) then
+ minetest.chat_send_player(name, "Invalid node name: " .. param, false)
+ return
+ end
+
+ local count = worldedit.hollow_dome(pos, tonumber(radius), nodename)
+ minetest.chat_send_player(name, count .. " nodes added", false)
+ end,
+})
+
+minetest.register_chatcommand("/dome", {
+ params = "<radius> <node>",
+ description = "Add dome at WorldEdit position 1 with radius <radius>, composed of <node>",
+ privs = {worldedit=true},
+ func = function(name, param)
+ local pos = worldedit.pos1[name]
+ if pos == nil then
+ minetest.chat_send_player(name, "No WorldEdit region selected", false)
+ return
+ end
+
+ local found, _, radius, nodename = param:find("^(%d+)%s+([^%s]+)$")
+ if found == nil then
+ minetest.chat_send_player(name, "Invalid usage: " .. param, false)
+ return
+ end
+ if not worldedit.node_is_valid(nodename) then
+ minetest.chat_send_player(name, "Invalid node name: " .. param, false)
+ return
+ end
+
+ local count = worldedit.dome(pos, tonumber(radius), nodename)
+ minetest.chat_send_player(name, count .. " nodes added", false)
+ end,
+})
+
minetest.register_chatcommand("/hollowcylinder", {
params = "x/y/z/? <length> <radius> <node>",
description = "Add hollow cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length> and radius <radius>, composed of <node>",
|