tree.lua 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. basictrees = basictrees or {}
  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=1, 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. minetest.register_node("basictrees:tree_leaves", {
  97. description = "Tree Leaves",
  98. drawtype = "allfaces_optional",
  99. waving = 1,
  100. visual_scale = 1.3,
  101. tiles = {"default_leaves.png"},
  102. --special_tiles = {"default_leaves_simple.png"},
  103. paramtype = "light",
  104. groups = basictrees.leaves_groups,
  105. drop = basictrees.get_leafdrop_table(SAPLING_CHANCE, "basictrees:tree_sapling", "basictrees:tree_leaves"),
  106. sounds = default.node_sound_leaves_defaults(),
  107. movement_speed_multiplier = default.SLOW_SPEED,
  108. on_construct = enhanced_leafdecay.make_leaf_constructor({}),
  109. on_timer = enhanced_leafdecay.make_leaf_nodetimer({tree="basictrees:tree_trunk"}),
  110. })
  111. -- Sappling crafts.
  112. minetest.register_craft({
  113. output = 'basictrees:tree_sapling',
  114. recipe = {
  115. {'default:mossycobble', 'default:sand', 'default:gravel' },
  116. {'default:dirt', 'default:junglegrass', 'default:dirt' },
  117. {'default:gravel', 'default:sand', 'default:mossycobble' },
  118. }
  119. })
  120. minetest.register_craft({
  121. output = 'basictrees:tree_wood 4',
  122. recipe = {
  123. {'basictrees:tree_trunk'},
  124. }
  125. })
  126. minetest.register_craft({
  127. output = 'basictrees:tree_wood 4',
  128. recipe = {
  129. {'basictrees:tree_trunk_dead'},
  130. }
  131. })
  132. -- Aliases for compatibility.
  133. minetest.register_alias("default:tree", "basictrees:tree_trunk")
  134. minetest.register_alias("default:sapling", "basictrees:tree_sapling")
  135. minetest.register_alias("default:wood", "basictrees:tree_wood")
  136. minetest.register_alias("default:leaves", "basictrees:tree_leaves")
  137. minetest.register_alias("default:apple", "basictrees:tree_apple")