minetest.spawn_tree

From Minetest Developer Wiki
Revision as of 18:14, 6 February 2015 by Wuzzy (talk | contribs) (Add example)
Jump to navigation Jump to search

Syntax

minetest.spawn_tree(pos, tree)

Description

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 will spawn an apple tree with its origin at position (0,0,0), 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"
}

local pos = { x=0, y=0, z=0 }

minetest.spawn_tree(pos, treedef)

The resulting tree may look like this:

Apple Tree.png


Notes

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.