birch.lua 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. moretrees = moretrees or {}
  2. local SAPLING_TIME_MIN = 60*15
  3. local SAPLING_TIME_MAX = 60*30
  4. local SAPLING_CHANCE = 40
  5. local SCHEMATIC_MINP = {x=-3, y=0, z=-3}
  6. local SCHEMATIC_MAXP = {x=3, y=11, z=3}
  7. local SCHEMATIC_RELP = {x=-3, y=0, z=-3}
  8. -- Localize for performance.
  9. local math_random = math.random
  10. minetest.register_node("moretrees:birch_tree", {
  11. drawtype = "nodebox",
  12. paramtype = "light",
  13. node_box = {
  14. type = "fixed",
  15. fixed = basictrees.trunk_nodebox,
  16. },
  17. description = "Birch Tree",
  18. tiles = {
  19. "moretrees_birch_trunk_top.png",
  20. "moretrees_birch_trunk_top.png",
  21. "moretrees_birch_trunk.png"
  22. },
  23. paramtype2 = "facedir",
  24. groups = moretrees.tree_groups,
  25. sounds = default.node_sound_wood_defaults(),
  26. on_place = minetest.rotate_node,
  27. movement_speed_multiplier = default.NORM_SPEED,
  28. on_destruct = enhanced_leafdecay.make_tree_destructor({
  29. leaves = {
  30. "moretrees:birch_leaves",
  31. "group:dry_leaves",
  32. },
  33. }),
  34. })
  35. minetest.register_node("moretrees:birch_leaves", {
  36. description = "Birch Leaves",
  37. drawtype = "allfaces_optional",
  38. visual_scale = 1.3,
  39. tiles = {"moretrees_birch_leaves.png"},
  40. paramtype = "light",
  41. groups = moretrees.leaves_groups,
  42. drop = moretrees.get_leafdrop_table(SAPLING_CHANCE, "moretrees:birch_sapling", "moretrees:birch_leaves"),
  43. sounds = default.node_sound_leaves_defaults(),
  44. waving = 1,
  45. movement_speed_multiplier = default.SLOW_SPEED,
  46. on_construct = enhanced_leafdecay.make_leaf_constructor({}),
  47. on_timer = enhanced_leafdecay.make_leaf_nodetimer({
  48. tree = "moretrees:birch_tree",
  49. }),
  50. })
  51. minetest.register_node("moretrees:birch_wood", {
  52. description = "Birch Planks",
  53. paramtype2 = "facedir",
  54. place_param2 = 0,
  55. tiles = {"moretrees_birch_wood.png"},
  56. groups = moretrees.get_wood_groups({wood_light = 1}),
  57. sounds = default.node_sound_wood_defaults(),
  58. })
  59. minetest.register_node("moretrees:birch_sapling", {
  60. description = "Birch Sapling\n\nWill not grow in deep caves.",
  61. drawtype = "plantlike",
  62. --visual_scale = 1.0,
  63. tiles = {"moretrees_birch_sapling.png"},
  64. paramtype = "light",
  65. sunlight_propagates = true,
  66. walkable = false,
  67. selection_box = moretrees.sapling_selection_box,
  68. groups = moretrees.sapling_groups,
  69. sounds = default.node_sound_leaves_defaults(),
  70. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  71. on_timer = function(pos, elapsed)
  72. if mtflower.can_grow(pos) then
  73. if mtflower.try_grow(pos, "moretrees:birch_tree", "moretrees:birch_leaves", "glowstone:minerals", "glowstone:minerals") then
  74. return
  75. end
  76. end
  77. if not moretrees.can_grow(pos) then
  78. minetest.get_node_timer(pos):start(math_random(SAPLING_TIME_MIN, SAPLING_TIME_MAX))
  79. return
  80. end
  81. minetest.set_node(pos, {name='air'}) -- Remove sapling first.
  82. local path = moretrees.modpath .. "/schematics/birch.mts"
  83. minetest.place_schematic(vector.add(vector.add(pos, {x=0, y=math_random(-1, 1), z=0}), SCHEMATIC_RELP), path, "random", nil, false)
  84. trunkgen.check_trunk(pos, 3, "moretrees:birch_tree")
  85. hb4.leafscatter.remove(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, "moretrees:birch_leaves", math_random(10, 30))
  86. hb4.leafscatter.add(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, "moretrees:birch_leaves", math_random(10, 30))
  87. snowscatter.dump_snowdust_on_tree(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP)
  88. ambiance.spawn_sound_beacon_inside_area("soundbeacon:trees", pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, 40, 3)
  89. end,
  90. on_construct = function(pos)
  91. minetest.get_node_timer(pos):start(math_random(SAPLING_TIME_MIN, SAPLING_TIME_MAX))
  92. end,
  93. on_place = function(itemstack, placer, pointed_thing)
  94. itemstack = default.sapling_on_place(itemstack, placer, pointed_thing,
  95. "moretrees:birch_sapling", SCHEMATIC_MINP, SCHEMATIC_MAXP, 4)
  96. return itemstack
  97. end,
  98. })
  99. minetest.register_craft({
  100. output = 'moretrees:birch_wood 4',
  101. recipe = {
  102. {'moretrees:birch_tree'},
  103. }
  104. })
  105. minetest.register_craft({
  106. output = "default:fence_wood 4",
  107. recipe = {
  108. {"moretrees:birch_wood", 'group:stick', "moretrees:birch_wood"},
  109. {"moretrees:birch_wood", 'group:stick', "moretrees:birch_wood"},
  110. }
  111. })
  112. minetest.register_craft({
  113. output = "doors:gate_wood_closed",
  114. recipe = {
  115. {"group:stick", "moretrees:birch_wood", "group:stick"},
  116. {"group:stick", "moretrees:birch_wood", "group:stick"}
  117. }
  118. })
  119. stairs.register_stair_and_slab(
  120. "birch",
  121. "moretrees:birch_wood",
  122. moretrees.stair_groups,
  123. {"moretrees_birch_wood.png"},
  124. "Birch Plank",
  125. default.node_sound_wood_defaults()
  126. )