diff --git a/ChatCommands.md b/ChatCommands.md index a37b65a..ea1f955 100644 --- a/ChatCommands.md +++ b/ChatCommands.md @@ -121,14 +121,16 @@ Set the current WorldEdit region to ``. Set the param2 value of all nodes in the current WorldEdit region to ``. -### `//mix ...` +### `//mix [] []...` -Fill the current WorldEdit region with a random mix of ``, `...`. +Fill the current WorldEdit region with a random mix of ``, ``, `...`. 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 ` diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua index 3640e0d..131c49b 100644 --- a/worldedit_commands/init.lua +++ b/worldedit_commands/init.lua @@ -425,15 +425,22 @@ minetest.register_chatcommand("/param2", { }) minetest.register_chatcommand("/mix", { - params = " ...", + params = " [] [ []] ...", description = "Fill the current WorldEdit region with a random mix of , ...", 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]