Skip to content

Commit

Permalink
Allow to bulk-set param2 of regions (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wuzzy2 authored and sfan5 committed Sep 5, 2017
1 parent 2f4eb19 commit 3c61759
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ChatCommands.md
Expand Up @@ -117,6 +117,10 @@ Set the current WorldEdit region to `<node>`.
//set Blue Lightstone
//set dirt with grass

### `//param2 <param2>`

Set the param2 value of all nodes in the current WorldEdit region to `<param2>`.

### `//mix <node1> ...`

Fill the current WorldEdit region with a random mix of `<node1>`, `...`.
Expand Down
6 changes: 6 additions & 0 deletions WorldEdit API.md
Expand Up @@ -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`.
Expand Down
23 changes: 23 additions & 0 deletions worldedit/manipulations.lua
Expand Up @@ -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 = manip:get_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`.
Expand Down
19 changes: 19 additions & 0 deletions worldedit_commands/init.lua
Expand Up @@ -408,6 +408,25 @@ minetest.register_chatcommand("/set", {
end, check_region),
})

minetest.register_chatcommand("/param2", {
params = "<param2>",
description = "Set param2 of all nodes in the current WorldEdit region to <param2>",
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 altered")
end, check_region),
})

minetest.register_chatcommand("/mix", {
params = "<node1> ...",
description = "Fill the current WorldEdit region with a random mix of <node1>, ...",
Expand Down

0 comments on commit 3c61759

Please sign in to comment.