From cca296f62c999a7c05056da471da8f58227d7b40 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Thu, 31 Aug 2017 01:06:14 +0200 Subject: [PATCH] Allow to bulk-set param2 of regions --- WorldEdit API.md | 6 ++++++ worldedit/manipulations.lua | 23 +++++++++++++++++++++++ worldedit_commands/init.lua | 19 +++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/WorldEdit API.md b/WorldEdit API.md index 5867dfc..9696247 100644 --- a/WorldEdit API.md +++ b/WorldEdit API.md @@ -27,6 +27,12 @@ Sets a region defined by positions `pos1` and `pos2` to `node_name`. To clear a Returns the number of nodes set. +### `count = worldedit.set_param2(pos1, pos2, param2)` + +Sets the param2 values of all nodes in a region defined by positions `pos1` and `pos2` to `param2`. + +Returns the number of nodes set. + ### count = worldedit.replace(pos1, pos2, searchnode, replacenode) Replaces all instances of `searchnode` with `replacenode` in a region defined by positions `pos1` and `pos2`. diff --git a/worldedit/manipulations.lua b/worldedit/manipulations.lua index 57c7a76..b668ddb 100644 --- a/worldedit/manipulations.lua +++ b/worldedit/manipulations.lua @@ -38,6 +38,29 @@ function worldedit.set(pos1, pos2, node_names) return worldedit.volume(pos1, pos2) end +--- Sets param2 of a region. +-- @param pos1 +-- @param pos2 +-- @param param2 Value of param2 to set +-- @return The number of nodes set. +function worldedit.set_param2(pos1, pos2, param2) + pos1, pos2 = worldedit.sort_pos(pos1, pos2) + + local manip, area = mh.init(pos1, pos2) + local param2_data = {} + + -- Set param2 for every node + for i in area:iterp(pos1, pos2) do + param2_data[i] = param2 + end + + -- Update map + manip:set_param2_data(param2_data) + manip:write_to_map() + manip:update_map() + + return worldedit.volume(pos1, pos2) +end --- Replaces all instances of `search_node` with `replace_node` in a region. -- When `inverse` is `true`, replaces all instances that are NOT `search_node`. diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua index 325a31c..009908f 100644 --- a/worldedit_commands/init.lua +++ b/worldedit_commands/init.lua @@ -387,6 +387,25 @@ minetest.register_chatcommand("/set", { end, check_region), }) +minetest.register_chatcommand("/param2", { + params = "", + description = "Set param2 of all nodes in the current WorldEdit region to ", + privs = {worldedit=true}, + func = safe_region(function(name, param) + local param2 = tonumber(param) + if not param2 then + worldedit.player_notify(name, "Invalid or missing param2 argument") + return + elseif param2 < 0 or param2 > 255 then + worldedit.player_notify(name, "Param2 is out of range (must be between 0 and 255 inclusive)!") + return + end + + local count = worldedit.set_param2(worldedit.pos1[name], worldedit.pos2[name], param2) + worldedit.player_notify(name, count .. " nodes set") + end, check_region), +}) + minetest.register_chatcommand("/mix", { params = " ...", description = "Fill the current WorldEdit region with a random mix of , ...",