]> git.lizzy.rs Git - worldedit.git/blobdiff - worldedit_commands/init.lua
Fix invalid node error message of //set and //mix
[worldedit.git] / worldedit_commands / init.lua
index 208eb5da0c18a5e6c7311effe854c6460455085a..a102dbcbf43b7bcb96e699d5204cbabd36d3c6ac 100644 (file)
@@ -1,21 +1,87 @@
 minetest.register_privilege("worldedit", "Can use WorldEdit commands")\r
 \r
 worldedit.set_pos = {}\r
+worldedit.inspect = {}\r
 \r
 worldedit.pos1 = {}\r
 worldedit.pos2 = {}\r
+if minetest.place_schematic then\r
+       worldedit.prob_pos = {}\r
+       worldedit.prob_list = {}\r
+end\r
 \r
+dofile(minetest.get_modpath("worldedit_commands") .. "/cuboid.lua")\r
 dofile(minetest.get_modpath("worldedit_commands") .. "/mark.lua")\r
+dofile(minetest.get_modpath("worldedit_commands") .. "/wand.lua")\r
+local safe_region, check_region, reset_pending = dofile(minetest.get_modpath("worldedit_commands") .. "/safe.lua")\r
+\r
+local function get_position(name) --position 1 retrieval function for when not using `safe_region`\r
+       local pos1 = worldedit.pos1[name]\r
+       if pos1 == nil then\r
+               worldedit.player_notify(name, "no position 1 selected")\r
+       end\r
+       return pos1\r
+end\r
 \r
---determines whether `nodename` is a valid node name, returning a boolean\r
-worldedit.node_is_valid = function(nodename)\r
-       return minetest.registered_nodes[nodename] ~= nil\r
-       or minetest.registered_nodes["default:" .. nodename] ~= nil\r
+-- normalize_nodename wrapper for convenience purposes\r
+local function get_node(name, nodename)\r
+       local node = worldedit.normalize_nodename(nodename)\r
+       if not node then\r
+               worldedit.player_notify(name, "invalid node name: " .. nodename)\r
+               return nil\r
+       end\r
+       return node\r
+end\r
+\r
+function worldedit.player_notify(name, message)\r
+       minetest.chat_send_player(name, "WorldEdit -!- " .. message, false)\r
 end\r
 \r
---determines the axis in which a player is facing, returning an axis ("x", "y", or "z") and the sign (1 or -1)\r
-worldedit.player_axis = function(name)\r
-       local dir = minetest.env:get_player_by_name(name):get_look_dir()\r
+local function string_endswith(full, part)\r
+       return full:find(part, 1, true) == #full - #part + 1\r
+end\r
+\r
+-- normalizes node "description" `nodename`, returning a string (or nil)\r
+worldedit.normalize_nodename = function(nodename)\r
+       nodename = nodename:gsub("^%s*(.-)%s*$", "%1") -- strip spaces\r
+       if nodename == "" then return nil end\r
+\r
+       local fullname = ItemStack({name=nodename}):get_name() -- resolve aliases\r
+       if minetest.registered_nodes[fullname] or fullname == "air" then -- full name\r
+               return fullname\r
+       end\r
+       for key, value in pairs(minetest.registered_nodes) do\r
+               if string_endswith(key, ":" .. nodename) then -- matches name (w/o mod part)\r
+                       return key\r
+               end\r
+       end\r
+       nodename = nodename:lower() -- lowercase both for case insensitive comparison\r
+       for key, value in pairs(minetest.registered_nodes) do\r
+               local desc = value.description:lower()\r
+               if desc == nodename then -- matches description\r
+                       return key\r
+               end\r
+               if string_endswith(desc, " block") and desc == nodename.." block" then\r
+                       -- fuzzy description match (e.g. "Steel" == "Steel Block")\r
+                       return key\r
+               end\r
+       end\r
+\r
+       local match = nil\r
+       for key, value in pairs(minetest.registered_nodes) do\r
+               if value.description:lower():find(nodename, 1, true) ~= nil then\r
+                       if match ~= nil then\r
+                               return nil\r
+                       end\r
+                       match = key -- substring description match (only if no ambiguities)\r
+               end\r
+       end\r
+       return match\r
+end\r
+\r
+-- Determines the axis in which a player is facing, returning an axis ("x", "y", or "z") and the sign (1 or -1)\r
+function worldedit.player_axis(name)\r
+       local dir = minetest.get_player_by_name(name):get_look_dir()\r
        local x, y, z = math.abs(dir.x), math.abs(dir.y), math.abs(dir.z)\r
        if x > y then\r
                if x > z then\r
@@ -27,6 +93,122 @@ worldedit.player_axis = function(name)
        return "z", dir.z > 0 and 1 or -1\r
 end\r
 \r
+local function mkdir(path)\r
+       if minetest.mkdir then\r
+               minetest.mkdir(path)\r
+       else\r
+               os.execute('mkdir "' .. path .. '"')\r
+       end\r
+end\r
+\r
+local function check_filename(name)\r
+       return name:find("^[%w%s%^&'@{}%[%],%$=!%-#%(%)%%%.%+~_]+$") ~= nil\r
+end\r
+\r
+\r
+minetest.register_chatcommand("/about", {\r
+       params = "",\r
+       description = "Get information about the mod",\r
+       func = function(name, param)\r
+               worldedit.player_notify(name, "WorldEdit " .. worldedit.version_string .. " is available on this server. Type /help to get a list of commands, or get more information at https://github.com/Uberi/MineTest-WorldEdit/")\r
+       end,\r
+})\r
+\r
+-- mostly copied from builtin/chatcommands.lua with minor modifications\r
+minetest.register_chatcommand("/help", {\r
+       privs = {},\r
+       params = "[all/<cmd>]",\r
+       description = "Get help for WorldEdit commands",\r
+       func = function(name, param)\r
+               local function is_we_command(cmd)\r
+                       return cmd:sub(0, 1) == "/"\r
+               end\r
+               local function format_help_line(cmd, def)\r
+                       local msg = minetest.colorize("#00ffff", "/"..cmd)\r
+                       if def.params and def.params ~= "" then\r
+                               msg = msg .. " " .. def.params\r
+                       end\r
+                       if def.description and def.description ~= "" then\r
+                               msg = msg .. ": " .. def.description\r
+                       end\r
+                       return msg\r
+               end\r
+\r
+               if not minetest.check_player_privs(name, "worldedit") then\r
+                       return false, "You are not allowed to use any WorldEdit commands."\r
+               end\r
+               if param == "" then\r
+                       local msg = ""\r
+                       local cmds = {}\r
+                       for cmd, def in pairs(minetest.chatcommands) do\r
+                               if is_we_command(cmd) and minetest.check_player_privs(name, def.privs) then\r
+                                       cmds[#cmds + 1] = cmd:sub(2) -- strip the /\r
+                               end\r
+                       end\r
+                       table.sort(cmds)\r
+                       return true, "Available commands: " .. table.concat(cmds, " ") .. "\n"\r
+                                       .. "Use '//help <cmd>' to get more information,"\r
+                                       .. " or '//help all' to list everything."\r
+               elseif param == "all" then\r
+                       local cmds = {}\r
+                       for cmd, def in pairs(minetest.chatcommands) do\r
+                               if is_we_command(cmd) and minetest.check_player_privs(name, def.privs) then\r
+                                       cmds[#cmds + 1] = format_help_line(cmd, def)\r
+                               end\r
+                       end\r
+                       table.sort(cmds)\r
+                       return true, "Available commands:\n"..table.concat(cmds, "\n")\r
+               else\r
+                       return minetest.chatcommands["help"].func(name, "/" .. param)\r
+               end\r
+       end,\r
+})\r
+\r
+minetest.register_chatcommand("/inspect", {\r
+       params = "on/off/1/0/true/false/yes/no/enable/disable/<blank>",\r
+       description = "Enable or disable node inspection",\r
+       privs = {worldedit=true},\r
+       func = function(name, param)\r
+               if param == "on" or param == "1" or param == "true" or param == "yes" or param == "enable" or param == "" then\r
+                       worldedit.inspect[name] = true\r
+                       local axis, sign = worldedit.player_axis(name)\r
+                       worldedit.player_notify(name, string.format("inspector: inspection enabled for %s, currently facing the %s axis",\r
+                               name, axis .. (sign > 0 and "+" or "-")))\r
+               elseif param == "off" or param == "0" or param == "false" or param == "no" or param == "disable" then\r
+                       worldedit.inspect[name] = nil\r
+                       worldedit.player_notify(name, "inspector: inspection disabled")\r
+               else\r
+                       worldedit.player_notify(name, "invalid usage: " .. param)\r
+               end\r
+       end,\r
+})\r
+\r
+local function get_node_rlight(pos)\r
+       local vecs = { -- neighboring nodes\r
+               {x= 1, y= 0, z= 0},\r
+               {x=-1, y= 0, z= 0},\r
+               {x= 0, y= 1, z= 0},\r
+               {x= 0, y=-1, z= 0},\r
+               {x= 0, y= 0, z= 1},\r
+               {x= 0, y= 0, z=-1},\r
+       }\r
+       local ret = 0\r
+       for _, v in ipairs(vecs) do\r
+               ret = math.max(ret, minetest.get_node_light(vector.add(pos, v)))\r
+       end\r
+       return ret\r
+end\r
+\r
+minetest.register_on_punchnode(function(pos, node, puncher)\r
+       local name = puncher:get_player_name()\r
+       if worldedit.inspect[name] then\r
+               local axis, sign = worldedit.player_axis(name)\r
+               message = string.format("inspector: %s at %s (param1=%d, param2=%d, received light=%d) punched facing the %s axis",\r
+                       node.name, minetest.pos_to_string(pos), node.param1, node.param2, get_node_rlight(pos), axis .. (sign > 0 and "+" or "-"))\r
+               worldedit.player_notify(name, message)\r
+       end\r
+end)\r
+\r
 minetest.register_chatcommand("/reset", {\r
        params = "",\r
        description = "Reset the region so that it is empty",\r
@@ -36,7 +218,10 @@ minetest.register_chatcommand("/reset", {
                worldedit.pos2[name] = nil\r
                worldedit.mark_pos1(name)\r
                worldedit.mark_pos2(name)\r
-               minetest.chat_send_player(name, "WorldEdit region reset")\r
+               worldedit.set_pos[name] = nil\r
+               --make sure the user does not try to confirm an operation after resetting pos:\r
+               reset_pending(name)\r
+               worldedit.player_notify(name, "region reset")\r
        end,\r
 })\r
 \r
@@ -47,7 +232,23 @@ minetest.register_chatcommand("/mark", {
        func = function(name, param)\r
                worldedit.mark_pos1(name)\r
                worldedit.mark_pos2(name)\r
-               minetest.chat_send_player(name, "WorldEdit region marked")\r
+               worldedit.player_notify(name, "region marked")\r
+       end,\r
+})\r
+\r
+minetest.register_chatcommand("/unmark", {\r
+       params = "",\r
+       description = "Hide markers if currently shown",\r
+       privs = {worldedit=true},\r
+       func = function(name, param)\r
+               local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
+               worldedit.pos1[name] = nil\r
+               worldedit.pos2[name] = nil\r
+               worldedit.mark_pos1(name)\r
+               worldedit.mark_pos2(name)\r
+               worldedit.pos1[name] = pos1\r
+               worldedit.pos2[name] = pos2\r
+               worldedit.player_notify(name, "region unmarked")\r
        end,\r
 })\r
 \r
@@ -56,11 +257,11 @@ minetest.register_chatcommand("/pos1", {
        description = "Set WorldEdit region position 1 to the player's location",\r
        privs = {worldedit=true},\r
        func = function(name, param)\r
-               local pos = minetest.env:get_player_by_name(name):getpos()\r
+               local pos = minetest.get_player_by_name(name):getpos()\r
                pos.x, pos.y, pos.z = math.floor(pos.x + 0.5), math.floor(pos.y + 0.5), math.floor(pos.z + 0.5)\r
                worldedit.pos1[name] = pos\r
                worldedit.mark_pos1(name)\r
-               minetest.chat_send_player(name, "WorldEdit position 1 set to " .. minetest.pos_to_string(pos))\r
+               worldedit.player_notify(name, "position 1 set to " .. minetest.pos_to_string(pos))\r
        end,\r
 })\r
 \r
@@ -69,11 +270,11 @@ minetest.register_chatcommand("/pos2", {
        description = "Set WorldEdit region position 2 to the player's location",\r
        privs = {worldedit=true},\r
        func = function(name, param)\r
-               local pos = minetest.env:get_player_by_name(name):getpos()\r
+               local pos = minetest.get_player_by_name(name):getpos()\r
                pos.x, pos.y, pos.z = math.floor(pos.x + 0.5), math.floor(pos.y + 0.5), math.floor(pos.z + 0.5)\r
                worldedit.pos2[name] = pos\r
                worldedit.mark_pos2(name)\r
-               minetest.chat_send_player(name, "WorldEdit position 2 set to " .. minetest.pos_to_string(pos))\r
+               worldedit.player_notify(name, "position 2 set to " .. minetest.pos_to_string(pos))\r
        end,\r
 })\r
 \r
@@ -84,26 +285,49 @@ minetest.register_chatcommand("/p", {
        func = function(name, param)\r
                if param == "set" then --set both WorldEdit positions\r
                        worldedit.set_pos[name] = "pos1"\r
-                       minetest.chat_send_player(name, "Select positions by punching two nodes")\r
+                       worldedit.player_notify(name, "select positions by punching two nodes")\r
                elseif param == "set1" then --set WorldEdit position 1\r
                        worldedit.set_pos[name] = "pos1only"\r
-                       minetest.chat_send_player(name, "Select position 1 by punching a node")\r
+                       worldedit.player_notify(name, "select position 1 by punching a node")\r
                elseif param == "set2" then --set WorldEdit position 2\r
                        worldedit.set_pos[name] = "pos2"\r
-                       minetest.chat_send_player(name, "Select position 2 by punching a node")\r
+                       worldedit.player_notify(name, "select position 2 by punching a node")\r
                elseif param == "get" then --display current WorldEdit positions\r
                        if worldedit.pos1[name] ~= nil then\r
-                               minetest.chat_send_player(name, "WorldEdit position 1: " .. minetest.pos_to_string(worldedit.pos1[name]))\r
+                               worldedit.player_notify(name, "position 1: " .. minetest.pos_to_string(worldedit.pos1[name]))\r
                        else\r
-                               minetest.chat_send_player(name, "WorldEdit position 1 not set")\r
+                               worldedit.player_notify(name, "position 1 not set")\r
                        end\r
                        if worldedit.pos2[name] ~= nil then\r
-                               minetest.chat_send_player(name, "WorldEdit position 2: " .. minetest.pos_to_string(worldedit.pos2[name]))\r
+                               worldedit.player_notify(name, "position 2: " .. minetest.pos_to_string(worldedit.pos2[name]))\r
                        else\r
-                               minetest.chat_send_player(name, "WorldEdit position 2 not set")\r
+                               worldedit.player_notify(name, "position 2 not set")\r
                        end\r
                else\r
-                       minetest.chat_send_player(name, "Unknown subcommand: " .. param)\r
+                       worldedit.player_notify(name, "unknown subcommand: " .. param)\r
+               end\r
+       end,\r
+})\r
+\r
+minetest.register_chatcommand("/fixedpos", {\r
+       params = "set1/set2 x y z",\r
+       description = "Set a WorldEdit region position to the position at (<x>, <y>, <z>)",\r
+       privs = {worldedit=true},\r
+       func = function(name, param)\r
+               local found, _, flag, x, y, z = param:find("^(set[12])%s+([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)$")\r
+               if found == nil then\r
+                       worldedit.player_notify(name, "invalid usage: " .. param)\r
+                       return\r
+               end\r
+               local pos = {x=tonumber(x), y=tonumber(y), z=tonumber(z)}\r
+               if flag == "set1" then\r
+                       worldedit.pos1[name] = pos\r
+                       worldedit.mark_pos1(name)\r
+                       worldedit.player_notify(name, "position 1 set to " .. minetest.pos_to_string(pos))\r
+               else --flag == "set2"\r
+                       worldedit.pos2[name] = pos\r
+                       worldedit.mark_pos2(name)\r
+                       worldedit.player_notify(name, "position 2 set to " .. minetest.pos_to_string(pos))\r
                end\r
        end,\r
 })\r
@@ -115,17 +339,20 @@ minetest.register_on_punchnode(function(pos, node, puncher)
                        worldedit.pos1[name] = pos\r
                        worldedit.mark_pos1(name)\r
                        worldedit.set_pos[name] = "pos2" --set position 2 on the next invocation\r
-                       minetest.chat_send_player(name, "WorldEdit position 1 set to " .. minetest.pos_to_string(pos))\r
+                       worldedit.player_notify(name, "position 1 set to " .. minetest.pos_to_string(pos))\r
                elseif worldedit.set_pos[name] == "pos1only" then --setting position 1 only\r
                        worldedit.pos1[name] = pos\r
                        worldedit.mark_pos1(name)\r
                        worldedit.set_pos[name] = nil --finished setting positions\r
-                       minetest.chat_send_player(name, "WorldEdit position 1 set to " .. minetest.pos_to_string(pos))\r
+                       worldedit.player_notify(name, "position 1 set to " .. minetest.pos_to_string(pos))\r
                elseif worldedit.set_pos[name] == "pos2" then --setting position 2\r
                        worldedit.pos2[name] = pos\r
                        worldedit.mark_pos2(name)\r
                        worldedit.set_pos[name] = nil --finished setting positions\r
-                       minetest.chat_send_player(name, "WorldEdit position 2 set to " .. minetest.pos_to_string(pos))\r
+                       worldedit.player_notify(name, "position 2 set to " .. minetest.pos_to_string(pos))\r
+               elseif worldedit.set_pos[name] == "prob" then --setting Minetest schematic node probabilities\r
+                       worldedit.prob_pos[name] = pos\r
+                       minetest.show_formspec(puncher:get_player_name(), "prob_val_enter", "field[text;;]")\r
                end\r
        end\r
 end)\r
@@ -137,371 +364,549 @@ minetest.register_chatcommand("/volume", {
        func = function(name, param)\r
                local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
                if pos1 == nil or pos2 == nil then\r
-                       minetest.chat_send_player(name, "No WorldEdit region selected")\r
-                       return\r
+                       worldedit.player_notify(name, "no region selected")\r
+                       return nil\r
                end\r
 \r
                local volume = worldedit.volume(pos1, pos2)\r
-               minetest.chat_send_player(name, "Current WorldEdit region has a volume of " .. volume .. " nodes (" .. pos2.x - pos1.x .. "*" .. pos2.y - pos1.y .. "*" .. pos2.z - pos1.z .. ")")\r
+               local abs = math.abs\r
+               worldedit.player_notify(name, "current region has a volume of " .. volume .. " nodes ("\r
+                       .. abs(pos2.x - pos1.x) + 1 .. "*"\r
+                       .. abs(pos2.y - pos1.y) + 1 .. "*"\r
+                       .. abs(pos2.z - pos1.z) + 1 .. ")")\r
        end,\r
 })\r
 \r
+minetest.register_chatcommand("/deleteblocks", {\r
+       params = "",\r
+       description = "remove all MapBlocks (16x16x16) containing the selected area from the map",\r
+       privs = {worldedit=true},\r
+       func = safe_region(function(name, param)\r
+               local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
+               local success = minetest.delete_area(pos1, pos2)\r
+               if success then\r
+                       worldedit.player_notify(name, "Area deleted.")\r
+               else\r
+                       worldedit.player_notify(name, "There was an error during deletion of the area.")\r
+               end\r
+       end),\r
+})\r
+\r
 minetest.register_chatcommand("/set", {\r
        params = "<node>",\r
        description = "Set the current WorldEdit region to <node>",\r
        privs = {worldedit=true},\r
-       func = function(name, param)\r
-               local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
-               if pos1 == nil or pos2 == nil then\r
-                       minetest.chat_send_player(name, "No WorldEdit region selected")\r
+       func = safe_region(function(name, param)\r
+               local node = get_node(name, param)\r
+               if not node then return end\r
+\r
+               local count = worldedit.set(worldedit.pos1[name], worldedit.pos2[name], node)\r
+               worldedit.player_notify(name, count .. " nodes set")\r
+       end, check_region),\r
+})\r
+\r
+minetest.register_chatcommand("/param2", {\r
+       params = "<param2>",\r
+       description = "Set param2 of all nodes in the current WorldEdit region to <param2>",\r
+       privs = {worldedit=true},\r
+       func = safe_region(function(name, param)\r
+               local param2 = tonumber(param)\r
+               if not param2 then\r
+                       worldedit.player_notify(name, "Invalid or missing param2 argument")\r
+                       return\r
+               elseif param2 < 0 or param2 > 255 then\r
+                       worldedit.player_notify(name, "Param2 is out of range (must be between 0 and 255 inclusive)!")\r
                        return\r
                end\r
 \r
-               if param == "" or not worldedit.node_is_valid(param) then\r
-                       minetest.chat_send_player(name, "Invalid node name: " .. param)\r
-                       return\r
+               local count = worldedit.set_param2(worldedit.pos1[name], worldedit.pos2[name], param2)\r
+               worldedit.player_notify(name, count .. " nodes altered")\r
+       end, check_region),\r
+})\r
+\r
+minetest.register_chatcommand("/mix", {\r
+       params = "<node1> ...",\r
+       description = "Fill the current WorldEdit region with a random mix of <node1>, ...",\r
+       privs = {worldedit=true},\r
+       func = safe_region(function(name, param)\r
+               local nodes = {}\r
+               for nodename in param:gmatch("[^%s]+") do\r
+                       local node = get_node(name, nodename)\r
+                       if not node then return end\r
+                       nodes[#nodes + 1] = node\r
                end\r
 \r
-               local count = worldedit.set(pos1, pos2, param)\r
-               minetest.chat_send_player(name, count .. " nodes set")\r
-       end,\r
+               local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
+               local count = worldedit.set(pos1, pos2, nodes)\r
+               worldedit.player_notify(name, count .. " nodes set")\r
+       end, check_region),\r
 })\r
 \r
+local check_replace = function(name, param)\r
+       local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+(.+)$")\r
+       if found == nil then\r
+               worldedit.player_notify(name, "invalid usage: " .. param)\r
+               return nil\r
+       end\r
+       local newsearchnode = worldedit.normalize_nodename(searchnode)\r
+       if not newsearchnode then\r
+               worldedit.player_notify(name, "invalid search node name: " .. searchnode)\r
+               return nil\r
+       end\r
+       local newreplacenode = worldedit.normalize_nodename(replacenode)\r
+       if not newreplacenode then\r
+               worldedit.player_notify(name, "invalid replace node name: " .. replacenode)\r
+               return nil\r
+       end\r
+       return check_region(name, param)\r
+end\r
+\r
 minetest.register_chatcommand("/replace", {\r
        params = "<search node> <replace node>",\r
        description = "Replace all instances of <search node> with <replace node> in the current WorldEdit region",\r
        privs = {worldedit=true},\r
-       func = function(name, param)\r
-               local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
-               if pos1 == nil or pos2 == nil then\r
-                       minetest.chat_send_player(name, "No WorldEdit region selected")\r
-                       return\r
-               end\r
-\r
-               local found, _, searchnode, replacenode = param:find("^([^%s]+)%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(searchnode) then\r
-                       minetest.chat_send_player(name, "Invalid search node name: " .. searchnode)\r
-                       return\r
-               end\r
-               if not worldedit.node_is_valid(replacenode) then\r
-                       minetest.chat_send_player(name, "Invalid replace node name: " .. replacenode)\r
-                       return\r
-               end\r
-\r
-               local count = worldedit.replace(pos1, pos2, searchnode, replacenode)\r
-               minetest.chat_send_player(name, count .. " nodes replaced")\r
-       end,\r
+       func = safe_region(function(name, param)\r
+               local found, _, search_node, replace_node = param:find("^([^%s]+)%s+(.+)$")\r
+               local norm_search_node = worldedit.normalize_nodename(search_node)\r
+               local norm_replace_node = worldedit.normalize_nodename(replace_node)\r
+               local count = worldedit.replace(worldedit.pos1[name], worldedit.pos2[name],\r
+                               norm_search_node, norm_replace_node)\r
+               worldedit.player_notify(name, count .. " nodes replaced")\r
+       end, check_replace),\r
 })\r
 \r
 minetest.register_chatcommand("/replaceinverse", {\r
        params = "<search node> <replace node>",\r
        description = "Replace all nodes other than <search node> with <replace node> in the current WorldEdit region",\r
        privs = {worldedit=true},\r
-       func = function(name, param)\r
-               local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
-               if pos1 == nil or pos2 == nil then\r
-                       minetest.chat_send_player(name, "No WorldEdit region selected")\r
-                       return\r
-               end\r
+       func = safe_region(function(name, param)\r
+               local found, _, search_node, replace_node = param:find("^([^%s]+)%s+(.+)$")\r
+               local norm_search_node = worldedit.normalize_nodename(search_node)\r
+               local norm_replace_node = worldedit.normalize_nodename(replace_node)\r
+               local count = worldedit.replace(worldedit.pos1[name], worldedit.pos2[name],\r
+                               norm_search_node, norm_replace_node, true)\r
+               worldedit.player_notify(name, count .. " nodes replaced")\r
+       end, check_replace),\r
+})\r
 \r
-               local found, _, searchnode, replacenode = param:find("^([^%s]+)%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(searchnode) then\r
-                       minetest.chat_send_player(name, "Invalid search node name: " .. searchnode)\r
-                       return\r
-               end\r
-               if not worldedit.node_is_valid(replacenode) then\r
-                       minetest.chat_send_player(name, "Invalid replace node name: " .. replacenode)\r
-                       return\r
-               end\r
+local check_cube = function(name, param)\r
+       if worldedit.pos1[name] == nil then\r
+               worldedit.player_notify(name, "no position 1 selected")\r
+               return nil\r
+       end\r
+       local found, _, w, h, l, nodename = param:find("^(%d+)%s+(%d+)%s+(%d+)%s+(.+)$")\r
+       if found == nil then\r
+               worldedit.player_notify(name, "invalid usage: " .. param)\r
+               return nil\r
+       end\r
+       local node = get_node(name, nodename)\r
+       if not node then return nil end\r
+       return tonumber(w) * tonumber(h) * tonumber(l)\r
+end\r
 \r
-               local count = worldedit.replaceinverse(pos1, pos2, searchnode, replacenode)\r
-               minetest.chat_send_player(name, count .. " nodes replaced")\r
-       end,\r
+minetest.register_chatcommand("/hollowcube", {\r
+       params = "<width> <height> <length> <node>",\r
+       description = "Add a hollow cube with its ground level centered at WorldEdit position 1 with dimensions <width> x <height> x <length>, composed of <node>.",\r
+       privs = {worldedit=true},\r
+       func = safe_region(function(name, param)\r
+               local found, _, w, h, l, nodename = param:find("^(%d+)%s+(%d+)%s+(%d+)%s+(.+)$")\r
+               local node = get_node(name, nodename)\r
+               local count = worldedit.cube(worldedit.pos1[name], tonumber(w), tonumber(h), tonumber(l), node, true)\r
+               worldedit.player_notify(name, count .. " nodes added")\r
+       end, check_cube),\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
+minetest.register_chatcommand("/cube", {\r
+       params = "<width> <height> <length> <node>",\r
+       description = "Add a cube with its ground level centered at WorldEdit position 1 with dimensions <width> x <height> x <length>, 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
+       func = safe_region(function(name, param)\r
+               local found, _, w, h, l, nodename = param:find("^(%d+)%s+(%d+)%s+(%d+)%s+(.+)$")\r
+               local node = get_node(name, nodename)\r
+               local count = worldedit.cube(worldedit.pos1[name], tonumber(w), tonumber(h), tonumber(l), node)\r
+               worldedit.player_notify(name, count .. " nodes added")\r
+       end, check_cube),\r
+})\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(nodename) then\r
-                       minetest.chat_send_player(name, "Invalid node name: " .. param)\r
-                       return\r
-               end\r
+local check_sphere = function(name, param)\r
+       if worldedit.pos1[name] == nil then\r
+               worldedit.player_notify(name, "no position 1 selected")\r
+               return nil\r
+       end\r
+       local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")\r
+       if found == nil then\r
+               worldedit.player_notify(name, "invalid usage: " .. param)\r
+               return nil\r
+       end\r
+       local node = get_node(name, nodename)\r
+       if not node then return nil end\r
+       return math.ceil((4 * math.pi * (tonumber(radius) ^ 3)) / 3) --volume of sphere\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
+minetest.register_chatcommand("/hollowsphere", {\r
+       params = "<radius> <node>",\r
+       description = "Add hollow sphere centered at WorldEdit position 1 with radius <radius>, composed of <node>",\r
+       privs = {worldedit=true},\r
+       func = safe_region(function(name, param)\r
+               local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")\r
+               local node = get_node(name, nodename)\r
+               local count = worldedit.sphere(worldedit.pos1[name], tonumber(radius), node, true)\r
+               worldedit.player_notify(name, count .. " nodes added")\r
+       end, check_sphere),\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
+       description = "Add sphere centered 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
+       func = safe_region(function(name, param)\r
+               local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")\r
+               local node = get_node(name, nodename)\r
+               local count = worldedit.sphere(worldedit.pos1[name], tonumber(radius), node)\r
+               worldedit.player_notify(name, count .. " nodes added")\r
+       end, check_sphere),\r
+})\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(nodename) then\r
-                       minetest.chat_send_player(name, "Invalid node name: " .. param)\r
-                       return\r
-               end\r
+local check_dome = function(name, param)\r
+       if worldedit.pos1[name] == nil then\r
+               worldedit.player_notify(name, "no position 1 selected")\r
+               return nil\r
+       end\r
+       local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")\r
+       if found == nil then\r
+               worldedit.player_notify(name, "invalid usage: " .. param)\r
+               return nil\r
+       end\r
+       local node = get_node(name, nodename)\r
+       if not node then return nil end\r
+       return math.ceil((2 * math.pi * (tonumber(radius) ^ 3)) / 3) --volume of dome\r
+end\r
 \r
-               local count = worldedit.sphere(pos, tonumber(radius), nodename)\r
-               minetest.chat_send_player(name, count .. " nodes added")\r
-       end,\r
+minetest.register_chatcommand("/hollowdome", {\r
+       params = "<radius> <node>",\r
+       description = "Add hollow dome centered at WorldEdit position 1 with radius <radius>, composed of <node>",\r
+       privs = {worldedit=true},\r
+       func = safe_region(function(name, param)\r
+               local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")\r
+               local node = get_node(name, nodename)\r
+               local count = worldedit.dome(worldedit.pos1[name], tonumber(radius), node, true)\r
+               worldedit.player_notify(name, count .. " nodes added")\r
+       end, check_dome),\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
+minetest.register_chatcommand("/dome", {\r
+       params = "<radius> <node>",\r
+       description = "Add dome centered 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
+       func = safe_region(function(name, param)\r
+               local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")\r
+               local node = get_node(name, nodename)\r
+               local count = worldedit.dome(worldedit.pos1[name], tonumber(radius), node)\r
+               worldedit.player_notify(name, count .. " nodes added")\r
+       end, check_dome),\r
+})\r
+\r
+local check_cylinder = function(name, param)\r
+       if worldedit.pos1[name] == nil then\r
+               worldedit.player_notify(name, "no position 1 selected")\r
+               return nil\r
+       end\r
+       -- two radii\r
+       local found, _, axis, length, radius1, radius2, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(%d+)%s+(.+)$")\r
+       if found == nil then\r
+               -- single radius\r
+               found, _, axis, length, radius1, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$")\r
+               radius2 = radius1\r
+       end\r
+       if found == nil then\r
+               worldedit.player_notify(name, "invalid usage: " .. param)\r
+               return nil\r
+       end\r
+       local node = get_node(name, nodename)\r
+       if not node then return nil end\r
+       local radius = math.max(tonumber(radius1), tonumber(radius2))\r
+       return math.ceil(math.pi * (radius ^ 2) * tonumber(length))\r
+end\r
 \r
-               local found, _, axis, length, radius, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+([^%s]+)$")\r
+minetest.register_chatcommand("/hollowcylinder", {\r
+       params = "x/y/z/? <length> <radius1> [radius2] <node>",\r
+       description = "Add hollow cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length>, base radius <radius1> (and top radius [radius2]), composed of <node>",\r
+       privs = {worldedit=true},\r
+       func = safe_region(function(name, param)\r
+               -- two radii\r
+               local found, _, axis, length, radius1, radius2, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(%d+)%s+(.+)$")\r
                if found == nil then\r
-                       minetest.chat_send_player(name, "Invalid usage: " .. param)\r
-                       return\r
+                       -- single radius\r
+                       found, _, axis, length, radius1, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$")\r
+                       radius2 = radius1\r
                end\r
+               length = tonumber(length)\r
                if axis == "?" then\r
                        axis, sign = worldedit.player_axis(name)\r
                        length = length * sign\r
                end\r
-               if not worldedit.node_is_valid(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
+               local node = get_node(name, nodename)\r
+               local count = worldedit.cylinder(worldedit.pos1[name], axis, length, tonumber(radius1), tonumber(radius2), node, true)\r
+               worldedit.player_notify(name, count .. " nodes added")\r
+       end, check_cylinder),\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
+       params = "x/y/z/? <length> <radius1> [radius2] <node>",\r
+       description = "Add cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length>, base radius <radius1> (and top radius [radius2]), 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
+       func = safe_region(function(name, param)\r
+               -- two radii\r
+               local found, _, axis, length, radius1, radius2, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(%d+)%s+(.+)$")\r
                if found == nil then\r
-                       minetest.chat_send_player(name, "Invalid usage: " .. param)\r
-                       return\r
+                       -- single radius\r
+                       found, _, axis, length, radius1, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$")\r
+                       radius2 = radius1\r
                end\r
+               length = tonumber(length)\r
                if axis == "?" then\r
                        axis, sign = worldedit.player_axis(name)\r
                        length = length * sign\r
                end\r
-               if not worldedit.node_is_valid(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
+               local node = get_node(name, nodename)\r
+               local count = worldedit.cylinder(worldedit.pos1[name], axis, length, tonumber(radius1), tonumber(radius2), node)\r
+               worldedit.player_notify(name, count .. " nodes added")\r
+       end, check_cylinder),\r
 })\r
 \r
-minetest.register_chatcommand("/pyramid", {\r
-       params = "<height> <node>",\r
-       description = "Add pyramid at WorldEdit position 1 with height <height>, composed of <node>",\r
+local check_pyramid = function(name, param)\r
+       if worldedit.pos1[name] == nil then\r
+               worldedit.player_notify(name, "no position 1 selected")\r
+               return nil\r
+       end\r
+       local found, _, axis, height, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(.+)$")\r
+       if found == nil then\r
+               worldedit.player_notify(name, "invalid usage: " .. param)\r
+               return nil\r
+       end\r
+       local node = get_node(name, nodename)\r
+       if not node then return nil end\r
+       height = tonumber(height)\r
+       return math.ceil(((height * 2 + 1) ^ 2) * height / 3)\r
+end\r
+     \r
+minetest.register_chatcommand("/hollowpyramid", {\r
+       params = "x/y/z/? <height> <node>",\r
+       description = "Add hollow pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height <height>, 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
+       func = safe_region(function(name, param)\r
+               local found, _, axis, height, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(.+)$")\r
+               height = tonumber(height)\r
+               if axis == "?" then\r
+                       axis, sign = worldedit.player_axis(name)\r
+                       height = height * sign\r
                end\r
+               local node = get_node(name, nodename)\r
+               local count = worldedit.pyramid(worldedit.pos1[name], axis, height, node, true)\r
+               worldedit.player_notify(name, count .. " nodes added")\r
+       end, check_pyramid),\r
+})\r
 \r
-               local found, _, size, 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(nodename) then\r
-                       minetest.chat_send_player(name, "Invalid node name: " .. param)\r
-                       return\r
+minetest.register_chatcommand("/pyramid", {\r
+       params = "x/y/z/? <height> <node>",\r
+       description = "Add pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height <height>, composed of <node>",\r
+       privs = {worldedit=true},\r
+       func = safe_region(function(name, param)\r
+               local found, _, axis, height, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(.+)$")\r
+               height = tonumber(height)\r
+               if axis == "?" then\r
+                       axis, sign = worldedit.player_axis(name)\r
+                       height = height * sign\r
                end\r
-\r
-               local count = worldedit.pyramid(pos, tonumber(size), nodename)\r
-               minetest.chat_send_player(name, count .. " nodes added")\r
-       end,\r
+               local node = get_node(name, nodename)\r
+               local count = worldedit.pyramid(worldedit.pos1[name], axis, height, node)\r
+               worldedit.player_notify(name, count .. " nodes added")\r
+       end, check_pyramid),\r
 })\r
 \r
 minetest.register_chatcommand("/spiral", {\r
-       params = "<width> <height> <space> <node>",\r
-       description = "Add spiral at WorldEdit position 1 with width <width>, height <height>, space between walls <space>, composed of <node>",\r
+       params = "<length> <height> <space> <node>",\r
+       description = "Add spiral centered at WorldEdit position 1 with side length <length>, height <height>, space between walls <space>, 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
+       func = safe_region(function(name, param)\r
+               local found, _, length, height, space, nodename = param:find("^(%d+)%s+(%d+)%s+(%d+)%s+(.+)$")\r
+               local node = get_node(name, nodename)\r
+               local count = worldedit.spiral(worldedit.pos1[name], tonumber(length), tonumber(height), tonumber(space), node)\r
+               worldedit.player_notify(name, count .. " nodes added")\r
+       end,\r
+       function(name, param)\r
+               if worldedit.pos1[name] == nil then\r
+                       worldedit.player_notify(name, "no position 1 selected")\r
+                       return nil\r
                end\r
-\r
-               local found, _, width, height, space, nodename = param:find("(%d+)%s+(%d+)%s+(%d+)%s+([^%s]+)$")\r
+               local found, _, length, height, space, nodename = param:find("^(%d+)%s+(%d+)%s+(%d+)%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(nodename) then\r
-                       minetest.chat_send_player(name, "Invalid node name: " .. param)\r
-                       return\r
+                       worldedit.player_notify(name, "invalid usage: " .. param)\r
+                       return nil\r
                end\r
-\r
-               local count = worldedit.spiral(pos, tonumber(width), tonumber(height), tonumber(space), nodename)\r
-               minetest.chat_send_player(name, count .. " nodes changed")\r
-       end,\r
+               local node = get_node(name, nodename)\r
+               if not node then return nil end\r
+               return 1 -- TODO: return an useful value\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
        privs = {worldedit=true},\r
-       func = function(name, param)\r
-               local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
-               if pos1 == nil or pos2 == nil then\r
-                       minetest.chat_send_player(name, "No WorldEdit region selected")\r
-                       return\r
-               end\r
-\r
+       func = safe_region(function(name, param)\r
                local found, _, axis, amount = param:find("^([xyz%?])%s+([+-]?%d+)$")\r
                if found == nil then\r
-                       minetest.chat_send_player(name, "Invalid usage: " .. param)\r
+                       worldedit.player_notify(name, "invalid usage: " .. param)\r
                        return\r
                end\r
+               amount = tonumber(amount)\r
                if axis == "?" then\r
                        axis, sign = worldedit.player_axis(name)\r
                        amount = amount * sign\r
                end\r
 \r
-               local count = worldedit.copy(pos1, pos2, axis, tonumber(amount))\r
-               minetest.chat_send_player(name, count .. " nodes copied")\r
+               local count = worldedit.copy(worldedit.pos1[name], worldedit.pos2[name], axis, amount)\r
+               worldedit.player_notify(name, count .. " nodes copied")\r
        end,\r
+       function(name, param)\r
+               local volume = check_region(name, param)\r
+               return volume and volume * 2 or volume\r
+       end),\r
 })\r
 \r
 minetest.register_chatcommand("/move", {\r
        params = "x/y/z/? <amount>",\r
        description = "Move the current WorldEdit region along the x/y/z/? axis by <amount> nodes",\r
        privs = {worldedit=true},\r
-       func = function(name, param)\r
+       func = safe_region(function(name, param)\r
                local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
-               if pos1 == nil or pos2 == nil then\r
-                       minetest.chat_send_player(name, "No WorldEdit region selected")\r
-                       return\r
-               end\r
-\r
                local found, _, axis, amount = param:find("^([xyz%?])%s+([+-]?%d+)$")\r
                if found == nil then\r
-                       minetest.chat_send_player(name, "Invalid usage: " .. param)\r
+                       worldedit.player_notify(name, "invalid usage: " .. param)\r
                        return\r
                end\r
+               amount = tonumber(amount)\r
                if axis == "?" then\r
                        axis, sign = worldedit.player_axis(name)\r
                        amount = amount * sign\r
                end\r
 \r
-               local count = worldedit.move(pos1, pos2, axis, tonumber(amount))\r
+               local count = worldedit.move(pos1, pos2, axis, amount)\r
 \r
                pos1[axis] = pos1[axis] + amount\r
                pos2[axis] = pos2[axis] + amount\r
                worldedit.mark_pos1(name)\r
                worldedit.mark_pos2(name)\r
-\r
-               minetest.chat_send_player(name, count .. " nodes moved")\r
-       end,\r
+               worldedit.player_notify(name, count .. " nodes moved")\r
+       end, check_region),\r
 })\r
 \r
 minetest.register_chatcommand("/stack", {\r
        params = "x/y/z/? <count>",\r
        description = "Stack the current WorldEdit region along the x/y/z/? axis <count> times",\r
        privs = {worldedit=true},\r
-       func = function(name, param)\r
-               local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
-               if pos1 == nil or pos2 == nil then\r
-                       minetest.chat_send_player(name, "No WorldEdit region selected")\r
-                       return\r
-               end\r
-\r
-               local found, _, axis, count = param:find("^([xyz%?])%s+([+-]?%d+)$")\r
-               if found == nil then\r
-                       minetest.chat_send_player(name, "Invalid usage: " .. param)\r
-                       return\r
-               end\r
+       func = safe_region(function(name, param)\r
+               local found, _, axis, repetitions = param:find("^([xyz%?])%s+([+-]?%d+)$")\r
+               repetitions = tonumber(repetitions)\r
                if axis == "?" then\r
                        axis, sign = worldedit.player_axis(name)\r
-                       count = count * sign\r
+                       repetitions = repetitions * sign\r
                end\r
-\r
-               local count = worldedit.stack(pos1, pos2, axis, tonumber(count))\r
-               minetest.chat_send_player(name, count .. " nodes stacked")\r
+               local count = worldedit.stack(worldedit.pos1[name], worldedit.pos2[name], axis, repetitions)\r
+               worldedit.player_notify(name, count .. " nodes stacked")\r
        end,\r
+       function(name, param)\r
+               local found, _, axis, repetitions = param:find("^([xyz%?])%s+([+-]?%d+)$")\r
+               if found == nil then\r
+                       worldedit.player_notify(name, "invalid usage: " .. param)\r
+                       return\r
+               end\r
+               local count = check_region(name, param)\r
+               if count then return (tonumber(repetitions) + 1) * count end\r
+               return nil\r
+       end),\r
 })\r
 \r
-minetest.register_chatcommand("/transpose", {\r
-       params = "x/y/z/? x/y/z/?",\r
-       description = "Transpose the current WorldEdit region along the x/y/z/? and x/y/z/? axes",\r
+minetest.register_chatcommand("/stack2", {\r
+       params = "<count> <x> <y> <z>",\r
+       description = "Stack the current WorldEdit region <count> times by offset <x>, <y>, <z>",\r
        privs = {worldedit=true},\r
        func = function(name, param)\r
                local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
                if pos1 == nil or pos2 == nil then\r
-                       minetest.chat_send_player(name, "No WorldEdit region selected")\r
+                       worldedit.player_notify(name, "Select a position first!")\r
                        return\r
                end\r
-\r
-               local found, _, axis1, axis2 = param:find("^([xyz%?])%s+([xyz%?])$")\r
-               if found == nil then\r
-                       minetest.chat_send_player(name, "Invalid usage: " .. param)\r
+               local repetitions, incs = param:match("(%d+)%s*(.+)")\r
+               if repetitions == nil then\r
+                       worldedit.player_notify(name, "invalid count: " .. param)\r
                        return\r
                end\r
-               if axis1 == "?" then\r
-                       axis1 = worldedit.player_axis(name)\r
+               repetitions = tonumber(repetitions)\r
+\r
+               local x, y, z = incs:match("([+-]?%d+) ([+-]?%d+) ([+-]?%d+)")\r
+               if x == nil then\r
+                       worldedit.player_notify(name, "invalid increments: " .. param)\r
+                       return\r
                end\r
-               if axis2 == "?" then\r
-                       axis2 = worldedit.player_axis(name)\r
+               x, y, z = tonumber(x), tonumber(y), tonumber(z)\r
+\r
+               local count = worldedit.volume(pos1, pos2) * repetitions\r
+\r
+               return safe_region(function()\r
+                       worldedit.stack2(pos1, pos2, {x=x, y=y, z=z}, repetitions,\r
+                               function() worldedit.player_notify(name, count .. " nodes stacked") end)\r
+               end, function()\r
+                       return count\r
+               end)(name,param) -- more hax --wip: clean this up a little bit\r
+       end\r
+})\r
+\r
+\r
+minetest.register_chatcommand("/stretch", {\r
+       params = "<stretchx> <stretchy> <stretchz>",\r
+       description = "Scale the current WorldEdit positions and region by a factor of <stretchx>, <stretchy>, <stretchz> along the X, Y, and Z axes, repectively, with position 1 as the origin",\r
+       privs = {worldedit=true},\r
+       func = safe_region(function(name, param)\r
+               local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
+               local found, _, stretchx, stretchy, stretchz = param:find("^(%d+)%s+(%d+)%s+(%d+)$")\r
+               stretchx, stretchy, stretchz = tonumber(stretchx), tonumber(stretchy), tonumber(stretchz)\r
+               local count, pos1, pos2 = worldedit.stretch(pos1, pos2, stretchx, stretchy, stretchz)\r
+\r
+               --reset markers to scaled positions\r
+               worldedit.pos1[name] = pos1\r
+               worldedit.pos2[name] = pos2\r
+               worldedit.mark_pos1(name)\r
+               worldedit.mark_pos2(name)\r
+\r
+               worldedit.player_notify(name, count .. " nodes stretched")\r
+       end,\r
+       function(name, param)\r
+               local found, _, stretchx, stretchy, stretchz = param:find("^(%d+)%s+(%d+)%s+(%d+)$")\r
+               if found == nil then\r
+                       worldedit.player_notify(name, "invalid usage: " .. param)\r
+                       return nil\r
                end\r
-               if axis1 == axis2 then\r
-                       minetest.chat_send_player(name, "Invalid usage: axes are the same")\r
-                       return\r
+               stretchx, stretchy, stretchz = tonumber(stretchx), tonumber(stretchy), tonumber(stretchz)\r
+               if stretchx == 0 or stretchy == 0 or stretchz == 0 then\r
+                       worldedit.player_notify(name, "invalid scaling factors: " .. param)\r
                end\r
+               local count = check_region(name, param)\r
+               if count then return tonumber(stretchx) * tonumber(stretchy) * tonumber(stretchz) * count end\r
+               return nil\r
+       end),\r
+})\r
 \r
+minetest.register_chatcommand("/transpose", {\r
+       params = "x/y/z/? x/y/z/?",\r
+       description = "Transpose the current WorldEdit region along the x/y/z/? and x/y/z/? axes",\r
+       privs = {worldedit=true},\r
+       func = safe_region(function(name, param)\r
+               local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
+               local found, _, axis1, axis2 = param:find("^([xyz%?])%s+([xyz%?])$")\r
+               if axis1 == "?" then axis1 = worldedit.player_axis(name) end\r
+               if axis2 == "?" then axis2 = worldedit.player_axis(name) end\r
                local count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2)\r
 \r
                --reset markers to transposed positions\r
@@ -510,58 +915,48 @@ minetest.register_chatcommand("/transpose", {
                worldedit.mark_pos1(name)\r
                worldedit.mark_pos2(name)\r
 \r
-               minetest.chat_send_player(name, count .. " nodes transposed")\r
+               worldedit.player_notify(name, count .. " nodes transposed")\r
        end,\r
+       function(name, param)\r
+               local found, _, axis1, axis2 = param:find("^([xyz%?])%s+([xyz%?])$")\r
+               if found == nil then\r
+                       worldedit.player_notify(name, "invalid usage: " .. param)\r
+                       return nil\r
+               end\r
+               if axis1 == axis2 then\r
+                       worldedit.player_notify(name, "invalid usage: axes must be different")\r
+                       return nil\r
+               end\r
+               return check_region(name, param)\r
+       end),\r
 })\r
 \r
 minetest.register_chatcommand("/flip", {\r
        params = "x/y/z/?",\r
        description = "Flip the current WorldEdit region along the x/y/z/? axis",\r
        privs = {worldedit=true},\r
-       func = function(name, param)\r
-               local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
-               if pos1 == nil or pos2 == nil then\r
-                       minetest.chat_send_player(name, "No WorldEdit region selected")\r
-                       return\r
-               end\r
-\r
-               if param == "?" then\r
-                       param = worldedit.player_axis(name)\r
-               end\r
-               if param ~= "x" and param ~= "y" and param ~= "z" then\r
-                       minetest.chat_send_player(name, "Invalid usage: " .. param)\r
-                       return\r
-               end\r
-\r
-               local count = worldedit.flip(pos1, pos2, param)\r
-               minetest.chat_send_player(name, count .. " nodes flipped")\r
+       func = safe_region(function(name, param)\r
+               if param == "?" then param = worldedit.player_axis(name) end\r
+               local count = worldedit.flip(worldedit.pos1[name], worldedit.pos2[name], param)\r
+               worldedit.player_notify(name, count .. " nodes flipped")\r
        end,\r
+       function(name, param)\r
+               if param ~= "x" and param ~= "y" and param ~= "z" and param ~= "?" then\r
+                       worldedit.player_notify(name, "invalid usage: " .. param)\r
+                       return nil\r
+               end\r
+               return check_region(name, param)\r
+       end),\r
 })\r
 \r
 minetest.register_chatcommand("/rotate", {\r
        params = "<axis> <angle>",\r
        description = "Rotate the current WorldEdit region around the axis <axis> by angle <angle> (90 degree increment)",\r
        privs = {worldedit=true},\r
-       func = function(name, param)\r
+       func = safe_region(function(name, param)\r
                local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
-               if pos1 == nil or pos2 == nil then\r
-                       minetest.chat_send_player(name, "No WorldEdit region selected")\r
-                       return\r
-               end\r
-\r
                local found, _, axis, angle = param:find("^([xyz%?])%s+([+-]?%d+)$")\r
-               if found == nil then\r
-                       minetest.chat_send_player(name, "Invalid usage: " .. param)\r
-                       return\r
-               end\r
-               if axis == "?" then\r
-                       axis = worldedit.player_axis(name)\r
-               end\r
-               if angle % 90 ~= 0 then\r
-                       minetest.chat_send_player(name, "Invalid usage: angle must be multiple of 90")\r
-                       return\r
-               end\r
-\r
+               if axis == "?" then axis = worldedit.player_axis(name) end\r
                local count, pos1, pos2 = worldedit.rotate(pos1, pos2, axis, angle)\r
 \r
                --reset markers to rotated positions\r
@@ -570,159 +965,153 @@ minetest.register_chatcommand("/rotate", {
                worldedit.mark_pos1(name)\r
                worldedit.mark_pos2(name)\r
 \r
-               minetest.chat_send_player(name, count .. " nodes rotated")\r
+               worldedit.player_notify(name, count .. " nodes rotated")\r
        end,\r
+       function(name, param)\r
+               local found, _, axis, angle = param:find("^([xyz%?])%s+([+-]?%d+)$")\r
+               if found == nil then\r
+                       worldedit.player_notify(name, "invalid usage: " .. param)\r
+                       return nil\r
+               end\r
+               if angle % 90 ~= 0 then\r
+                       worldedit.player_notify(name, "invalid usage: angle must be multiple of 90")\r
+                       return nil\r
+               end\r
+               return check_region(name, param)\r
+       end),\r
 })\r
 \r
 minetest.register_chatcommand("/orient", {\r
        params = "<angle>",\r
        description = "Rotate oriented nodes in the current WorldEdit region around the Y axis by angle <angle> (90 degree increment)",\r
        privs = {worldedit=true},\r
-       func = function(name, param)\r
-               local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
-               if pos1 == nil or pos2 == nil then\r
-                       minetest.chat_send_player(name, "No WorldEdit region selected")\r
-                       return\r
-               end\r
-\r
+       func = safe_region(function(name, param)\r
+               local found, _, angle = param:find("^([+-]?%d+)$")\r
+               local count = worldedit.orient(worldedit.pos1[name], worldedit.pos2[name], angle)\r
+               worldedit.player_notify(name, count .. " nodes oriented")\r
+       end,\r
+       function(name, param)\r
                local found, _, angle = param:find("^([+-]?%d+)$")\r
                if found == nil then\r
-                       minetest.chat_send_player(name, "Invalid usage: " .. param)\r
-                       return\r
+                       worldedit.player_notify(name, "invalid usage: " .. param)\r
+                       return nil\r
                end\r
                if angle % 90 ~= 0 then\r
-                       minetest.chat_send_player(name, "Invalid usage: angle must be multiple of 90")\r
-                       return\r
+                       worldedit.player_notify(name, "invalid usage: angle must be multiple of 90")\r
+                       return nil\r
                end\r
-\r
-               local count = worldedit.orient(pos1, pos2, angle)\r
-\r
-               minetest.chat_send_player(name, count .. " nodes oriented")\r
-       end,\r
+               return check_region(name, param)\r
+       end),\r
 })\r
 \r
 minetest.register_chatcommand("/fixlight", {\r
        params = "",\r
        description = "Fix the lighting in the current WorldEdit region",\r
        privs = {worldedit=true},\r
-       func = function(name, param)\r
-               local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
-               if pos1 == nil or pos2 == nil then\r
-                       minetest.chat_send_player(name, "No WorldEdit region selected")\r
-                       return\r
-               end\r
+       func = safe_region(function(name, param)\r
+               local count = worldedit.fixlight(worldedit.pos1[name], worldedit.pos2[name])\r
+               worldedit.player_notify(name, count .. " nodes updated")\r
+       end),\r
+})\r
 \r
-               local count = worldedit.fixlight(pos1, pos2)\r
-               minetest.chat_send_player(name, count .. " nodes updated")\r
-       end,\r
+minetest.register_chatcommand("/drain", {\r
+       params = "",\r
+       description = "Remove any fluid node within the current WorldEdit region",\r
+       privs = {worldedit=true},\r
+       func = safe_region(function(name, param)\r
+               -- TODO: make an API function for this\r
+               local count = 0\r
+               local pos1, pos2 = worldedit.sort_pos(worldedit.pos1[name], worldedit.pos2[name])\r
+               for x = pos1.x, pos2.x do\r
+               for y = pos1.y, pos2.y do\r
+               for z = pos1.z, pos2.z do\r
+                       local n = minetest.get_node({x=x, y=y, z=z}).name\r
+                       local d = minetest.registered_nodes[n]\r
+                       if d ~= nil and (d["drawtype"] == "liquid" or d["drawtype"] == "flowingliquid") then\r
+                               minetest.remove_node({x=x, y=y, z=z})\r
+                               count = count + 1\r
+                       end\r
+               end\r
+               end\r
+               end\r
+               worldedit.player_notify(name, count .. " nodes updated")\r
+       end),\r
 })\r
 \r
 minetest.register_chatcommand("/hide", {\r
        params = "",\r
        description = "Hide all nodes in the current WorldEdit region non-destructively",\r
        privs = {worldedit=true},\r
-       func = function(name, param)\r
-               local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
-               if pos1 == nil or pos2 == nil then\r
-                       minetest.chat_send_player(name, "No WorldEdit region selected")\r
-                       return\r
-               end\r
-\r
-               local count = worldedit.hide(pos1, pos2)\r
-               minetest.chat_send_player(name, count .. " nodes hidden")\r
-       end,\r
+       func = safe_region(function(name, param)\r
+               local count = worldedit.hide(worldedit.pos1[name], worldedit.pos2[name])\r
+               worldedit.player_notify(name, count .. " nodes hidden")\r
+       end),\r
 })\r
 \r
 minetest.register_chatcommand("/suppress", {\r
        params = "<node>",\r
        description = "Suppress all <node> in the current WorldEdit region non-destructively",\r
        privs = {worldedit=true},\r
-       func = function(name, param)\r
-               local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
-               if pos1 == nil or pos2 == nil then\r
-                       minetest.chat_send_player(name, "No WorldEdit region selected")\r
-                       return\r
-               end\r
-\r
-               if param == "" or not worldedit.node_is_valid(param) then\r
-                       minetest.chat_send_player(name, "Invalid node name: " .. param)\r
-                       return\r
-               end\r
-\r
-               local count = worldedit.suppress(pos1, pos2, param)\r
-               minetest.chat_send_player(name, count .. " nodes suppressed")\r
-       end,\r
+       func = safe_region(function(name, param)\r
+               local node = get_node(name, param)\r
+               local count = worldedit.suppress(worldedit.pos1[name], worldedit.pos2[name], node)\r
+               worldedit.player_notify(name, count .. " nodes suppressed")\r
+       end, check_region),\r
 })\r
 \r
 minetest.register_chatcommand("/highlight", {\r
        params = "<node>",\r
        description = "Highlight <node> in the current WorldEdit region by hiding everything else non-destructively",\r
        privs = {worldedit=true},\r
-       func = function(name, param)\r
-               local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
-               if pos1 == nil or pos2 == nil then\r
-                       minetest.chat_send_player(name, "No WorldEdit region selected")\r
-                       return\r
-               end\r
-\r
-               if param == "" or not worldedit.node_is_valid(param) then\r
-                       minetest.chat_send_player(name, "Invalid node name: " .. param)\r
-                       return\r
-               end\r
-\r
-               local count = worldedit.highlight(pos1, pos2, param)\r
-               minetest.chat_send_player(name, count .. " nodes highlighted")\r
-       end,\r
+       func = safe_region(function(name, param)\r
+               local node = get_node(name, param)\r
+               local count = worldedit.highlight(worldedit.pos1[name], worldedit.pos2[name], node)\r
+               worldedit.player_notify(name, count .. " nodes highlighted")\r
+       end, check_region),\r
 })\r
 \r
 minetest.register_chatcommand("/restore", {\r
        params = "",\r
        description = "Restores nodes hidden with WorldEdit in the current WorldEdit region",\r
        privs = {worldedit=true},\r
-       func = function(name, param)\r
-               local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
-               if pos1 == nil or pos2 == nil then\r
-                       minetest.chat_send_player(name, "No WorldEdit region selected")\r
-                       return\r
-               end\r
-\r
-               local count = worldedit.restore(pos1, pos2)\r
-               minetest.chat_send_player(name, count .. " nodes restored")\r
-       end,\r
+       func = safe_region(function(name, param)\r
+               local count = worldedit.restore(worldedit.pos1[name], worldedit.pos2[name])\r
+               worldedit.player_notify(name, count .. " nodes restored")\r
+       end),\r
 })\r
 \r
 minetest.register_chatcommand("/save", {\r
        params = "<file>",\r
        description = "Save the current WorldEdit region to \"(world folder)/schems/<file>.we\"",\r
        privs = {worldedit=true},\r
-       func = function(name, param)\r
-               local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
-               if pos1 == nil or pos2 == nil then\r
-                       minetest.chat_send_player(name, "No WorldEdit region selected")\r
+       func = safe_region(function(name, param)\r
+               if param == "" then\r
+                       worldedit.player_notify(name, "invalid usage: " .. param)\r
                        return\r
                end\r
-\r
-               if param == "" then\r
-                       minetest.chat_send_player(name, "Invalid usage: " .. param)\r
+               if not check_filename(param) then\r
+                       worldedit.player_notify(name, "Disallowed file name: " .. param)\r
                        return\r
                end\r
-\r
-               local result, count = worldedit.serialize(pos1, pos2)\r
+               local result, count = worldedit.serialize(worldedit.pos1[name],\r
+                               worldedit.pos2[name])\r
 \r
                local path = minetest.get_worldpath() .. "/schems"\r
+               -- Create directory if it does not already exist\r
+               mkdir(path)\r
+\r
                local filename = path .. "/" .. param .. ".we"\r
-               os.execute("mkdir \"" .. path .. "\"") --create directory if it does not already exist\r
                local file, err = io.open(filename, "wb")\r
                if err ~= nil then\r
-                       minetest.chat_send_player(name, "Could not save file to \"" .. filename .. "\"")\r
+                       worldedit.player_notify(name, "Could not save file to \"" .. filename .. "\"")\r
                        return\r
                end\r
                file:write(result)\r
                file:flush()\r
                file:close()\r
 \r
-               minetest.chat_send_player(name, count .. " nodes saved")\r
-       end,\r
+               worldedit.player_notify(name, count .. " nodes saved")\r
+       end),\r
 })\r
 \r
 minetest.register_chatcommand("/allocate", {\r
@@ -730,38 +1119,42 @@ minetest.register_chatcommand("/allocate", {
        description = "Set the region defined by nodes from \"(world folder)/schems/<file>.we\" as the current WorldEdit region",\r
        privs = {worldedit=true},\r
        func = function(name, param)\r
-               local pos1 = worldedit.pos1[name]\r
-               if pos1 == nil then\r
-                       minetest.chat_send_player(name, "No WorldEdit region selected")\r
-                       return\r
-               end\r
+               local pos = get_position(name)\r
+               if pos == nil then return end\r
 \r
                if param == "" then\r
-                       minetest.chat_send_player(name, "Invalid usage: " .. param)\r
+                       worldedit.player_notify(name, "invalid usage: " .. param)\r
+                       return\r
+               end\r
+               if not check_filename(param) then\r
+                       worldedit.player_notify(name, "Disallowed file name: " .. param)\r
                        return\r
                end\r
 \r
                local filename = minetest.get_worldpath() .. "/schems/" .. param .. ".we"\r
                local file, err = io.open(filename, "rb")\r
                if err ~= nil then\r
-                       minetest.chat_send_player(name, "Could not open file \"" .. filename .. "\"")\r
+                       worldedit.player_notify(name, "could not open file \"" .. filename .. "\"")\r
                        return\r
                end\r
                local value = file:read("*a")\r
                file:close()\r
 \r
-               if worldedit.valueversion(value) == 0 then --unknown version\r
-                       minetest.chat_send_player(name, "Invalid file: file is invalid or created with newer version of WorldEdit")\r
+               local version = worldedit.read_header(value)\r
+               if version == 0 then\r
+                       worldedit.player_notify(name, "File is invalid!")\r
                        return\r
+               elseif version > worldedit.LATEST_SERIALIZATION_VERSION then\r
+                       worldedit.player_notify(name, "File was created with newer version of WorldEdit!")\r
                end\r
-               local nodepos1, nodepos2, count = worldedit.allocate(pos1, value)\r
+               local nodepos1, nodepos2, count = worldedit.allocate(pos, value)\r
 \r
                worldedit.pos1[name] = nodepos1\r
                worldedit.mark_pos1(name)\r
                worldedit.pos2[name] = nodepos2\r
                worldedit.mark_pos2(name)\r
 \r
-               minetest.chat_send_player(name, count .. " nodes allocated")\r
+               worldedit.player_notify(name, count .. " nodes allocated")\r
        end,\r
 })\r
 \r
@@ -770,14 +1163,15 @@ minetest.register_chatcommand("/load", {
        description = "Load nodes from \"(world folder)/schems/<file>[.we[m]]\" with position 1 of the current WorldEdit region as the origin",\r
        privs = {worldedit=true},\r
        func = function(name, param)\r
-               local pos1 = worldedit.pos1[name]\r
-               if pos1 == nil then\r
-                       minetest.chat_send_player(name, "No WorldEdit region selected")\r
-                       return\r
-               end\r
+               local pos = get_position(name)\r
+               if pos == nil then return end\r
 \r
                if param == "" then\r
-                       minetest.chat_send_player(name, "Invalid usage: " .. param)\r
+                       worldedit.player_notify(name, "invalid usage: " .. param)\r
+                       return\r
+               end\r
+               if not string.find(param, "^[%w \t.,+-_=!@#$%%^&*()%[%]{};'\"]+$") then\r
+                       worldedit.player_notify(name, "invalid file name: " .. param)\r
                        return\r
                end\r
 \r
@@ -795,19 +1189,24 @@ minetest.register_chatcommand("/load", {
                        end\r
                end\r
                if err then\r
-                       minetest.chat_send_player(name, "Could not open file \"" .. param .. "\"")\r
+                       worldedit.player_notify(name, "could not open file \"" .. param .. "\"")\r
                        return\r
                end\r
                local value = file:read("*a")\r
                file:close()\r
 \r
-               if worldedit.valueversion(value) == 0 then --unknown version\r
-                       minetest.chat_send_player(name, "Invalid file: file is invalid or created with newer version of WorldEdit")\r
+               local version = worldedit.read_header(value)\r
+               if version == 0 then\r
+                       worldedit.player_notify(name, "File is invalid!")\r
+                       return\r
+               elseif version > worldedit.LATEST_SERIALIZATION_VERSION then\r
+                       worldedit.player_notify(name, "File was created with newer version of WorldEdit!")\r
                        return\r
                end\r
-               local count = worldedit.deserialize(pos1, value)\r
 \r
-               minetest.chat_send_player(name, count .. " nodes loaded")\r
+               local count = worldedit.deserialize(pos, value)\r
+\r
+               worldedit.player_notify(name, count .. " nodes loaded")\r
        end,\r
 })\r
 \r
@@ -818,9 +1217,11 @@ minetest.register_chatcommand("/lua", {
        func = function(name, param)\r
                local err = worldedit.lua(param)\r
                if err then\r
-                       minetest.chat_send_player(name, "Code error: " .. err)\r
+                       worldedit.player_notify(name, "code error: " .. err)\r
+                       minetest.log("action", name.." tried to execute "..param)\r
                else\r
-                       minetest.chat_send_player(name, "Code successfully executed")\r
+                       worldedit.player_notify(name, "code successfully executed", false)\r
+                       minetest.log("action", name.." executed "..param)\r
                end\r
        end,\r
 })\r
@@ -829,18 +1230,122 @@ minetest.register_chatcommand("/luatransform", {
        params = "<code>",\r
        description = "Executes <code> as a Lua chunk in the global namespace with the variable pos available, for each node in the current WorldEdit region",\r
        privs = {worldedit=true, server=true},\r
+       func = safe_region(function(name, param)\r
+               local err = worldedit.luatransform(worldedit.pos1[name], worldedit.pos2[name], param)\r
+               if err then\r
+                       worldedit.player_notify(name, "code error: " .. err, false)\r
+                       minetest.log("action", name.." tried to execute luatransform "..param)\r
+               else\r
+                       worldedit.player_notify(name, "code successfully executed", false)\r
+                       minetest.log("action", name.." executed luatransform "..param)\r
+               end\r
+       end),\r
+})\r
+\r
+minetest.register_chatcommand("/mtschemcreate", {\r
+       params = "<file>",\r
+       description = "Save the current WorldEdit region using the Minetest "..\r
+               "Schematic format to \"(world folder)/schems/<filename>.mts\"",\r
+       privs = {worldedit=true},\r
+       func = safe_region(function(name, param)\r
+               if param == nil then\r
+                       worldedit.player_notify(name, "No filename specified")\r
+                       return\r
+               end\r
+               if not check_filename(param) then\r
+                       worldedit.player_notify(name, "Disallowed file name: " .. param)\r
+                       return\r
+               end\r
+\r
+               local path = minetest.get_worldpath() .. "/schems"\r
+               -- Create directory if it does not already exist\r
+               mkdir(path)\r
+\r
+               local filename = path .. "/" .. param .. ".mts"\r
+               local ret = minetest.create_schematic(worldedit.pos1[name],\r
+                               worldedit.pos2[name], worldedit.prob_list[name],\r
+                               filename)\r
+               if ret == nil then\r
+                       worldedit.player_notify(name, "Failed to create Minetest schematic", false)\r
+               else\r
+                       worldedit.player_notify(name, "Saved Minetest schematic to " .. param, false)\r
+               end\r
+               worldedit.prob_list[name] = {}\r
+       end),\r
+})\r
+\r
+minetest.register_chatcommand("/mtschemplace", {\r
+       params = "<file>",\r
+       description = "Load nodes from \"(world folder)/schems/<file>.mts\" with position 1 of the current WorldEdit region as the origin",\r
+       privs = {worldedit=true},\r
        func = function(name, param)\r
-               local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
-               if pos1 == nil or pos2 == nil then\r
-                       minetest.chat_send_player(name, "No WorldEdit region selected")\r
+               if param == "" then\r
+                       worldedit.player_notify(name, "no filename specified")\r
+                       return\r
+               end\r
+               if not check_filename(param) then\r
+                       worldedit.player_notify(name, "Disallowed file name: " .. param)\r
                        return\r
                end\r
 \r
-               local err = worldedit.luatransform(pos1, pos2, param)\r
-               if err then\r
-                       minetest.chat_send_player(name, "Code error: " .. err)\r
+               local pos = get_position(name)\r
+               if pos == nil then return end\r
+\r
+               local path = minetest.get_worldpath() .. "/schems/" .. param .. ".mts"\r
+               if minetest.place_schematic(pos, path) == nil then\r
+                       worldedit.player_notify(name, "failed to place Minetest schematic", false)\r
+               else\r
+                       worldedit.player_notify(name, "placed Minetest schematic " .. param ..\r
+                               " at " .. minetest.pos_to_string(pos), false)\r
+               end\r
+       end,\r
+})\r
+\r
+minetest.register_chatcommand("/mtschemprob", {\r
+       params = "start/finish/get",\r
+       description = "Begins node probability entry for Minetest schematics, gets the nodes that have probabilities set, or ends node probability entry",\r
+       privs = {worldedit=true},\r
+       func = function(name, param)\r
+               if param == "start" then --start probability setting\r
+                       worldedit.set_pos[name] = "prob"\r
+                       worldedit.prob_list[name] = {}\r
+                       worldedit.player_notify(name, "select Minetest schematic probability values by punching nodes")\r
+               elseif param == "finish" then --finish probability setting\r
+                       worldedit.set_pos[name] = nil\r
+                       worldedit.player_notify(name, "finished Minetest schematic probability selection")\r
+               elseif param == "get" then --get all nodes that had probabilities set on them\r
+                       local text = ""\r
+                       local problist = worldedit.prob_list[name]\r
+                       if problist == nil then\r
+                               return\r
+                       end\r
+                       for k,v in pairs(problist) do\r
+                               local prob = math.floor(((v.prob / 256) * 100) * 100 + 0.5) / 100\r
+                               text = text .. minetest.pos_to_string(v.pos) .. ": " .. prob .. "% | "\r
+                       end\r
+                       worldedit.player_notify(name, "currently set node probabilities:")\r
+                       worldedit.player_notify(name, text)\r
                else\r
-                       minetest.chat_send_player(name, "Code successfully executed")\r
+                       worldedit.player_notify(name, "unknown subcommand: " .. param)\r
                end\r
        end,\r
-})
\ No newline at end of file
+})\r
+\r
+minetest.register_on_player_receive_fields(function(player, formname, fields)\r
+       if formname == "prob_val_enter" and not (fields.text == "" or fields.text == nil) then\r
+               local name = player:get_player_name()\r
+               local prob_entry = {pos=worldedit.prob_pos[name], prob=tonumber(fields.text)}\r
+               local index = table.getn(worldedit.prob_list[name]) + 1\r
+               worldedit.prob_list[name][index] = prob_entry\r
+       end\r
+end)\r
+\r
+minetest.register_chatcommand("/clearobjects", {\r
+       params = "",\r
+       description = "Clears all objects within the WorldEdit region",\r
+       privs = {worldedit=true},\r
+       func = safe_region(function(name, param)\r
+               local count = worldedit.clear_objects(worldedit.pos1[name], worldedit.pos2[name])\r
+               worldedit.player_notify(name, count .. " objects cleared")\r
+       end),\r
+})\r