From 7cf84045d4dea9727f9db5e5de9a6524fc4ef1af Mon Sep 17 00:00:00 2001 From: Anthony Zhang Date: Sat, 12 Jan 2013 18:29:57 -0500 Subject: Replace //homogenize with //replaceinverse (//homogenize x is equivalent to //replaceinverse air x), add documentation for it. --- worldedit_commands/init.lua | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'worldedit_commands') diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua index a2e6246..b568da3 100644 --- a/worldedit_commands/init.lua +++ b/worldedit_commands/init.lua @@ -197,9 +197,9 @@ minetest.register_chatcommand("/replace", { end, }) -minetest.register_chatcommand("/homogenize", { - params = "", - description = "Replace all non-air nodes with in the current WorldEdit region", +minetest.register_chatcommand("/replaceinverse", { + params = " ", + description = "Replace all nodes other than with in the current WorldEdit region", privs = {worldedit=true}, func = function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] @@ -208,13 +208,22 @@ minetest.register_chatcommand("/homogenize", { return end - if not worldedit.node_is_valid(param) then - minetest.chat_send_player(name, "Invalid node name: " .. param) + local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+([^%s]+)$") + if found == nil then + minetest.chat_send_player(name, "Invalid usage: " .. param) + return + end + if not worldedit.node_is_valid(searchnode) then + minetest.chat_send_player(name, "Invalid search node name: " .. searchnode) + return + end + if not worldedit.node_is_valid(replacenode) then + minetest.chat_send_player(name, "Invalid replace node name: " .. replacenode) return end - local count = worldedit.homogenize(pos1, pos2, param) - minetest.chat_send_player(name, count .. " nodes homogenized") + local count = worldedit.replaceinverse(pos1, pos2, searchnode, replacenode) + minetest.chat_send_player(name, count .. " nodes replaced") end, }) -- cgit v1.2.3