]> git.lizzy.rs Git - worldedit.git/commitdiff
Allow to bulk-set param2 of regions (#144)
authorWuzzy <wuzzy2@mail.ru>
Tue, 5 Sep 2017 12:40:46 +0000 (14:40 +0200)
committersfan5 <sfan5@live.de>
Tue, 5 Sep 2017 12:40:46 +0000 (14:40 +0200)
ChatCommands.md
WorldEdit API.md
worldedit/manipulations.lua
worldedit_commands/init.lua

index 2a43c0574959360e78d7f8ae39a7ee457bced39c..03db3029aaf511a037abf2f7c6833537a5431297 100644 (file)
@@ -117,6 +117,10 @@ Set the current WorldEdit region to `<node>`.
     //set Blue Lightstone\r
     //set dirt with grass\r
 \r
+### `//param2 <param2>`\r
+\r
+Set the param2 value of all nodes in the current WorldEdit region to `<param2>`.\r
+\r
 ### `//mix <node1> ...`\r
 \r
 Fill the current WorldEdit region with a random mix of `<node1>`, `...`.\r
index 1106fc70055d5c9de6c077550ed83154e542cb2a..8cee31ba1bf745f4efb350109da813146db25c2c 100644 (file)
@@ -27,6 +27,12 @@ Sets a region defined by positions `pos1` and `pos2` to `node_name`. To clear a
 \r
 Returns the number of nodes set.\r
 \r
+### `count = worldedit.set_param2(pos1, pos2, param2)`\r
+\r
+Sets the param2 values of all nodes in a region defined by positions `pos1` and `pos2` to `param2`.\r
+\r
+Returns the number of nodes set.\r
+\r
 ### count = worldedit.replace(pos1, pos2, searchnode, replacenode)\r
 \r
 Replaces all instances of `searchnode` with `replacenode` in a region defined by positions `pos1` and `pos2`.\r
index 57c7a764e8de015b2ed8093823d59000d066b147..995619c39c58f7694604a5ea18e39d8ce1f2988d 100644 (file)
@@ -38,6 +38,29 @@ function worldedit.set(pos1, pos2, node_names)
        return worldedit.volume(pos1, pos2)\r
 end\r
 \r
+--- Sets param2 of a region.\r
+-- @param pos1\r
+-- @param pos2\r
+-- @param param2 Value of param2 to set\r
+-- @return The number of nodes set.\r
+function worldedit.set_param2(pos1, pos2, param2)\r
+       pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
+\r
+       local manip, area = mh.init(pos1, pos2)\r
+       local param2_data = manip:get_param2_data()\r
+\r
+       -- Set param2 for every node\r
+       for i in area:iterp(pos1, pos2) do\r
+               param2_data[i] = param2\r
+       end\r
+\r
+       -- Update map\r
+       manip:set_param2_data(param2_data)\r
+       manip:write_to_map()\r
+       manip:update_map()\r
+\r
+       return worldedit.volume(pos1, pos2)\r
+end\r
 \r
 --- Replaces all instances of `search_node` with `replace_node` in a region.\r
 -- When `inverse` is `true`, replaces all instances that are NOT `search_node`.\r
index 897636cc332a9cc6e721bc645c7b4d9675458b58..1ab8c1953851b149c8ba66c31aef8272f72bd99c 100644 (file)
@@ -408,6 +408,25 @@ minetest.register_chatcommand("/set", {
        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