Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
//mix: Add node weighting support
  • Loading branch information
sbrl authored and sfan5 committed Oct 28, 2018
1 parent f725663 commit b376059
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
6 changes: 4 additions & 2 deletions ChatCommands.md
Expand Up @@ -121,14 +121,16 @@ Set the current WorldEdit region to `<node>`.

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

### `//mix <node1> ...`
### `//mix <node1> [<count1>] <node2> [<count2>]...`

Fill the current WorldEdit region with a random mix of `<node1>`, `...`.
Fill the current WorldEdit region with a random mix of `<node1>`, `<node2>`, `...`. Weightings can be optionally specified via a number after a node name.

//mix air
//mix cactus stone glass sandstone
//mix Bronze
//mix default:cobble air
//mix stone 3 dirt 2
//mix cobblestone 8 stoneblock 2 stonebrick

### `//replace <search node> <replace node>`

Expand Down
15 changes: 11 additions & 4 deletions worldedit_commands/init.lua
Expand Up @@ -425,15 +425,22 @@ minetest.register_chatcommand("/param2", {
})

minetest.register_chatcommand("/mix", {
params = "<node1> ...",
params = "<node1> [<weighting1>] [<node2> [<weighting2>]] ...",
description = "Fill the current WorldEdit region with a random mix of <node1>, ...",
privs = {worldedit=true},
func = safe_region(function(name, param)
local nodes = {}
for nodename in param:gmatch("[^%s]+") do
local node = get_node(name, nodename)
if not node then return end
nodes[#nodes + 1] = node
if tonumber(nodename) ~= nil and #nodes > 0 then
local last_node = nodes[#nodes]
for i = 1, tonumber(nodename) do
nodes[#nodes + 1] = last_node
end
else
local node = get_node(name, nodename)
if not node then return end
nodes[#nodes + 1] = node
end
end

local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
Expand Down

0 comments on commit b376059

Please sign in to comment.