\r
### //replace <search node> <replace node>\r
\r
-Replace all instances of <search node> with <place node> in the current WorldEdit region.\r
+Replace all instances of <search node> with <replace node> in the current WorldEdit region.\r
\r
//replace cobble stone\r
//replace default:steelblock glass\r
//replace dirt flowers:flower_waterlily\r
//replace flowers:flower_rose flowers:flower_tulip\r
\r
+### //replaceinverse <search node> <replace node>\r
+\r
+Replace all nodes other than <search node> with <replace node> in the current WorldEdit region.\r
+\r
+ //replaceinverse air stone\r
+ //replaceinverse water_source default:dirt\r
+ //replaceinverse mesecons:mesecon air\r
+ //replaceinverse default:steelblock default:glass\r
+\r
### //hollowsphere <radius> <node>\r
\r
Add hollow sphere at WorldEdit position 1 with radius <radius>, composed of <node>.\r
\r
Returns the number of nodes replaced.\r
\r
+### count = worldedit.replaceinverse(pos1, pos2, searchnode, replacenode)\r
+\r
+Replaces all nodes other than `searchnode` with `replacenode` in a region defined by positions `pos1` and `pos2`.\r
+\r
+Returns the number of nodes replaced.\r
+\r
### count = worldedit.copy(pos1, pos2, axis, amount)\r
\r
Copies the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes.\r
return count\r
end\r
\r
+--replaces all nodes other than `searchnode` with `replacenode` in a region defined by positions `pos1` and `pos2`, returning the number of nodes replaced\r
+worldedit.replaceinverse = function(pos1, pos2, searchnode, replacenode)\r
+ local pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
+ local env = minetest.env\r
+\r
+ if minetest.registered_nodes[searchnode] == nil then\r
+ searchnode = "default:" .. searchnode\r
+ end\r
+\r
+ local pos = {x=pos1.x, y=0, z=0}\r
+ local node = {name=replacenode}\r
+ local count = 0\r
+ while pos.x <= pos2.x do\r
+ pos.y = pos1.y\r
+ while pos.y <= pos2.y do\r
+ pos.z = pos1.z\r
+ while pos.z <= pos2.z do\r
+ local name = env:get_node(pos).name\r
+ if name ~= "ignore" and name ~= searchnode then\r
+ env:add_node(pos, node)\r
+ count = count + 1\r
+ end\r
+ pos.z = pos.z + 1\r
+ end\r
+ pos.y = pos.y + 1\r
+ end\r
+ pos.x = pos.x + 1\r
+ end\r
+ return count\r
+end\r
+\r
--copies the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes, returning the number of nodes copied\r
worldedit.copy = function(pos1, pos2, axis, amount)\r
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
pos.x = pos.x + 1\r
end\r
return count\r
-end
+end\r
end,\r
})\r
\r
-minetest.register_chatcommand("/homogenize", {\r
- params = "<node>",\r
- description = "Replace all non-air nodes with <node> in the current WorldEdit region",\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
return\r
end\r
\r
- if not worldedit.node_is_valid(param) then\r
- minetest.chat_send_player(name, "Invalid node name: " .. param)\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.homogenize(pos1, pos2, param)\r
- minetest.chat_send_player(name, count .. " nodes homogenized")\r
+ local count = worldedit.replaceinverse(pos1, pos2, searchnode, replacenode)\r
+ minetest.chat_send_player(name, count .. " nodes replaced")\r
end,\r
})\r
\r