]> git.lizzy.rs Git - worldedit.git/blobdiff - init.lua
Add //hollowcylinder and //cylinder commands, add worldedit.hollow_cylinder and world...
[worldedit.git] / init.lua
index 5c37567138723f654da5ee6bdd273364ac9661a8..eae615b349532654492100cea2204cffd7632f2c 100644 (file)
--- a/init.lua
+++ b/init.lua
@@ -12,14 +12,8 @@ dofile(minetest.get_modpath("worldedit") .. "/mark.lua")
 \r
 --determines whether `nodename` is a valid node name, returning a boolean\r
 worldedit.node_is_valid = function(temp_pos, nodename)\r
-       local originalnode = minetest.env:get_node(temp_pos) --save the original node to restore later\r
-       minetest.env:add_node(temp_pos, {name=nodename}) --attempt to add the node\r
-       local value = minetest.env:get_node(temp_pos).name --obtain the name of the newly added node\r
-       if value == nodename or value == "default:" .. nodename then --successfully added node\r
-               minetest.env:add_node(temp_pos, originalnode) --restore the original node\r
-               return true --node is valid\r
-       end\r
-       return false --node is not valid\r
+       return minetest.registered_nodes[nodename] ~= nil\r
+       or minetest.registered_nodes["default:" .. nodename] ~= nil\r
 end\r
 \r
 minetest.register_chatcommand("/reset", {\r
@@ -181,6 +175,58 @@ minetest.register_chatcommand("/replace", {
        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
+       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, _, axis, length, radius, nodename = param:find("^([xyz])%s+([+-]?%d+)%s+(%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_cylinder(pos, axis, tonumber(length), tonumber(radius), nodename)\r
+               minetest.chat_send_player(name, count .. " nodes added")\r
+       end,\r
+})\r
+\r
+minetest.register_chatcommand("/cylinder", {\r
+       params = "x/y/z <length> <radius> <node>",\r
+       description = "Add cylinder at WorldEdit position 1 along the x/y/z axis with length <length> and 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, _, axis, length, radius, nodename = param:find("^([xyz])%s+([+-]?%d+)%s+(%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.cylinder(pos, axis, tonumber(length), tonumber(radius), nodename)\r
+               minetest.chat_send_player(name, count .. " nodes added")\r
+       end,\r
+})\r
+\r
 minetest.register_chatcommand("/copy", {\r
        params = "x/y/z <amount>",\r
        description = "Copy the current WorldEdit region along the x/y/z axis by <amount> nodes",\r