tree.lua 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. if not minetest.global_exists("basictrees") then basictrees = {} end
  2. local SAPLING_TIME_MIN = 60*10
  3. local SAPLING_TIME_MAX = 60*20
  4. local SAPLING_CHANCE = 20
  5. local SCHEMATIC_MINP = {x=-2, y=0, z=-2}
  6. local SCHEMATIC_MAXP = {x=2, y=6, z=2}
  7. local SCHEMATIC_RELP = {x=-2, y=-1, z=-2}
  8. -- Localize for performance.
  9. local math_random = math.random
  10. minetest.register_node("basictrees:tree_trunk", {
  11. drawtype = "nodebox",
  12. paramtype = "light",
  13. node_box = {
  14. type = "fixed",
  15. fixed = basictrees.trunk_nodebox,
  16. },
  17. description = "Tree",
  18. tiles = {"default_tree_top.png", "default_tree_top.png", "default_tree.png"},
  19. paramtype2 = "facedir",
  20. groups = basictrees.tree_groups,
  21. sounds = default.node_sound_wood_defaults(),
  22. on_place = minetest.rotate_node,
  23. movement_speed_multiplier = default.NORM_SPEED,
  24. on_destruct = enhanced_leafdecay.make_tree_destructor({
  25. leaves = {
  26. "basictrees:tree_leaves",
  27. "basictrees:tree_apple",
  28. "group:dry_leaves",
  29. },
  30. }),
  31. })
  32. -- Note: dead tree must drop itself, not regular tree, because otherwise if player
  33. -- places the node, they won't be able to dig it by hand again, which will be
  34. -- confusing.
  35. minetest.register_node("basictrees:tree_trunk_dead", {
  36. drawtype = "nodebox",
  37. paramtype = "light",
  38. node_box = {
  39. type = "fixed",
  40. fixed = basictrees.trunk_nodebox,
  41. },
  42. description = "Dead Tree",
  43. tiles = {"default_tree_dead_top.png", "default_tree_dead_top.png", "default_tree_dead.png"},
  44. paramtype2 = "facedir",
  45. groups = basictrees.dead_tree_groups,
  46. sounds = default.node_sound_wood_defaults(),
  47. on_place = minetest.rotate_node,
  48. movement_speed_multiplier = default.NORM_SPEED,
  49. })
  50. minetest.register_node("basictrees:tree_sapling", {
  51. description = "Tree Sapling\n\nWill not grow in deep caves.\nGrows apples.",
  52. drawtype = "plantlike",
  53. tiles = {"default_sapling.png"},
  54. inventory_image = "default_sapling.png",
  55. wield_image = "default_sapling.png",
  56. paramtype = "light",
  57. sunlight_propagates = true,
  58. walkable = false,
  59. selection_box = basictrees.sapling_selection_box,
  60. groups = basictrees.sapling_groups,
  61. sounds = default.node_sound_leaves_defaults(),
  62. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  63. on_timer = function(pos)
  64. if mtflower.can_grow(pos) then
  65. if mtflower.try_grow(pos, "basictrees:tree_trunk", "basictrees:tree_leaves", "glowstone:minerals", "glowstone:minerals") then
  66. return
  67. end
  68. end
  69. if not basictrees.can_grow(pos) then
  70. minetest.get_node_timer(pos):start(math_random(SAPLING_TIME_MIN, SAPLING_TIME_MAX))
  71. return
  72. end
  73. local path = basictrees.modpath .. "/schematics/apple_tree_from_sapling.mts"
  74. minetest.place_schematic(vector.add(pos, SCHEMATIC_RELP),
  75. path, "random", nil, false)
  76. snowscatter.dump_snowdust_on_tree(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP)
  77. ambiance.spawn_sound_beacon_inside_area("soundbeacon:trees", pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, 40, 3)
  78. end,
  79. on_construct = function(pos)
  80. minetest.get_node_timer(pos):start(math_random(SAPLING_TIME_MIN, SAPLING_TIME_MAX))
  81. end,
  82. on_place = function(itemstack, placer, pointed_thing)
  83. itemstack = default.sapling_on_place(itemstack, placer, pointed_thing,
  84. "basictrees:tree_sapling", SCHEMATIC_MINP, SCHEMATIC_MAXP, 4)
  85. return itemstack
  86. end,
  87. })
  88. minetest.register_node("basictrees:tree_wood", {
  89. description = "Wooden Planks",
  90. paramtype2 = "facedir",
  91. place_param2 = 0,
  92. tiles = {"default_wood.png"},
  93. groups = basictrees.get_wood_groups({wood_light = 1}),
  94. sounds = default.node_sound_wood_defaults(),
  95. })
  96. -- drawtype = "plantlike"
  97. -- visual_scale = 1.4
  98. -- walkable = false ?
  99. -- climbable = true ?
  100. minetest.register_node("basictrees:tree_leaves", {
  101. description = "Tree Leaves",
  102. drawtype = "allfaces_optional",
  103. waving = 1,
  104. tiles = {"default_leaves.png"},
  105. paramtype = "light",
  106. groups = basictrees.leaves_groups,
  107. drop = basictrees.get_leafdrop_table(SAPLING_CHANCE, "basictrees:tree_sapling", "basictrees:tree_leaves"),
  108. sounds = default.node_sound_leaves_defaults(),
  109. movement_speed_multiplier = default.SLOW_SPEED,
  110. on_construct = enhanced_leafdecay.make_leaf_constructor({}),
  111. on_timer = enhanced_leafdecay.make_leaf_nodetimer({tree="basictrees:tree_trunk"}),
  112. })
  113. minetest.register_craft({
  114. output = 'basictrees:tree_wood 4',
  115. recipe = {
  116. {'basictrees:tree_trunk'},
  117. }
  118. })
  119. minetest.register_craft({
  120. output = 'basictrees:tree_wood 4',
  121. recipe = {
  122. {'basictrees:tree_trunk_dead'},
  123. }
  124. })
  125. -- Aliases for compatibility.
  126. minetest.register_alias("default:tree", "basictrees:tree_trunk")
  127. minetest.register_alias("default:sapling", "basictrees:tree_sapling")
  128. minetest.register_alias("default:wood", "basictrees:tree_wood")
  129. minetest.register_alias("default:leaves", "basictrees:tree_leaves")
  130. minetest.register_alias("default:apple", "basictrees:tree_apple")