tree.lua 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. ---@meta
  2. ---Tree definition
  3. ------------------
  4. --[[ Example:
  5. Spawn a small apple tree:
  6. pos = {x=230,y=20,z=4}
  7. apple_tree={
  8. axiom="FFFFFAFFBF",
  9. rules_a="[&&&FFFFF&&FFFF][&&&++++FFFFF&&FFFF][&&&----FFFFF&&FFFF]",
  10. rules_b="[&&&++FFFFF&&FFFF][&&&--FFFFF&&FFFF][&&&------FFFFF&&FFFF]",
  11. trunk="default:tree",
  12. leaves="default:leaves",
  13. angle=30,
  14. iterations=2,
  15. random_level=0,
  16. trunk_type="single",
  17. thin_branches=true,
  18. fruit_chance=10,
  19. fruit="default:apple"
  20. }
  21. minetest.spawn_tree(pos,apple_tree)
  22. ]]
  23. ---@class mt.TreeDef
  24. ---@field axiom mt.TreeAxioms Initial tree axiom.
  25. ---@field rules_a mt.TreeAxioms Rules set A.
  26. ---@field rules_b mt.TreeAxioms Rules set B.
  27. ---@field rules_c mt.TreeAxioms Rules set C.
  28. ---@field rules_d mt.TreeAxioms Rules set D.
  29. ---@field trunk string Trunk node name.
  30. ---@field leaves string Leaves node name.
  31. ---@field leaves2 string Secondary leaves node name.
  32. ---@field leaves2_chance number Chance (0-100) to replace leaves with leaves2.
  33. ---@field angle number Angle in deg.
  34. ---@field iterations number Max number of iterations, usually 2-5.
  35. ---@field random_level number Factor to lower number of iterations, usually 0-3.
  36. -- Type of trunk: 1 node, 2x2 nodes or 3x3 in cross shape.
  37. ---@field trunk_type "single"|"double"|"crossed"
  38. ---@field thin_branches boolean
  39. ---@field fruit string Fruit node name.
  40. ---@field fruit_chance number Chance (0-100) to replace leaves with fruit node.
  41. ---@field seed number Seed, if no seed is provided, the engine will create one.
  42. --[[ Key for special L-System symbols used in axioms:
  43. - `G`: Move forward one unit with the pen up.
  44. - `F`: Move forward one unit with the pen down drawing trunks and branches.
  45. - `f`: Move forward one unit with the pen down drawing leaves (100% chance).
  46. - `T`: Move forward one unit with the pen down drawing trunks only.
  47. - `R`: Move forward one unit with the pen down placing fruit.
  48. - `A`: Replace with rules set A.
  49. - `B`: Replace with rules set B.
  50. - `C`: Replace with rules set C.
  51. - `D`: Replace with rules set D.
  52. - `a`: Replace with rules set A, chance 90%.
  53. - `b`: Replace with rules set B, chance 80%.
  54. - `c`: Replace with rules set C, chance 70%.
  55. - `d`: Replace with rules set D, chance 60%.
  56. - `+`: Yaw the turtle right by `angle` parameter.
  57. - `-`: Yaw the turtle left by `angle` parameter.
  58. - `&`: Pitch the turtle down by `angle` parameter.
  59. - `^`: Pitch the turtle up by `angle` parameter.
  60. - `/`: Roll the turtle to the right by `angle` parameter.
  61. - `*`: Roll the turtle to the left by `angle` parameter.
  62. - `[`: Save in stack current state info.
  63. - `]`: Recover from stack state info.
  64. ]]
  65. ---@alias mt.TreeAxioms string