Skip to content

Commit b376059

Browse files
sbrlsfan5
authored andcommittedOct 28, 2018
//mix: Add node weighting support
1 parent f725663 commit b376059

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed
 

‎ChatCommands.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,16 @@ Set the current WorldEdit region to `<node>`.
121121

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

124-
### `//mix <node1> ...`
124+
### `//mix <node1> [<count1>] <node2> [<count2>]...`
125125

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

128128
//mix air
129129
//mix cactus stone glass sandstone
130130
//mix Bronze
131131
//mix default:cobble air
132+
//mix stone 3 dirt 2
133+
//mix cobblestone 8 stoneblock 2 stonebrick
132134

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

‎worldedit_commands/init.lua

+11-4
Original file line numberDiff line numberDiff line change
@@ -425,15 +425,22 @@ minetest.register_chatcommand("/param2", {
425425
})
426426

427427
minetest.register_chatcommand("/mix", {
428-
params = "<node1> ...",
428+
params = "<node1> [<weighting1>] [<node2> [<weighting2>]] ...",
429429
description = "Fill the current WorldEdit region with a random mix of <node1>, ...",
430430
privs = {worldedit=true},
431431
func = safe_region(function(name, param)
432432
local nodes = {}
433433
for nodename in param:gmatch("[^%s]+") do
434-
local node = get_node(name, nodename)
435-
if not node then return end
436-
nodes[#nodes + 1] = node
434+
if tonumber(nodename) ~= nil and #nodes > 0 then
435+
local last_node = nodes[#nodes]
436+
for i = 1, tonumber(nodename) do
437+
nodes[#nodes + 1] = last_node
438+
end
439+
else
440+
local node = get_node(name, nodename)
441+
if not node then return end
442+
nodes[#nodes + 1] = node
443+
end
437444
end
438445

439446
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]

0 commit comments

Comments
 (0)
Please sign in to comment.