mirror of
https://github.com/Uberi/Minetest-WorldEdit.git
synced 2025-01-12 19:10:29 +01:00
Randomized set
Can /set node node2 node3 and it will randomly choose between those three.
This commit is contained in:
parent
2c4a791805
commit
174416b010
@ -24,7 +24,11 @@ worldedit.volume = function(pos1, pos2)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--sets a region defined by positions `pos1` and `pos2` to `nodename`, returning the number of nodes filled
|
--sets a region defined by positions `pos1` and `pos2` to `nodename`, returning the number of nodes filled
|
||||||
worldedit.set = function(pos1, pos2, nodename)
|
worldedit.set = function(pos1, pos2, nodenames)
|
||||||
|
if type(nodenames) == 'string' then
|
||||||
|
nodenames = {nodenames}
|
||||||
|
end
|
||||||
|
|
||||||
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||||
|
|
||||||
--set up voxel manipulator
|
--set up voxel manipulator
|
||||||
@ -40,9 +44,12 @@ worldedit.set = function(pos1, pos2, nodename)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--fill selected area with node
|
--fill selected area with node
|
||||||
local node_id = minetest.get_content_id(nodename)
|
local node_ids = {}
|
||||||
|
for i,v in ipairs(nodenames) do
|
||||||
|
node_ids[i] = minetest.get_content_id(nodenames[i])
|
||||||
|
end
|
||||||
for i in area:iterp(pos1, pos2) do
|
for i in area:iterp(pos1, pos2) do
|
||||||
nodes[i] = node_id
|
nodes[i] = node_ids[math.random(#node_ids)]
|
||||||
end
|
end
|
||||||
|
|
||||||
--update map nodes
|
--update map nodes
|
||||||
|
@ -278,22 +278,26 @@ minetest.register_chatcommand("/volume", {
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
local check_set = function(name, param)
|
|
||||||
local node = get_node(name, param)
|
|
||||||
if not node then return nil end
|
|
||||||
return check_region(name, param)
|
|
||||||
end
|
|
||||||
|
|
||||||
minetest.register_chatcommand("/set", {
|
minetest.register_chatcommand("/set", {
|
||||||
params = "<node>",
|
params = "<node>",
|
||||||
description = "Set the current WorldEdit region to <node>",
|
description = "Set the current WorldEdit region to <node>",
|
||||||
privs = {worldedit=true},
|
privs = {worldedit=true},
|
||||||
func = safe_region(function(name, param)
|
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
|
||||||
|
worldedit.player_notify(name, 'Could not identify node "'..name..'"')
|
||||||
|
return
|
||||||
|
end
|
||||||
|
nodes[#nodes+1] = node
|
||||||
|
end
|
||||||
|
|
||||||
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
||||||
local node = get_node(name, param)
|
local count = worldedit.set(pos1, pos2, nodes)
|
||||||
local count = worldedit.set(pos1, pos2, node)
|
|
||||||
worldedit.player_notify(name, count .. " nodes set")
|
worldedit.player_notify(name, count .. " nodes set")
|
||||||
end, check_set),
|
end, check_region),
|
||||||
})
|
})
|
||||||
|
|
||||||
local check_replace = function(name, param)
|
local check_replace = function(name, param)
|
||||||
|
Loading…
Reference in New Issue
Block a user