cedar.lua 6.0 KB

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