spruce.lua 6.0 KB

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