+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