From 42d64e0d2d07a03261be88c06b48579b437ffe19 Mon Sep 17 00:00:00 2001 From: zmv7 Date: Tue, 6 Aug 2024 17:33:53 +0500 Subject: [PATCH] Add feature to set param2 of specified nodes only --- worldedit/manipulations.lua | 15 +++++++++++---- worldedit_commands/manipulations.lua | 13 +++++++------ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/worldedit/manipulations.lua b/worldedit/manipulations.lua index 73d0242..8dda79f 100644 --- a/worldedit/manipulations.lua +++ b/worldedit/manipulations.lua @@ -42,16 +42,23 @@ end -- @param pos1 -- @param pos2 -- @param param2 Value of param2 to set +-- @param node Optional specified node to affect -- @return The number of nodes set. -function worldedit.set_param2(pos1, pos2, param2) +function worldedit.set_param2(pos1, pos2, param2, node) pos1, pos2 = worldedit.sort_pos(pos1, pos2) local manip, area = mh.init(pos1, pos2) local param2_data = manip:get_param2_data() + local data = manip:get_data() - -- Set param2 for every node + local search_id = node and minetest.get_content_id(node) + local count = 0 + -- Set param2 for every node or only for specified nodes for i in area:iterp(pos1, pos2) do - param2_data[i] = param2 + if not search_id or data[i] == search_id then + param2_data[i] = param2 + count = count + 1 + end end -- Update map @@ -59,7 +66,7 @@ function worldedit.set_param2(pos1, pos2, param2) manip:write_to_map() manip:update_map() - return worldedit.volume(pos1, pos2) + return count end --- Replaces all instances of `search_node` with `replace_node` in a region. diff --git a/worldedit_commands/manipulations.lua b/worldedit_commands/manipulations.lua index 2a6d36b..e1e9358 100644 --- a/worldedit_commands/manipulations.lua +++ b/worldedit_commands/manipulations.lua @@ -57,23 +57,24 @@ worldedit.register_command("set", { }) worldedit.register_command("param2", { - params = "", - description = S("Set param2 of all nodes in the current WorldEdit region to "), + params = " [node]", + description = S("Set param2 of all or specified nodes in the current WorldEdit region to "), category = S("Node manipulation"), privs = {worldedit=true}, require_pos = 2, parse = function(param) - local param2 = tonumber(param) + local param2, node = param:match("^(%d+) (%S+)$") + param2 = tonumber(param2) or tonumber(param) if not param2 then return false elseif param2 < 0 or param2 > 255 then return false, S("Param2 is out of range (must be between 0 and 255 inclusive!)") end - return true, param2 + return true, param2, node end, nodes_needed = check_region, - func = function(name, param2) - local count = worldedit.set_param2(worldedit.pos1[name], worldedit.pos2[name], param2) + func = function(name, param2, node) + local count = worldedit.set_param2(worldedit.pos1[name], worldedit.pos2[name], param2, node) return true, S("@1 nodes altered", count) end, })