seeds.lua 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. local modname = minetest.get_current_modname()
  2. local modpath = minetest.get_modpath(modname)
  3. local S = minetest.get_translator(modname)
  4. --localize stuff for performance
  5. local random = math.random
  6. local spawn_tree = minetest.spawn_tree
  7. local get_node_timer = minetest.get_node_timer
  8. local remove_node = minetest.remove_node
  9. local place_schematic = minetest.place_schematic
  10. local schematics =
  11. {
  12. modpath .. "/schematics/little_tree.mts",
  13. modpath .. "/schematics/palm_tree.mts",
  14. modpath .. "/schematics/spruce.mts",
  15. modpath .. "/schematics/tree1.mts",
  16. modpath .. "/schematics/tree2.mts",
  17. }
  18. local treedefs =
  19. {
  20. }
  21. local schem_count = #schematics
  22. local l_system_count = #treedefs
  23. minetest.register_node(modname .. ":sapling",
  24. {
  25. description = S("Sapling"),
  26. drawtype = "mesh",
  27. mesh = modname .. "_sapling.obj",
  28. tiles = {modname .. "_leaves.png", modname .. "_wood_sides.png"},
  29. groups = {dig_immediate = 2, attached_node = 1},
  30. paramtype = "light",
  31. walkable = false,
  32. is_ground_content = false,
  33. selection_box =
  34. {
  35. type = "fixed",
  36. fixed =
  37. {
  38. {-0.125, -0.5, -0.125, 0.125, 0.125, 0.125}
  39. }
  40. },
  41. on_construct = function(pos)
  42. local timer = get_node_timer(pos)
  43. timer:start(random(120, 1200)) --TODO: make settings
  44. end,
  45. on_timer = function(pos, elapsed)
  46. --delete sapling
  47. remove_node(pos)
  48. local index = random(schem_count + l_system_count)
  49. if index > schem_count
  50. then
  51. --place l-system
  52. spawn_tree(pos, treedefs[index - schem_count])
  53. else
  54. --place schematic
  55. local schem = schematics[index]
  56. place_schematic(pos, schem, "random", nil, false, "place_center_x, place_center_z")
  57. end
  58. end
  59. })