oak.lua 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. if not minetest.global_exists("moretrees") then moretrees = {} end
  2. local SAPLING_TIME_MIN = 60*10
  3. local SAPLING_TIME_MAX = 60*15
  4. local SAPLING_CHANCE = 40
  5. local SCHEMATIC_MINP = {x=-4, y=0, z=-4}
  6. local SCHEMATIC_MAXP = {x=4, y=12, z=4}
  7. local SCHEMATIC_RELP = {x=-4, y=0, z=-4}
  8. -- Localize for performance.
  9. local math_random = math.random
  10. minetest.register_node("moretrees:oak_tree", {
  11. drawtype = "nodebox",
  12. paramtype = "light",
  13. node_box = {
  14. type = "fixed",
  15. fixed = basictrees.trunk_nodebox,
  16. },
  17. description = "Oak Tree",
  18. tiles = {
  19. "moretrees_oak_trunk_top.png",
  20. "moretrees_oak_trunk_top.png",
  21. "moretrees_oak_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:oak_leaves",
  31. "moretrees:oak_acorn",
  32. "group:dry_leaves",
  33. },
  34. }),
  35. })
  36. minetest.register_node("moretrees:oak_leaves", {
  37. description = "Oak Leaves",
  38. drawtype = "allfaces_optional",
  39. waving = 1,
  40. tiles = {"moretrees_oak_leaves.png"},
  41. paramtype = "light",
  42. groups = moretrees.leaves_groups,
  43. drop = moretrees.get_leafdrop_table(SAPLING_CHANCE, "moretrees:oak_sapling", "moretrees:oak_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:oak_tree"}),
  48. })
  49. minetest.register_node("moretrees:oak_wood", {
  50. description = "Oak Planks",
  51. paramtype2 = "facedir",
  52. place_param2 = 0,
  53. tiles = {"moretrees_oak_wood.png"},
  54. groups = moretrees.get_wood_groups({wood_light = 1}),
  55. sounds = default.node_sound_wood_defaults(),
  56. })
  57. minetest.register_node("moretrees:oak_sapling", {
  58. description = "Oak Sapling\n\nWill not grow in deep caves.\nGrows acorns.",
  59. drawtype = "plantlike",
  60. tiles = {"moretrees_oak_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:oak_tree", "moretrees:oak_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/oak.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:oak_tree")
  82. hb4.leafscatter.remove(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, "moretrees:oak_leaves", math_random(10, 30))
  83. hb4.leafscatter.add(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, "moretrees:oak_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:oak_leaves",
  89. "moretrees:oak_acorn",
  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:oak_sapling", SCHEMATIC_MINP, SCHEMATIC_MAXP, 4)
  101. return itemstack
  102. end,
  103. })
  104. minetest.register_node("moretrees:oak_acorn", {
  105. description = "Acorn",
  106. drawtype = "plantlike",
  107. visual_scale = 0.8,
  108. tiles = {"moretrees_acorn.png"},
  109. inventory_image = "moretrees_acorn.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. -- Nuts do not rot.
  118. groups = {fleshy=3, dig_immediate=3, flammable=2, leafdecay=3, leafdecay_drop=1},
  119. sounds = default.node_sound_defaults(),
  120. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  121. on_construct = enhanced_leafdecay.make_leaf_constructor({}),
  122. on_timer = enhanced_leafdecay.make_leaf_nodetimer({tree="moretrees:oak_tree"}),
  123. after_dig_node = hb4.fruitregrow.after_dig_node(),
  124. after_place_node = hb4.fruitregrow.after_place_node(),
  125. on_finish_collapse = hb4.fruitregrow.on_finish_collapse(),
  126. })
  127. minetest.register_craftitem("moretrees:acorn_muffin_batter", {
  128. description = "Acorn Muffin batter",
  129. inventory_image = "moretrees_acorn_muffin_batter.png",
  130. groups = {foodrot=1},
  131. })
  132. local eat_function = minetest.item_eat(4)
  133. minetest.register_craftitem("moretrees:acorn_muffin", {
  134. description = "Acorn Muffin\n\nImproves health regeneration for a period of time.",
  135. inventory_image = "moretrees_acorn_muffin.png",
  136. groups = {foodrot=1},
  137. on_use = function(itemstack, user, pointed_thing)
  138. if not user or not user:is_player() then return end
  139. -- 3 times (300%) faster than normal.
  140. hunger.apply_hpgen_boost(user:get_player_name(), "muffin", {regen=3, time=(HUNGER_HEALTH_TICK * 10)})
  141. return eat_function(itemstack, user, pointed_thing)
  142. end,
  143. })
  144. minetest.register_craft({
  145. type = "shapeless",
  146. output = "moretrees:acorn_muffin_batter",
  147. recipe = {
  148. "moretrees:oak_acorn",
  149. "moretrees:oak_acorn",
  150. "moretrees:oak_acorn",
  151. "moretrees:oak_acorn",
  152. "moretrees:coconut_milk",
  153. },
  154. replacements = {
  155. { "moretrees:coconut_milk", "vessels:drinking_glass" },
  156. },
  157. })
  158. minetest.register_craft({
  159. type = "cooking",
  160. output = "moretrees:acorn_muffin 4",
  161. recipe = "moretrees:acorn_muffin_batter",
  162. })
  163. minetest.register_craft({
  164. output = 'moretrees:oak_wood 4',
  165. recipe = {
  166. {'moretrees:oak_tree'},
  167. }
  168. })
  169. minetest.register_craft({
  170. output = "default:fence_wood 4",
  171. recipe = {
  172. {"moretrees:oak_wood", 'group:stick', "moretrees:oak_wood"},
  173. {"moretrees:oak_wood", 'group:stick', "moretrees:oak_wood"},
  174. }
  175. })
  176. minetest.register_craft({
  177. output = "doors:gate_wood_closed",
  178. recipe = {
  179. {"techcrafts:hinge_wood", "moretrees:oak_wood", "group:stick"},
  180. {"group:stick", "moretrees:oak_wood", "group:stick"}
  181. }
  182. })
  183. stairs.register_stair_and_slab(
  184. "oak",
  185. "moretrees:oak_wood",
  186. moretrees.stair_groups,
  187. {"moretrees_oak_wood.png"},
  188. "Oak Plank",
  189. default.node_sound_wood_defaults()
  190. )