cedar.lua 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. if not minetest.global_exists("moretrees") then moretrees = {} end
  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. tiles = {"moretrees_cedar_leaves.png"},
  40. paramtype = "light",
  41. waving = 1,
  42. groups = moretrees.leaves_groups,
  43. drop = moretrees.get_leafdrop_table(SAPLING_CHANCE, "moretrees:cedar_sapling", "moretrees:cedar_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({
  48. tree = "moretrees:cedar_tree",
  49. }),
  50. })
  51. minetest.register_node("moretrees:cedar_wood", {
  52. description = "Cedar Planks",
  53. paramtype2 = "facedir",
  54. place_param2 = 0,
  55. tiles = {"moretrees_cedar_wood.png"},
  56. groups = moretrees.get_wood_groups({wood_light = 1}),
  57. sounds = default.node_sound_wood_defaults(),
  58. })
  59. minetest.register_node("moretrees:cedar_sapling", {
  60. description = "Cedar Sapling\n\nWill not grow in deep caves.\nGrows nuts.",
  61. drawtype = "plantlike",
  62. tiles = {"moretrees_cedar_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:cedar_tree", "moretrees:cedar_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/cedar.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:cedar_tree")
  84. hb4.leafscatter.remove(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, "moretrees:cedar_leaves", math_random(10, 30))
  85. hb4.leafscatter.add(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, "moretrees:cedar_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:cedar_leaves",
  91. "moretrees:cedar_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:cedar_sapling", SCHEMATIC_MINP, SCHEMATIC_MAXP, 4)
  103. return itemstack
  104. end,
  105. })
  106. minetest.register_node("moretrees:cedar_cone", {
  107. description = "Cedar Cone",
  108. drawtype = "plantlike",
  109. visual_scale = 0.8,
  110. tiles = {"moretrees_cedar_cone.png"},
  111. inventory_image = "moretrees_cedar_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:cedar_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:cedar_nuts", {
  129. description = "Roasted Cedar Cone Nuts",
  130. inventory_image = "moretrees_cedar_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:cedar_nuts 4",
  137. recipe = "moretrees:cedar_cone",
  138. })
  139. minetest.register_craft({
  140. output = 'moretrees:cedar_wood 4',
  141. recipe = {
  142. {'moretrees:cedar_tree'},
  143. }
  144. })
  145. minetest.register_craft({
  146. output = "default:fence_wood 4",
  147. recipe = {
  148. {"moretrees:cedar_wood", 'group:stick', "moretrees:cedar_wood"},
  149. {"moretrees:cedar_wood", 'group:stick', "moretrees:cedar_wood"},
  150. }
  151. })
  152. minetest.register_craft({
  153. output = "doors:gate_wood_closed",
  154. recipe = {
  155. {"techcrafts:hinge_wood", "moretrees:cedar_wood", "group:stick"},
  156. {"group:stick", "moretrees:cedar_wood", "group:stick"}
  157. }
  158. })
  159. stairs.register_stair_and_slab(
  160. "cedar",
  161. "moretrees:cedar_wood",
  162. moretrees.stair_groups,
  163. {"moretrees_cedar_wood.png"},
  164. "Cedar Plank",
  165. default.node_sound_wood_defaults()
  166. )