Difference between revisions of "minetest.spawn tree"
Jump to navigation
Jump to search
(→Description: Update link) |
ROllerozxa (talk | contribs) |
||
(9 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
+ | {{UnofficialLua}} | ||
{{DISPLAYTITLE:minetest.spawn_tree}} | {{DISPLAYTITLE:minetest.spawn_tree}} | ||
== Syntax == | == Syntax == | ||
Line 4: | Line 5: | ||
== Description == | == Description == | ||
− | * <code>pos</code> — | + | * <code>pos</code> — position |
− | * <code>tree</code> — | + | * <code>tree</code> — treedef |
Spawns an L-system tree at position <code>pos</code>, using the tree definition <code>tree</code>. | Spawns an L-system tree at position <code>pos</code>, using the tree definition <code>tree</code>. | ||
See [[Introduction to L-system trees]] for a description of L-system trees. | See [[Introduction to L-system trees]] for a description of L-system trees. | ||
+ | |||
+ | == Example == | ||
+ | This code adds the chat command "/spawn_tree" to spawn an apple tree with its origin at the current position of the player, assuming that [http://wiki.minetest.net/Subgames/Minetest%20Game Minetest Game] is used: | ||
+ | <source> | ||
+ | local treedef = { | ||
+ | axiom="FFFFFAFFBF", | ||
+ | rules_a="[&&&FFFFF&&FFFF][&&&++++FFFFF&&FFFF][&&&----FFFFF&&FFFF]", | ||
+ | rules_b="[&&&++FFFFF&&FFFF][&&&--FFFFF&&FFFF][&&&------FFFFF&&FFFF]", | ||
+ | trunk="default:tree", | ||
+ | leaves="default:leaves", | ||
+ | angle=30, | ||
+ | iterations=2, | ||
+ | random_level=0, | ||
+ | trunk_type="single", | ||
+ | thin_branches=true, | ||
+ | fruit_chance=10, | ||
+ | fruit="default:apple" | ||
+ | } | ||
+ | |||
+ | core.register_chatcommand("spawn_tree", { | ||
+ | params = "", description = "Spawns tree at player position", | ||
+ | func = function(name, param) | ||
+ | local pos = minetest.get_player_by_name(name):getpos() | ||
+ | minetest.chat_send_player(name, "Spawning tree at " .. minetest.pos_to_string(pos) | ||
+ | .. ", please wait") | ||
+ | minetest.spawn_tree(pos, treedef) | ||
+ | return true, "successfully spawned" | ||
+ | end, | ||
+ | }) | ||
+ | </source> | ||
+ | |||
+ | The resulting tree may look like this: | ||
+ | |||
+ | [[File:Apple Tree.png|420px]] | ||
== Notes == | == Notes == | ||
− | VanessaE's [https://forum.minetest.net/viewtopic.php?id=3898 plants_lib] mod | + | * For examples, go to [[L-system tree examples]] |
− | ([https://github.com/VanessaE/plantlife/blob/master/plants_lib/ github]) | + | * VanessaE's [https://forum.minetest.net/viewtopic.php?id=3898 plants_lib] mod ([https://github.com/VanessaE/plantlife/blob/master/plants_lib/ github]) provides functions to register L-system trees to be spawned during map generation, and finds places for them to spawn based on the map seed and biome. |
− | provides functions to register L-system trees to be spawned during map generation, | + | * [https://forum.minetest.net/viewtopic.php?f=11&t=9458 L-System Tree Utility] is a mod which helps to create L-system trees in-game |
− | and finds places for them to spawn based on the map seed and biome. | ||
− | |||
− | [[Category:Methods]] | + | [[Category:Methods|s]] |
Latest revision as of 19:11, 25 January 2023
This page contains unofficial, low-quality Lua API documentation and is likely to be outdated or wrong. Do not rely on it! For the official and up-to-date documentation, see Lua API Documentation. |
This page has been proposed for deletion for the following reason: "Contains unofficial and potentially outdated, redundant and inconsistent Lua API information" If you don't think that this page should be deleted, please explain why on the talk page. |
Syntax
minetest.spawn_tree(pos, tree)
Description
pos
— positiontree
— treedef
Spawns an L-system tree at position pos
, using the tree definition tree
.
See Introduction to L-system trees for a description of L-system trees.
Example
This code adds the chat command "/spawn_tree" to spawn an apple tree with its origin at the current position of the player, assuming that Minetest Game is used:
local treedef = {
axiom="FFFFFAFFBF",
rules_a="[&&&FFFFF&&FFFF][&&&++++FFFFF&&FFFF][&&&----FFFFF&&FFFF]",
rules_b="[&&&++FFFFF&&FFFF][&&&--FFFFF&&FFFF][&&&------FFFFF&&FFFF]",
trunk="default:tree",
leaves="default:leaves",
angle=30,
iterations=2,
random_level=0,
trunk_type="single",
thin_branches=true,
fruit_chance=10,
fruit="default:apple"
}
core.register_chatcommand("spawn_tree", {
params = "", description = "Spawns tree at player position",
func = function(name, param)
local pos = minetest.get_player_by_name(name):getpos()
minetest.chat_send_player(name, "Spawning tree at " .. minetest.pos_to_string(pos)
.. ", please wait")
minetest.spawn_tree(pos, treedef)
return true, "successfully spawned"
end,
})
The resulting tree may look like this:
Notes
- For examples, go to L-system tree examples
- VanessaE's plants_lib mod (github) provides functions to register L-system trees to be spawned during map generation, and finds places for them to spawn based on the map seed and biome.
- L-System Tree Utility is a mod which helps to create L-system trees in-game