]> git.lizzy.rs Git - worldedit.git/commitdiff
Add worldedit.hollow_sphere, worldedit.sphere, //hollowsphere, and //sphere, improve...
authorAnthony Zhang <azhang9@gmail.com>
Tue, 25 Sep 2012 22:42:10 +0000 (18:42 -0400)
committerAnthony Zhang <azhang9@gmail.com>
Tue, 25 Sep 2012 22:42:10 +0000 (18:42 -0400)
README.md
functions.lua
init.lua

index ff79659890a41ca7f5eb9f59c787bc0224ed0ed1..e513605b655d2f1eb2749fa51f6b9b1405b68b2c 100644 (file)
--- 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).
 
index eaac5d6172e6ebfe0f85eb92a8641424c7ff673b..4b98a84663d03d9432cb721d8b7e748aa719a653 100644 (file)
@@ -75,7 +75,50 @@ worldedit.replace = function(pos1, pos2, searchnode, replacenode)
        return count\r
 end\r
 \r
---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\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
+       local node = {name=nodename}\r
+       local pos1 = {x=0, y=0, z=0}\r
+       local full_radius = radius * radius + radius\r
+       local env = minetest.env\r
+       for x = -radius, radius do\r
+               pos1.x = pos.x + x\r
+               for y = -radius, radius do\r
+                       pos1.y = pos.y + y\r
+                       for z = -radius, radius do\r
+                               if x*x+y*y+z*z >= (radius-1) * (radius-1) + (radius-1) and x*x+y*y+z*z <= full_radius then\r
+                                       pos1.z = pos.z + z\r
+                                       env:add_node({x=pos.x+x,y=pos.y+y,z=pos.z+z}, node)\r
+                               end\r
+                       end\r
+               end\r
+       end\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
+       local node = {name=nodename}\r
+       local pos1 = {x=0, y=0, z=0}\r
+       local full_radius = radius * radius + radius\r
+       local count = 0\r
+       local env = minetest.env\r
+       for x = -radius, radius do\r
+               pos1.x = pos.x + x\r
+               for y = -radius, radius do\r
+                       pos1.y = pos.y + y\r
+                       for z = -radius, radius do\r
+                               if x*x+y*y+z*z <= full_radius then\r
+                                       pos1.z = pos.z + z\r
+                                       env:add_node(pos1, node)\r
+                                       count = count + 1\r
+                               end\r
+                       end\r
+               end\r
+       end\r
+       return count\r
+end\r
+\r
+--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\r
 worldedit.hollow_cylinder = function(pos, axis, length, radius, nodename)\r
        local other1, other2\r
        if axis == "x" then\r
@@ -136,7 +179,7 @@ worldedit.hollow_cylinder = function(pos, axis, length, radius, nodename)
        return count\r
 end\r
 \r
---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\r
+--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\r
 worldedit.cylinder = function(pos, axis, length, radius, nodename)\r
        local other1, other2\r
        if axis == "x" then\r
@@ -195,7 +238,7 @@ worldedit.cylinder = function(pos, axis, length, radius, nodename)
        return count\r
 end\r
 \r
---adds a spiral at `pos` with size `size`, returning the number of nodes changed\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
index 1e9b0efce442d19a5e2609045dd2e24bfaf51f4b..a7e1947abf2e8b6941db95ba71c58ee1e593854b 100644 (file)
--- a/init.lua
+++ b/init.lua
@@ -189,6 +189,58 @@ minetest.register_chatcommand("/replace", {
        end,\r
 })\r
 \r
+minetest.register_chatcommand("/hollowsphere", {\r
+       params = "<radius> <node>",\r
+       description = "Add hollow sphere at WorldEdit position 1 with radius <radius>, composed of <node>",\r
+       privs = {worldedit=true},\r
+       func = function(name, param)\r
+               local pos = worldedit.pos1[name]\r
+               if pos == nil then\r
+                       minetest.chat_send_player(name, "No WorldEdit region selected")\r
+                       return\r
+               end\r
+\r
+               local found, _, radius, nodename = param:find("^(%d+)%s+([^%s]+)$")\r
+               if found == nil then\r
+                       minetest.chat_send_player(name, "Invalid usage: " .. param)\r
+                       return\r
+               end\r
+               if not worldedit.node_is_valid(pos, nodename) then\r
+                       minetest.chat_send_player(name, "Invalid node name: " .. param)\r
+                       return\r
+               end\r
+\r
+               local count = worldedit.hollow_sphere(pos, tonumber(radius), nodename)\r
+               minetest.chat_send_player(name, count .. " nodes added")\r
+       end,\r
+})\r
+\r
+minetest.register_chatcommand("/sphere", {\r
+       params = "<radius> <node>",\r
+       description = "Add sphere at WorldEdit position 1 with radius <radius>, composed of <node>",\r
+       privs = {worldedit=true},\r
+       func = function(name, param)\r
+               local pos = worldedit.pos1[name]\r
+               if pos == nil then\r
+                       minetest.chat_send_player(name, "No WorldEdit region selected")\r
+                       return\r
+               end\r
+\r
+               local found, _, radius, nodename = param:find("^(%d+)%s+([^%s]+)$")\r
+               if found == nil then\r
+                       minetest.chat_send_player(name, "Invalid usage: " .. param)\r
+                       return\r
+               end\r
+               if not worldedit.node_is_valid(pos, nodename) then\r
+                       minetest.chat_send_player(name, "Invalid node name: " .. param)\r
+                       return\r
+               end\r
+\r
+               local count = worldedit.sphere(pos, tonumber(radius), nodename)\r
+               minetest.chat_send_player(name, count .. " nodes added")\r
+       end,\r
+})\r
+\r
 minetest.register_chatcommand("/hollowcylinder", {\r
        params = "x/y/z/? <length> <radius> <node>",\r
        description = "Add hollow cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length> and radius <radius>, composed of <node>",\r