Skip to content

Commit 3c61759

Browse files
Wuzzy2sfan5
authored andcommittedSep 5, 2017
Allow to bulk-set param2 of regions (#144)
1 parent 2f4eb19 commit 3c61759

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed
 

Diff for: ‎ChatCommands.md

+4
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ Set the current WorldEdit region to `<node>`.
117117
//set Blue Lightstone
118118
//set dirt with grass
119119

120+
### `//param2 <param2>`
121+
122+
Set the param2 value of all nodes in the current WorldEdit region to `<param2>`.
123+
120124
### `//mix <node1> ...`
121125

122126
Fill the current WorldEdit region with a random mix of `<node1>`, `...`.

Diff for: ‎WorldEdit API.md

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ Sets a region defined by positions `pos1` and `pos2` to `node_name`. To clear a
2727

2828
Returns the number of nodes set.
2929

30+
### `count = worldedit.set_param2(pos1, pos2, param2)`
31+
32+
Sets the param2 values of all nodes in a region defined by positions `pos1` and `pos2` to `param2`.
33+
34+
Returns the number of nodes set.
35+
3036
### count = worldedit.replace(pos1, pos2, searchnode, replacenode)
3137

3238
Replaces all instances of `searchnode` with `replacenode` in a region defined by positions `pos1` and `pos2`.

Diff for: ‎worldedit/manipulations.lua

+23
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,29 @@ function worldedit.set(pos1, pos2, node_names)
3838
return worldedit.volume(pos1, pos2)
3939
end
4040

41+
--- Sets param2 of a region.
42+
-- @param pos1
43+
-- @param pos2
44+
-- @param param2 Value of param2 to set
45+
-- @return The number of nodes set.
46+
function worldedit.set_param2(pos1, pos2, param2)
47+
pos1, pos2 = worldedit.sort_pos(pos1, pos2)
48+
49+
local manip, area = mh.init(pos1, pos2)
50+
local param2_data = manip:get_param2_data()
51+
52+
-- Set param2 for every node
53+
for i in area:iterp(pos1, pos2) do
54+
param2_data[i] = param2
55+
end
56+
57+
-- Update map
58+
manip:set_param2_data(param2_data)
59+
manip:write_to_map()
60+
manip:update_map()
61+
62+
return worldedit.volume(pos1, pos2)
63+
end
4164

4265
--- Replaces all instances of `search_node` with `replace_node` in a region.
4366
-- When `inverse` is `true`, replaces all instances that are NOT `search_node`.

Diff for: ‎worldedit_commands/init.lua

+19
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,25 @@ minetest.register_chatcommand("/set", {
408408
end, check_region),
409409
})
410410

411+
minetest.register_chatcommand("/param2", {
412+
params = "<param2>",
413+
description = "Set param2 of all nodes in the current WorldEdit region to <param2>",
414+
privs = {worldedit=true},
415+
func = safe_region(function(name, param)
416+
local param2 = tonumber(param)
417+
if not param2 then
418+
worldedit.player_notify(name, "Invalid or missing param2 argument")
419+
return
420+
elseif param2 < 0 or param2 > 255 then
421+
worldedit.player_notify(name, "Param2 is out of range (must be between 0 and 255 inclusive)!")
422+
return
423+
end
424+
425+
local count = worldedit.set_param2(worldedit.pos1[name], worldedit.pos2[name], param2)
426+
worldedit.player_notify(name, count .. " nodes altered")
427+
end, check_region),
428+
})
429+
411430
minetest.register_chatcommand("/mix", {
412431
params = "<node1> ...",
413432
description = "Fill the current WorldEdit region with a random mix of <node1>, ...",

0 commit comments

Comments
 (0)
Please sign in to comment.