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
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
- nodename = nodename:gsub("^%s*(.-)%s*$", "%1")\r
+ nodename = nodename:gsub("^%s*(.-)%s*$", "%1") -- strip spaces\r
if nodename == "" then return nil end\r
- local fullname = ItemStack({name=nodename}):get_name() --resolve aliases of node names to full names\r
- if minetest.registered_nodes[fullname] or fullname == "air" then --directly found node name or alias of nodename\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
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_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