summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md34
-rw-r--r--functions.lua49
-rw-r--r--init.lua52
3 files changed, 129 insertions, 6 deletions
diff --git a/README.md b/README.md
index ff79659..e513605 100644
--- a/README.md
+++ b/README.md
@@ -91,6 +91,22 @@ Replace all instances of <search node> with <place node> in the current WorldEdi
//replace dirt flowers:flower_waterlily
//replace flowers:flower_rose flowers:flower_tulip
+### //hollowsphere <radius> <node>
+
+Add hollow sphere at WorldEdit position 1 with radius <radius>, composed of <node>.
+
+ //hollowsphere 5 dirt
+ //hollowsphere 12 default:glass
+ //hollowsphere 17 mesecons:mesecon
+
+### //sphere <radius> <node>
+
+Add sphere at WorldEdit position 1 with radius <radius>, composed of <node>.
+
+ //sphere 5 dirt
+ //sphere 12 default:glass
+ //sphere 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>.
@@ -228,15 +244,27 @@ Replaces all instances of `searchnode` with `replacenode` in a region defined by
Returns the number of nodes replaced.
+### worldedit.hollow_sphere = function(pos, radius, nodename)
+
+Adds a hollow sphere at `pos` with radius `radius`, composed of `nodename`.
+
+Returns the number of nodes added.
+
+### worldedit.sphere = function(pos, radius, nodename)
+
+Adds a sphere at `pos` with radius `radius`, composed of `nodename`.
+
+Returns the number of nodes added.
+
### 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`.
+Adds a hollow cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `length` and radius `radius`, composed of `nodename`.
Returns the number of nodes added.
### worldedit.cylinder(pos, axis, length, radius, nodename)
-Adds a cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `length` and radius `radius`.
+Adds a cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `length` and radius `radius`, composed of `nodename`.
Returns the number of nodes added.
@@ -322,7 +350,7 @@ Returns the number of nodes loaded
License
-------
-Copyright 2012 sfan5, Anthony Zhang (Temperest), and Brett O'Donnell (cornernote).
+Copyright 2012 sfan5 and Anthony Zhang (Temperest)
This mod is licensed under the [GNU Affero General Public License](http://www.gnu.org/licenses/agpl-3.0.html).
diff --git a/functions.lua b/functions.lua
index eaac5d6..4b98a84 100644
--- a/functions.lua
+++ b/functions.lua
@@ -75,7 +75,50 @@ worldedit.replace = function(pos1, pos2, searchnode, replacenode)
return count
end
---adds a hollow cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `length` and radius `radius`, returning the number of nodes added
+--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)
+ local node = {name=nodename}
+ local pos1 = {x=0, y=0, z=0}
+ local full_radius = radius * radius + radius
+ local env = minetest.env
+ for x = -radius, radius do
+ pos1.x = pos.x + x
+ 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
+ pos1.z = pos.z + z
+ env:add_node({x=pos.x+x,y=pos.y+y,z=pos.z+z}, node)
+ end
+ end
+ end
+ end
+end
+
+--adds a sphere at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added
+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 count = 0
+ local env = minetest.env
+ for x = -radius, radius do
+ pos1.x = pos.x + x
+ 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
+ pos1.z = pos.z + z
+ env:add_node(pos1, node)
+ count = count + 1
+ end
+ end
+ end
+ end
+ return count
+end
+
+--adds a hollow cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `length` and radius `radius`, composed of `nodename`, returning the number of nodes added
worldedit.hollow_cylinder = function(pos, axis, length, radius, nodename)
local other1, other2
if axis == "x" then
@@ -136,7 +179,7 @@ worldedit.hollow_cylinder = function(pos, axis, length, radius, nodename)
return count
end
---adds a cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `length` and radius `radius`, returning the number of nodes added
+--adds a cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `length` and radius `radius`, composed of `nodename`, returning the number of nodes added
worldedit.cylinder = function(pos, axis, length, radius, nodename)
local other1, other2
if axis == "x" then
@@ -195,7 +238,7 @@ 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
+--adds a spiral at `pos` with size `size`, composed of `nodename`, returning the number of nodes changed
worldedit.spiral = function(pos, size, nodename)
local shift_x, shift_y
sa = spiralt(size)
diff --git a/init.lua b/init.lua
index 1e9b0ef..a7e1947 100644
--- a/init.lua
+++ b/init.lua
@@ -189,6 +189,58 @@ minetest.register_chatcommand("/replace", {
end,
})
+minetest.register_chatcommand("/hollowsphere", {
+ params = "<radius> <node>",
+ description = "Add hollow sphere 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")
+ return
+ end
+
+ local found, _, radius, nodename = param:find("^(%d+)%s+([^%s]+)$")
+ if found == nil then
+ minetest.chat_send_player(name, "Invalid usage: " .. param)
+ return
+ end
+ if not worldedit.node_is_valid(pos, nodename) then
+ minetest.chat_send_player(name, "Invalid node name: " .. param)
+ return
+ end
+
+ local count = worldedit.hollow_sphere(pos, tonumber(radius), nodename)
+ minetest.chat_send_player(name, count .. " nodes added")
+ end,
+})
+
+minetest.register_chatcommand("/sphere", {
+ params = "<radius> <node>",
+ description = "Add sphere 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")
+ return
+ end
+
+ local found, _, radius, nodename = param:find("^(%d+)%s+([^%s]+)$")
+ if found == nil then
+ minetest.chat_send_player(name, "Invalid usage: " .. param)
+ return
+ end
+ if not worldedit.node_is_valid(pos, nodename) then
+ minetest.chat_send_player(name, "Invalid node name: " .. param)
+ return
+ end
+
+ local count = worldedit.sphere(pos, tonumber(radius), nodename)
+ minetest.chat_send_player(name, count .. " nodes added")
+ 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>",