Add seed parameter in lplant cmd and function
This commit is contained in:
parent
4dc18bcf36
commit
38f92367ce
3
API.md
3
API.md
@ -133,12 +133,13 @@ It depends:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
### `ltool.plant_tree(tree_id, pos)`
|
### `ltool.plant_tree(tree_id, pos, seed)`
|
||||||
Plants a tree as the specified position.
|
Plants a tree as the specified position.
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
* `tree_id`: ID of tree to be planted
|
* `tree_id`: ID of tree to be planted
|
||||||
* `pos`: Position of tree, in the format `{x=?, y=?, z=?}`
|
* `pos`: Position of tree, in the format `{x=?, y=?, z=?}`
|
||||||
|
* `seed`: Optional randomness seed, equal seed creates equal trees
|
||||||
|
|
||||||
#### Return value
|
#### Return value
|
||||||
`false` on failure, `nil` otherwise.
|
`false` on failure, `nil` otherwise.
|
||||||
|
18
init.lua
18
init.lua
@ -204,15 +204,23 @@ end
|
|||||||
--[[ Plants a tree as the specified position
|
--[[ Plants a tree as the specified position
|
||||||
tree_id: ID of tree to be planted
|
tree_id: ID of tree to be planted
|
||||||
pos: Position of tree, in format {x=?, y=?, z=?}
|
pos: Position of tree, in format {x=?, y=?, z=?}
|
||||||
|
seed: Optional seed for randomness, equal seed makes equal trees
|
||||||
|
|
||||||
returns false on failure, nil otherwise
|
returns false on failure, nil otherwise
|
||||||
]]
|
]]
|
||||||
function ltool.plant_tree(tree_id, pos)
|
function ltool.plant_tree(tree_id, pos, seed)
|
||||||
local tree = ltool.trees[tree_id]
|
local tree = ltool.trees[tree_id]
|
||||||
if(tree==nil) then
|
if(tree==nil) then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
minetest.spawn_tree(pos, tree.treedef)
|
local treedef
|
||||||
|
if seed ~= nil then
|
||||||
|
treedef = table.copy(tree.treedef)
|
||||||
|
treedef.seed = seed
|
||||||
|
else
|
||||||
|
treedef = tree.treedef
|
||||||
|
end
|
||||||
|
minetest.spawn_tree(pos, treedef)
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[ Tries to return a tree data structure for a given tree_id
|
--[[ Tries to return a tree data structure for a given tree_id
|
||||||
@ -821,8 +829,8 @@ minetest.register_chatcommand("lplant",
|
|||||||
params = "<tree ID> <x> <y> <z>",
|
params = "<tree ID> <x> <y> <z>",
|
||||||
func = function(playername, param)
|
func = function(playername, param)
|
||||||
local p = {}
|
local p = {}
|
||||||
local tree_id, x, y, z = string.match(param, "^([^ ]+) +([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")
|
local tree_id, x, y, z, seed = string.match(param, "^([^ ]+) +([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+) *([%d.-]*)")
|
||||||
tree_id, p.x, p.y, p.z = tonumber(tree_id), tonumber(x), tonumber(y), tonumber(z)
|
tree_id, p.x, p.y, p.z, seed = tonumber(tree_id), tonumber(x), tonumber(y), tonumber(z), tonumber(seed)
|
||||||
if not tree_id or not p.x or not p.y or not p.z then
|
if not tree_id or not p.x or not p.y or not p.z then
|
||||||
return false, "Invalid usage, see /help lplant."
|
return false, "Invalid usage, see /help lplant."
|
||||||
end
|
end
|
||||||
@ -831,7 +839,7 @@ minetest.register_chatcommand("lplant",
|
|||||||
return false, "Cannot plant tree out of map bounds!"
|
return false, "Cannot plant tree out of map bounds!"
|
||||||
end
|
end
|
||||||
|
|
||||||
local success = ltool.plant_tree(tree_id, p)
|
local success = ltool.plant_tree(tree_id, p, seed)
|
||||||
if success == false then
|
if success == false then
|
||||||
return false, "Unknown tree ID!"
|
return false, "Unknown tree ID!"
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user