tree.lua 5.0 KB

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