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
-worldedit.player_notify = function(name, message)\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
+-- 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 whether `nodename` is a valid node name, returning a boolean\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
- local fullname = ItemStack({name=nodename}):get_name() --resolve aliases of node names to full names\r
- if minetest.registered_nodes[fullname] then --directly found node name or alias of 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 key:find(":" .. nodename, 1, true) then --found in mod\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
+ nodename = nodename:lower() -- lowercase both for case insensitive comparison\r
for key, value in pairs(minetest.registered_nodes) do\r
- if value.description:lower() == nodename then --found in description\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
- return nil\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
-worldedit.player_axis = function(name)\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
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
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",\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" then\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
- worldedit.player_notify(name, "node inspection enabled")\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, "node inspection disabled")\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
- if minetest.check_player_privs(name, {worldedit=true}) then\r
- message = "inspector: " .. node.name .. " at " .. minetest.pos_to_string(pos) .. " (param1=" .. node.param1 .. ", param2=" .. node.param2 .. ")"\r
- else\r
- message = "inspector: worldedit privileges required"\r
- end\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
worldedit.mark_pos1(name)\r
worldedit.mark_pos2(name)\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
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
if pos1 == nil or pos2 == nil then\r
worldedit.player_notify(name, "no region selected")\r
- return\r
+ return nil\r
end\r
\r
local volume = worldedit.volume(pos1, pos2)\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
- worldedit.player_notify(name, "no region selected")\r
+ func = safe_region(function(name, param)\r
+ local node = get_node(name, param)\r
+ if not node then\r
+ worldedit.player_notify(name, "Could not identify node \"" .. param .. "\"")\r
return\r
end\r
\r
- local node = worldedit.normalize_nodename(param)\r
- if param == "" or not node then\r
- worldedit.player_notify(name, "invalid node name: " .. param)\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
- local count = worldedit.set(pos1, pos2, node)\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\r
+ worldedit.player_notify(name, "Could not identify node \"" .. name .. "\"")\r
+ return\r
+ end\r
+ nodes[#nodes + 1] = node\r
+ end\r
+\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,\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
- worldedit.player_notify(name, "no region selected")\r
- return\r
- end\r
-\r
- local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+(.+)$")\r
- if found == nil then\r
- worldedit.player_notify(name, "invalid usage: " .. param)\r
- return\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\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\r
- end\r
-\r
- local count = worldedit.replace(pos1, pos2, newsearchnode, newreplacenode)\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,\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
- worldedit.player_notify(name, "no 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+(.+)$")\r
- if found == nil then\r
- worldedit.player_notify(name, "invalid usage: " .. param)\r
- return\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\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\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
- worldedit.player_notify(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("/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 = 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 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
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 = function(name, param)\r
- local pos = worldedit.pos1[name]\r
- if pos == nil then\r
- worldedit.player_notify(name, "no region selected")\r
- return\r
- end\r
-\r
+ func = safe_region(function(name, param)\r
local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")\r
- if found == nil then\r
- worldedit.player_notify(name, "invalid usage: " .. param)\r
- return\r
- end\r
- local node = worldedit.normalize_nodename(nodename)\r
- if not node then\r
- worldedit.player_notify(name, "invalid node name: " .. nodename)\r
- return\r
- end\r
-\r
- local count = worldedit.hollow_sphere(pos, tonumber(radius), node)\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,\r
+ end, check_sphere),\r
})\r
\r
minetest.register_chatcommand("/sphere", {\r
params = "<radius> <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
- worldedit.player_notify(name, "no region selected")\r
- return\r
- end\r
-\r
+ func = safe_region(function(name, param)\r
local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$")\r
- if found == nil then\r
- worldedit.player_notify(name, "invalid usage: " .. param)\r
- return\r
- end\r
- local node = worldedit.normalize_nodename(nodename)\r
- if not node then\r
- worldedit.player_notify(name, "invalid node name: " .. nodename)\r
- return\r
- end\r
-\r
- local count = worldedit.sphere(pos, tonumber(radius), node)\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,\r
+ end, check_sphere),\r
})\r
\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
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 = function(name, param)\r
- local pos = worldedit.pos1[name]\r
- if pos == nil then\r
- worldedit.player_notify(name, "no region selected")\r
- return\r
- end\r
-\r
- local found, _, radius, nodename = param:find("^([+-]?%d+)%s+(.+)$")\r
- if found == nil then\r
- worldedit.player_notify(name, "invalid usage: " .. param)\r
- return\r
- end\r
- local node = worldedit.normalize_nodename(nodename)\r
- if not node then\r
- worldedit.player_notify(name, "invalid node name: " .. nodename)\r
- return\r
- end\r
-\r
- local count = worldedit.hollow_dome(pos, tonumber(radius), node)\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,\r
+ end, check_dome),\r
})\r
\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
- worldedit.player_notify(name, "no region selected")\r
- return\r
- end\r
-\r
- local found, _, radius, nodename = param:find("^([+-]?%d+)%s+(.+)$")\r
- if found == nil then\r
- worldedit.player_notify(name, "invalid usage: " .. param)\r
- return\r
- end\r
- local node = worldedit.normalize_nodename(nodename)\r
- if not node then\r
- worldedit.player_notify(name, "invalid node name: " .. nodename)\r
- return\r
- end\r
-\r
- local count = worldedit.dome(pos, tonumber(radius), node)\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,\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
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
+ 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 = function(name, param)\r
- local pos = worldedit.pos1[name]\r
- if pos == nil then\r
- worldedit.player_notify(name, "no region selected")\r
- return\r
- end\r
-\r
- local found, _, axis, length, radius, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%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
- worldedit.player_notify(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, radius = tonumber(length), tonumber(radius)\r
+ length = tonumber(length)\r
if axis == "?" then\r
axis, sign = worldedit.player_axis(name)\r
length = length * sign\r
end\r
- local node = worldedit.normalize_nodename(nodename)\r
- if not node then\r
- worldedit.player_notify(name, "invalid node name: " .. nodename)\r
- return\r
- end\r
-\r
- local count = worldedit.hollow_cylinder(pos, axis, length, radius, node)\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,\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
- worldedit.player_notify(name, "no region selected")\r
- return\r
- end\r
-\r
- local found, _, axis, length, radius, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%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
- worldedit.player_notify(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, radius = tonumber(length), tonumber(radius)\r
+ length = tonumber(length)\r
if axis == "?" then\r
axis, sign = worldedit.player_axis(name)\r
length = length * sign\r
end\r
- local node = worldedit.normalize_nodename(nodename)\r
- if not node then\r
- worldedit.player_notify(name, "invalid node name: " .. nodename)\r
- return\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
- local count = worldedit.cylinder(pos, axis, length, radius, 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 = 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,\r
+ end, check_pyramid),\r
})\r
\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 = function(name, param)\r
- local pos = worldedit.pos1[name]\r
- if pos == nil then\r
- worldedit.player_notify(name, "no region selected")\r
- return\r
- end\r
-\r
+ func = safe_region(function(name, param)\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\r
- end\r
height = tonumber(height)\r
if axis == "?" then\r
axis, sign = worldedit.player_axis(name)\r
height = height * sign\r
end\r
- local node = worldedit.normalize_nodename(nodename)\r
- if not node then\r
- worldedit.player_notify(name, "invalid node name: " .. nodename)\r
- return\r
- end\r
-\r
- local count = worldedit.pyramid(pos, axis, height, node)\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,\r
+ end, check_pyramid),\r
})\r
\r
minetest.register_chatcommand("/spiral", {\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
- worldedit.player_notify(name, "no 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, _, length, height, space, nodename = param:find("^(%d+)%s+(%d+)%s+(%d+)%s+(.+)$")\r
if found == nil then\r
worldedit.player_notify(name, "invalid usage: " .. param)\r
- return\r
+ return nil\r
end\r
- local node = worldedit.normalize_nodename(nodename)\r
- if not node then\r
- worldedit.player_notify(name, "invalid node name: " .. nodename)\r
- return\r
- end\r
-\r
- local count = worldedit.spiral(pos, tonumber(length), tonumber(height), tonumber(space), node)\r
- worldedit.player_notify(name, count .. " nodes added")\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
- worldedit.player_notify(name, "no 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
worldedit.player_notify(name, "invalid usage: " .. param)\r
amount = amount * sign\r
end\r
\r
- local count = worldedit.copy(pos1, pos2, axis, amount)\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
- worldedit.player_notify(name, "no region selected")\r
- return\r
- end\r
-\r
local found, _, axis, amount = param:find("^([xyz%?])%s+([+-]?%d+)$")\r
if found == nil then\r
worldedit.player_notify(name, "invalid usage: " .. param)\r
worldedit.mark_pos1(name)\r
worldedit.mark_pos2(name)\r
worldedit.player_notify(name, count .. " nodes moved")\r
- end,\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
- worldedit.player_notify(name, "no region selected")\r
- return\r
- end\r
-\r
- local found, _, axis, count = param:find("^([xyz%?])%s+([+-]?%d+)$")\r
- if found == nil then\r
- worldedit.player_notify(name, "invalid usage: " .. param)\r
- return\r
- end\r
- count = tonumber(count)\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, count)\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("/scale", {\r
- params = "<factor>",\r
- description = "Scale the current WorldEdit positions and region by a factor of positive integer <factor> with position 1 as the origin",\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
- worldedit.player_notify(name, "no region selected")\r
+ worldedit.player_notify(name, "Select a position first!")\r
+ return\r
+ end\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
+ repetitions = tonumber(repetitions)\r
\r
- local factor = tonumber(param)\r
- if not factor or factor ~= math.floor(factor) or factor <= 0 then\r
- worldedit.player_notify(name, "invalid scaling factor: " .. param)\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
+ 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
- local count, pos1, pos2 = worldedit.scale(pos1, pos2, factor)\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.mark_pos1(name)\r
worldedit.mark_pos2(name)\r
\r
- worldedit.player_notify(name, count .. " nodes scaled")\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
+ 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 = 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
- worldedit.player_notify(name, "no region selected")\r
- return\r
- end\r
-\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\r
- end\r
- if axis1 == "?" then\r
- axis1 = worldedit.player_axis(name)\r
- end\r
- if axis2 == "?" then\r
- axis2 = worldedit.player_axis(name)\r
- end\r
- if axis1 == axis2 then\r
- worldedit.player_notify(name, "invalid usage: axes must be different")\r
- return\r
- end\r
-\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
\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
- worldedit.player_notify(name, "no 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
- worldedit.player_notify(name, "invalid usage: " .. param)\r
- return\r
- end\r
-\r
- local count = worldedit.flip(pos1, pos2, param)\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
- worldedit.player_notify(name, "no region selected")\r
- return\r
- end\r
-\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\r
- end\r
- if axis == "?" then\r
- axis = worldedit.player_axis(name)\r
- end\r
- if angle % 90 ~= 0 then\r
- worldedit.player_notify(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
\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
- worldedit.player_notify(name, "no 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
worldedit.player_notify(name, "invalid usage: " .. param)\r
- return\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\r
+ return nil\r
end\r
-\r
- local count = worldedit.orient(pos1, pos2, angle)\r
-\r
- worldedit.player_notify(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
- worldedit.player_notify(name, "no 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.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
+ 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
- worldedit.player_notify(name, "no region selected")\r
- return\r
- end\r
-\r
- local count = worldedit.hide(pos1, pos2)\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
+ 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
- worldedit.player_notify(name, "no region selected")\r
- return\r
- end\r
-\r
- local node = worldedit.normalize_nodename(param)\r
- if param == "" or not node then\r
- worldedit.player_notify(name, "invalid node name: " .. param)\r
- return\r
- end\r
-\r
- local count = worldedit.suppress(pos1, pos2, node)\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,\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
- worldedit.player_notify(name, "no region selected")\r
- return\r
- end\r
-\r
- local node = worldedit.normalize_nodename(param)\r
- if param == "" or not node then\r
- worldedit.player_notify(name, "invalid node name: " .. param)\r
- return\r
- end\r
-\r
- local count = worldedit.highlight(pos1, pos2, node)\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,\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
- worldedit.player_notify(name, "no region selected")\r
- return\r
- end\r
-\r
- local count = worldedit.restore(pos1, pos2)\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
+ 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
- worldedit.player_notify(name, "no region selected")\r
- return\r
- end\r
-\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
- local result, count = worldedit.serialize(pos1, pos2)\r
+ if not check_filename(param) then\r
+ worldedit.player_notify(name, "Disallowed file name: " .. param)\r
+ return\r
+ end\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
- worldedit.player_notify(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:close()\r
\r
worldedit.player_notify(name, count .. " nodes saved")\r
- end,\r
+ end),\r
})\r
\r
minetest.register_chatcommand("/allocate", {\r
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
- worldedit.player_notify(name, "no 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
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
local value = file:read("*a")\r
file:close()\r
\r
- if worldedit.valueversion(value) == 0 then --unknown version\r
- worldedit.player_notify(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
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
- worldedit.player_notify(name, "no 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
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
--find the file in the world path\r
local testpaths = {\r
local value = file:read("*a")\r
file:close()\r
\r
- if worldedit.valueversion(value) == 0 then --unknown version\r
- worldedit.player_notify(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
\r
- local count = worldedit.deserialize(pos1, value)\r
+ local count = worldedit.deserialize(pos, value)\r
\r
worldedit.player_notify(name, count .. " nodes loaded")\r
end,\r
local err = worldedit.lua(param)\r
if err then\r
worldedit.player_notify(name, "code error: " .. err)\r
+ minetest.log("action", name.." tried to execute "..param)\r
else\r
worldedit.player_notify(name, "code successfully executed", false)\r
+ minetest.log("action", name.." executed "..param)\r
end\r
end,\r
})\r
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 = function(name, param)\r
- local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
- if pos1 == nil or pos2 == nil then\r
- worldedit.player_notify(name, "no region selected")\r
- return\r
- end\r
-\r
- local err = worldedit.luatransform(pos1, pos2, param)\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
+ end),\r
})\r
\r
-if minetest.place_schematic then\r
minetest.register_chatcommand("/mtschemcreate", {\r
params = "<file>",\r
- description = "Save the current WorldEdit region using the Minetest Schematic format to \"(world folder)/schems/<filename>.mts\"",\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 = function(name, param)\r
- local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
- if pos1 == nil or pos2 == nil then\r
- worldedit.player_notify(name, "No region selected")\r
- return\r
- end\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
- local filename = path .. "/" .. param .. ".mts"\r
- os.execute("mkdir \"" .. path .. "\"") --create directory if it does not already exist\r
+ -- Create directory if it does not already exist\r
+ mkdir(path)\r
\r
- local ret = minetest.create_schematic(pos1, pos2, worldedit.prob_list[name], filename)\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
+ end),\r
})\r
\r
minetest.register_chatcommand("/mtschemplace", {\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 pos = worldedit.pos1[name]\r
- if pos == nil then\r
- worldedit.player_notify(name, "No position selected")\r
+ if param == "" then\r
+ worldedit.player_notify(name, "no filename specified")\r
return\r
end\r
- if param == nil then\r
- worldedit.player_notify(name, "No filename specified")\r
+ if not check_filename(param) then\r
+ worldedit.player_notify(name, "Disallowed file name: " .. param)\r
return\r
end\r
\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
+ worldedit.player_notify(name, "failed to place Minetest schematic", false)\r
else\r
- worldedit.player_notify(name, "Placed Minetest schematic " .. param ..\r
+ worldedit.player_notify(name, "placed Minetest schematic " .. param ..\r
" at " .. minetest.pos_to_string(pos), false)\r
end\r
end,\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
+ 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, "currently set node probabilities:")\r
worldedit.player_notify(name, text)\r
else\r
worldedit.player_notify(name, "unknown subcommand: " .. param)\r
end,\r
})\r
\r
-minetest.register_on_player_receive_fields(\r
- function(player, formname, fields)\r
- if (formname == "prob_val_enter") and (fields.text ~= "") 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
+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
-)\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 = function(name, param)\r
- local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
- if pos1 == nil or pos2 == nil then\r
- worldedit.player_notify(name, "no region selected")\r
- return\r
- end\r
-\r
- local count = worldedit.clearobjects(pos1, pos2)\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
+ end),\r
})\r