fir.lua 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. moretrees = moretrees or {}
  2. local SAPLING_TIME_MIN = 60*20
  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=14, 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:fir_tree", {
  11. drawtype = "nodebox",
  12. paramtype = "light",
  13. node_box = {
  14. type = "fixed",
  15. fixed = basictrees.trunk_nodebox,
  16. },
  17. description = "Fir Tree",
  18. tiles = {
  19. "moretrees_fir_trunk_top.png",
  20. "moretrees_fir_trunk_top.png",
  21. "moretrees_fir_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:fir_leaves",
  31. "moretrees:fir_cone",
  32. "group:dry_leaves",
  33. },
  34. }),
  35. })
  36. minetest.register_node("moretrees:fir_leaves", {
  37. description = "Fir Leaves",
  38. drawtype = "allfaces_optional",
  39. visual_scale = 1.3,
  40. tiles = {"moretrees_fir_leaves.png"},
  41. paramtype = "light",
  42. groups = moretrees.leaves_groups,
  43. drop = moretrees.get_leafdrop_table(SAPLING_CHANCE, "moretrees:fir_sapling", "moretrees:fir_leaves"),
  44. sounds = default.node_sound_leaves_defaults(),
  45. waving = 1,
  46. movement_speed_multiplier = default.SLOW_SPEED,
  47. on_construct = enhanced_leafdecay.make_leaf_constructor({}),
  48. on_timer = enhanced_leafdecay.make_leaf_nodetimer({tree="moretrees:fir_tree"}),
  49. })
  50. minetest.register_node("moretrees:fir_wood", {
  51. description = "Fir Planks",
  52. paramtype2 = "facedir",
  53. place_param2 = 0,
  54. tiles = {"moretrees_fir_wood.png"},
  55. groups = moretrees.get_wood_groups({wood_light = 1}),
  56. sounds = default.node_sound_wood_defaults(),
  57. })
  58. minetest.register_node("moretrees:fir_sapling", {
  59. description = "Fir Sapling\n\nWill not grow in deep caves.\nGrows nuts.",
  60. drawtype = "plantlike",
  61. --visual_scale = 1.0,
  62. tiles = {"moretrees_fir_sapling.png"},
  63. paramtype = "light",
  64. sunlight_propagates = true,
  65. walkable = false,
  66. selection_box = moretrees.sapling_selection_box,
  67. groups = moretrees.sapling_groups,
  68. sounds = default.node_sound_leaves_defaults(),
  69. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  70. on_timer = function(pos, elapsed)
  71. if mtflower.can_grow(pos) then
  72. if mtflower.try_grow(pos, "moretrees:fir_tree", "moretrees:fir_leaves", "glowstone:minerals", "glowstone:minerals") then
  73. return
  74. end
  75. end
  76. if not moretrees.can_grow(pos) then
  77. minetest.get_node_timer(pos):start(math_random(SAPLING_TIME_MIN, SAPLING_TIME_MAX))
  78. return
  79. end
  80. minetest.set_node(pos, {name='air'}) -- Remove sapling first.
  81. local path = moretrees.modpath .. "/schematics/fir.mts"
  82. minetest.place_schematic(vector.add(vector.add(pos, {x=0, y=math_random(-1, 1), z=0}), SCHEMATIC_RELP), path, "random", nil, false)
  83. trunkgen.check_trunk(pos, 3, "moretrees:fir_tree")
  84. hb4.leafscatter.remove(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, "moretrees:fir_leaves", math_random(10, 30))
  85. hb4.leafscatter.add(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, "moretrees:fir_leaves", math_random(10, 30))
  86. snowscatter.dump_snowdust_on_tree(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP)
  87. ambiance.spawn_sound_beacon_inside_area("soundbeacon:trees", pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, 40, 3)
  88. fruitscatter.scatter_fruit_under_leaves(
  89. pos,
  90. "moretrees:fir_leaves",
  91. "moretrees:fir_cone",
  92. SCHEMATIC_MINP,
  93. SCHEMATIC_MAXP,
  94. math_random(6, 10)
  95. )
  96. end,
  97. on_construct = function(pos)
  98. minetest.get_node_timer(pos):start(math_random(SAPLING_TIME_MIN, SAPLING_TIME_MAX))
  99. end,
  100. on_place = function(itemstack, placer, pointed_thing)
  101. itemstack = default.sapling_on_place(itemstack, placer, pointed_thing,
  102. "moretrees:fir_sapling", SCHEMATIC_MINP, SCHEMATIC_MAXP, 4)
  103. return itemstack
  104. end,
  105. })
  106. minetest.register_node("moretrees:fir_cone", {
  107. description = "Fir Cone",
  108. drawtype = "plantlike",
  109. visual_scale = 0.8,
  110. tiles = {"moretrees_fir_cone.png"},
  111. inventory_image = "moretrees_fir_cone.png",
  112. paramtype = "light",
  113. sunlight_propagates = true,
  114. walkable = false,
  115. selection_box = {
  116. type = "fixed",
  117. fixed = {-0.2, -0.5, -0.2, 0.2, 0, 0.2},
  118. },
  119. groups = {fleshy=3, dig_immediate=3, flammable=2, leafdecay=3, leafdecay_drop=1},
  120. sounds = default.node_sound_defaults(),
  121. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  122. on_construct = enhanced_leafdecay.make_leaf_constructor({}),
  123. on_timer = enhanced_leafdecay.make_leaf_nodetimer({tree="moretrees:fir_tree"}),
  124. after_dig_node = hb4.fruitregrow.after_dig_node(),
  125. after_place_node = hb4.fruitregrow.after_place_node(),
  126. on_finish_collapse = hb4.fruitregrow.on_finish_collapse(),
  127. })
  128. minetest.register_craftitem("moretrees:fir_nuts", {
  129. description = "Roasted Fir Cone Nuts",
  130. inventory_image = "moretrees_fir_nuts.png",
  131. on_use = minetest.item_eat(1),
  132. -- Nuts do not rot.
  133. })
  134. minetest.register_craft({
  135. type = "cooking",
  136. output = "moretrees:fir_nuts 4",
  137. recipe = "moretrees:fir_cone",
  138. })
  139. minetest.register_craft({
  140. output = 'moretrees:fir_wood 4',
  141. recipe = {
  142. {'moretrees:fir_tree'},
  143. }
  144. })
  145. minetest.register_craft({
  146. output = "default:fence_wood 4",
  147. recipe = {
  148. {"moretrees:fir_wood", 'group:stick', "moretrees:fir_wood"},
  149. {"moretrees:fir_wood", 'group:stick', "moretrees:fir_wood"},
  150. }
  151. })
  152. minetest.register_craft({
  153. output = "doors:gate_wood_closed",
  154. recipe = {
  155. {"group:stick", "moretrees:fir_wood", "group:stick"},
  156. {"group:stick", "moretrees:fir_wood", "group:stick"}
  157. }
  158. })
  159. stairs.register_stair_and_slab(
  160. "fir",
  161. "moretrees:fir_wood",
  162. moretrees.stair_groups,
  163. {"moretrees_fir_wood.png"},
  164. "Fir Plank",
  165. default.node_sound_wood_defaults()
  166. )