]> git.lizzy.rs Git - worldedit.git/commitdiff
Replace //homogenize with //replaceinverse (//homogenize x is equivalent to //replace...
authorAnthony Zhang <azhang9@gmail.com>
Sat, 12 Jan 2013 23:29:57 +0000 (18:29 -0500)
committerAnthony Zhang <azhang9@gmail.com>
Sat, 12 Jan 2013 23:29:57 +0000 (18:29 -0500)
Chat Commands.md
WorldEdit API.md
worldedit/manipulations.lua
worldedit_commands/init.lua

index 23920a4860bccc6423b3e5f3e4a43c7f4689c4a3..9e9ccaefd546a3532f0faea6b8105293cc4d9ff9 100644 (file)
@@ -51,13 +51,22 @@ Set the current WorldEdit region to <node>.
 \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
index 0b383edfbb92661f48370822b3dca6522f287942..e0331506e939fef516ddd83bf295e63cd9a71e7a 100644 (file)
@@ -20,6 +20,12 @@ Replaces all instances of `searchnode` with `replacenode` in a region defined by
 \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
index 253456cfefccd81d7b23239e89dd53f2810dc348..c6bb9dd553c8d0db421f3b798a270f03e3f0e2cb 100644 (file)
@@ -74,6 +74,37 @@ worldedit.replace = function(pos1, pos2, searchnode, replacenode)
        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
@@ -383,4 +414,4 @@ worldedit.fixlight = function(pos1, pos2)
                pos.x = pos.x + 1\r
        end\r
        return count\r
-end
+end\r
index a2e6246a9fdb0c988ef89bc91526131241ad9312..b568da32496454c9dcf3a9a2cc224439a7012407 100644 (file)
@@ -197,9 +197,9 @@ minetest.register_chatcommand("/replace", {
        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
@@ -208,13 +208,22 @@ minetest.register_chatcommand("/homogenize", {
                        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