]> git.lizzy.rs Git - worldedit.git/commitdiff
New commands //hollowdome and //dome, as well as new API functions worldedit.dome...
authorAnthony Zhang <azhang9@gmail.com>
Sat, 27 Apr 2013 22:28:20 +0000 (18:28 -0400)
committerAnthony Zhang <azhang9@gmail.com>
Sat, 27 Apr 2013 22:28:20 +0000 (18:28 -0400)
Chat Commands.md
WorldEdit API.md
worldedit/primitives.lua
worldedit_commands/init.lua

index 7f6eeb02a2e6387c17215d3b75289641312b68a1..1e265868b26c941351d1eb4a829bf0b8de0c8480 100644 (file)
@@ -83,6 +83,22 @@ Add sphere at WorldEdit position 1 with radius <radius>, composed of <node>.
     //sphere 12 default:glass\r
     //sphere 17 mesecons:mesecon\r
 \r
+### //hollowdome <radius> <node>\r
+\r
+Add hollow dome at WorldEdit position 1 with radius <radius>, composed of <node>.\r
+\r
+    //hollowdome 5 dirt\r
+    //hollowdome 12 default:glass\r
+    //hollowdome 17 mesecons:mesecon\r
+\r
+### //dome <radius> <node>\r
+\r
+Add dome at WorldEdit position 1 with radius <radius>, composed of <node>.\r
+\r
+    //dome 5 dirt\r
+    //dome 12 default:glass\r
+    //dome 17 mesecons:mesecon\r
+\r
 ### //hollowcylinder x/y/z/? <length> <radius> <node>\r
 \r
 Add hollow cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length> and radius <radius>, composed of <node>.\r
index a69062f04e5e482e34fa2a0288e8148884e842bf..6008a9fb54431629b88709c99ca3af921accdfd2 100644 (file)
@@ -92,6 +92,18 @@ Adds a sphere at `pos` with radius `radius`, composed of `nodename`.
 \r
 Returns the number of nodes added.\r
 \r
+### count = worldedit.hollow_dome(pos, radius, nodename)\r
+\r
+Adds a hollow dome at `pos` with radius `radius`, composed of `nodename`.\r
+\r
+Returns the number of nodes added.\r
+\r
+### count = worldedit.dome(pos, radius, nodename)\r
+\r
+Adds a dome at `pos` with radius `radius`, composed of `nodename`.\r
+\r
+Returns the number of nodes added.\r
+\r
 ### count = worldedit.hollow_cylinder(pos, axis, length, radius, nodename)\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`.\r
index 37e2298a408adfe800b89827f506c159967a7772..8dfe88e81cecb01fa750d070dd14c4db17af5f04 100644 (file)
@@ -1,10 +1,11 @@
 worldedit = worldedit or {}\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) --wip: use bresenham sphere for maximum speed\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 min_radius = radius * (radius - 1)\r
+       local max_radius = radius * (radius + 1)\r
        local count = 0\r
        local env = minetest.env\r
        for x = -radius, radius do\r
@@ -12,9 +13,9 @@ worldedit.hollow_sphere = function(pos, radius, nodename) --wip: use bresenham s
                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
+                               if x*x+y*y+z*z >= min_radius and x*x+y*y+z*z <= max_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
+                                       env:add_node(pos1, node)\r
                                        count = count + 1\r
                                end\r
                        end\r
@@ -24,10 +25,10 @@ worldedit.hollow_sphere = function(pos, radius, nodename) --wip: use bresenham s
 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) --wip: use bresenham sphere for maximum speed\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 max_radius = radius * (radius + 1)\r
        local count = 0\r
        local env = minetest.env\r
        for x = -radius, radius do\r
@@ -35,7 +36,54 @@ worldedit.sphere = function(pos, radius, nodename) --wip: use bresenham sphere f
                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
+                               if x*x+y*y+z*z <= max_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 dome at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added\r
+worldedit.hollow_dome = 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 min_radius = radius * (radius - 1)\r
+       local max_radius = radius * (radius + 1)\r
+       local count = 0\r
+       local env = minetest.env\r
+       for x = -radius, radius do\r
+               pos1.x = pos.x + x\r
+               for y = 0, radius do\r
+                       pos1.y = pos.y + y\r
+                       for z = -radius, radius do\r
+                               if x*x+y*y+z*z >= min_radius and x*x+y*y+z*z <= max_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 dome at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added\r
+worldedit.dome = 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 max_radius = radius * (radius + 1)\r
+       local count = 0\r
+       local env = minetest.env\r
+       for x = -radius, radius do\r
+               pos1.x = pos.x + x\r
+               for y = 0, radius do\r
+                       pos1.y = pos.y + y\r
+                       for z = -radius, radius do\r
+                               if x*x+y*y+z*z <= max_radius then\r
                                        pos1.z = pos.z + z\r
                                        env:add_node(pos1, node)\r
                                        count = count + 1\r
index da24747890b8e28cdc08f87f394b13dbb89351f2..fb01ce722ead0ca685fde5e7d93fe7374d1d3bb1 100644 (file)
@@ -279,6 +279,58 @@ minetest.register_chatcommand("/sphere", {
        end,\r
 })\r
 \r
+minetest.register_chatcommand("/hollowdome", {\r
+       params = "<radius> <node>",\r
+       description = "Add hollow dome 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", false)\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, false)\r
+                       return\r
+               end\r
+               if not worldedit.node_is_valid(nodename) then\r
+                       minetest.chat_send_player(name, "Invalid node name: " .. param, false)\r
+                       return\r
+               end\r
+\r
+               local count = worldedit.hollow_dome(pos, tonumber(radius), nodename)\r
+               minetest.chat_send_player(name, count .. " nodes added", false)\r
+       end,\r
+})\r
+\r
+minetest.register_chatcommand("/dome", {\r
+       params = "<radius> <node>",\r
+       description = "Add dome 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", false)\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, false)\r
+                       return\r
+               end\r
+               if not worldedit.node_is_valid(nodename) then\r
+                       minetest.chat_send_player(name, "Invalid node name: " .. param, false)\r
+                       return\r
+               end\r
+\r
+               local count = worldedit.dome(pos, tonumber(radius), nodename)\r
+               minetest.chat_send_player(name, count .. " nodes added", false)\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