sapling.lua 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. local S = ethereal.intllib
  2. -- Bamboo Sprout
  3. minetest.register_node("ethereal:bamboo_sprout", {
  4. description = S("Bamboo Sprout"),
  5. drawtype = "plantlike",
  6. tiles = {"bamboo_sprout.png"},
  7. inventory_image = "bamboo_sprout.png",
  8. wield_image = "bamboo_sprout.png",
  9. paramtype = "light",
  10. sunlight_propagates = true,
  11. walkable = false,
  12. groups = {
  13. food_bamboo_sprout = 1, snappy = 3, attached_node = 1, flammable = 2,
  14. dig_immediate = 3, ethereal_sapling = 1, sapling = 1,
  15. },
  16. sounds = default.node_sound_defaults(),
  17. selection_box = {
  18. type = "fixed",
  19. fixed = {-4 / 16, -0.5, -4 / 16, 4 / 16, 0, 4 / 16}
  20. },
  21. on_use = minetest.item_eat(2),
  22. grown_height = 11,
  23. })
  24. -- Register Saplings
  25. local register_sapling = function(name, desc, texture, height)
  26. minetest.register_node(name .. "_sapling", {
  27. description = S(desc .. " Tree Sapling"),
  28. drawtype = "plantlike",
  29. tiles = {texture .. ".png"},
  30. inventory_image = texture .. ".png",
  31. wield_image = texture .. ".png",
  32. paramtype = "light",
  33. sunlight_propagates = true,
  34. is_ground_content = false,
  35. walkable = false,
  36. selection_box = {
  37. type = "fixed",
  38. fixed = {-4 / 16, -0.5, -4 / 16, 4 / 16, 7 / 16, 4 / 16}
  39. },
  40. groups = {
  41. snappy = 2, dig_immediate = 3, flammable = 2,
  42. ethereal_sapling = 1, attached_node = 1, sapling = 1
  43. },
  44. sounds = default.node_sound_leaves_defaults(),
  45. grown_height = height,
  46. })
  47. end
  48. register_sapling("ethereal:willow", "Willow", "willow_sapling", 14)
  49. register_sapling("ethereal:yellow_tree", "Healing", "yellow_tree_sapling", 19)
  50. register_sapling("ethereal:big_tree", "Big", "ethereal_big_tree_sapling", 7)
  51. register_sapling("ethereal:banana_tree", "Banana", "banana_tree_sapling", 8)
  52. register_sapling("ethereal:frost_tree", "Frost", "ethereal_frost_tree_sapling", 19)
  53. register_sapling("ethereal:mushroom", "Mushroom", "ethereal_mushroom_sapling", 11)
  54. register_sapling("ethereal:palm", "Palm", "moretrees_palm_sapling", 9)
  55. register_sapling("ethereal:redwood", "Redwood", "redwood_sapling", 31)
  56. register_sapling("ethereal:orange_tree", "Orange", "orange_tree_sapling", 6)
  57. register_sapling("ethereal:birch", "Birch", "moretrees_birch_sapling", 7)
  58. register_sapling("ethereal:sakura", "Sakura", "ethereal_sakura_sapling", 10)
  59. local add_tree = function (pos, ofx, ofy, ofz, schem, replace)
  60. -- check for schematic
  61. if not schem then
  62. print (S("Schematic not found"))
  63. return
  64. end
  65. -- remove sapling and place schematic
  66. minetest.swap_node(pos, {name = "air"})
  67. minetest.place_schematic(
  68. {x = pos.x - ofx, y = pos.y - ofy, z = pos.z - ofz},
  69. schem, 0, replace, false)
  70. end
  71. local path = minetest.get_modpath("ethereal") .. "/schematics/"
  72. -- grow tree functions
  73. function ethereal.grow_yellow_tree(pos)
  74. add_tree(pos, 4, 0, 4, ethereal.yellowtree)
  75. end
  76. function ethereal.grow_big_tree(pos)
  77. add_tree(pos, 4, 0, 4, ethereal.bigtree)
  78. end
  79. function ethereal.grow_banana_tree(pos)
  80. add_tree(pos, 3, 0, 3, ethereal.bananatree)
  81. end
  82. function ethereal.grow_frost_tree(pos)
  83. add_tree(pos, 4, 0, 4, ethereal.frosttrees)
  84. end
  85. function ethereal.grow_mushroom_tree(pos)
  86. add_tree(pos, 4, 0, 4, ethereal.mushroomone)
  87. end
  88. function ethereal.grow_palm_tree(pos)
  89. add_tree(pos, 4, 0, 4, ethereal.palmtree)
  90. end
  91. function ethereal.grow_willow_tree(pos)
  92. add_tree(pos, 5, 0, 5, ethereal.willow)
  93. end
  94. function ethereal.grow_redwood_tree(pos)
  95. add_tree(pos, 7, 0, 7, ethereal.redwood_tree)
  96. end
  97. function ethereal.grow_orange_tree(pos)
  98. add_tree(pos, 1, 0, 1, ethereal.orangetree)
  99. end
  100. function ethereal.grow_bamboo_tree(pos)
  101. add_tree(pos, 1, 0, 1, ethereal.bambootree)
  102. end
  103. function ethereal.grow_birch_tree(pos)
  104. add_tree(pos, 2, 0, 2, ethereal.birchtree)
  105. end
  106. function ethereal.grow_sakura_tree(pos)
  107. if math.random(10) == 1 then
  108. add_tree(pos, 4, 0, 3, ethereal.sakura_tree,
  109. {{"ethereal:sakura_leaves", "ethereal:sakura_leaves2"}})
  110. else
  111. add_tree(pos, 4, 0, 3, ethereal.sakura_tree)
  112. end
  113. end
  114. -- check if sapling has enough height room to grow
  115. local enough_height = function(pos, height)
  116. local nod = minetest.line_of_sight(
  117. {x = pos.x, y = pos.y + 1, z = pos.z},
  118. {x = pos.x, y = pos.y + height, z = pos.z})
  119. if not nod then
  120. return false -- obstructed
  121. else
  122. return true -- can grow
  123. end
  124. end
  125. local grow_sapling = function(pos, node)
  126. local under = minetest.get_node({
  127. x = pos.x,
  128. y = pos.y - 1,
  129. z = pos.z
  130. }).name
  131. if not minetest.registered_nodes[node.name] then
  132. return
  133. end
  134. local height = minetest.registered_nodes[node.name].grown_height
  135. -- do we have enough height to grow sapling into tree?
  136. if not height or not enough_height(pos, height) then
  137. return
  138. end
  139. -- Check if Ethereal Sapling is growing on correct substrate
  140. if node.name == "ethereal:yellow_tree_sapling"
  141. and minetest.get_item_group(under, "soil") > 0 then
  142. ethereal.grow_yellow_tree(pos)
  143. elseif node.name == "ethereal:big_tree_sapling"
  144. and under == "default:dirt_with_grass" then
  145. ethereal.grow_big_tree(pos)
  146. elseif node.name == "ethereal:banana_tree_sapling"
  147. and under == "ethereal:grove_dirt" then
  148. ethereal.grow_banana_tree(pos)
  149. elseif node.name == "ethereal:frost_tree_sapling"
  150. and under == "ethereal:crystal_dirt" then
  151. ethereal.grow_frost_tree(pos)
  152. elseif node.name == "ethereal:mushroom_sapling"
  153. and under == "ethereal:mushroom_dirt" then
  154. ethereal.grow_mushroom_tree(pos)
  155. elseif node.name == "ethereal:palm_sapling"
  156. and under == "default:sand" then
  157. ethereal.grow_palm_tree(pos)
  158. elseif node.name == "ethereal:willow_sapling"
  159. and under == "ethereal:gray_dirt" then
  160. ethereal.grow_willow_tree(pos)
  161. elseif node.name == "ethereal:redwood_sapling"
  162. and under == "default:dirt_with_dry_grass" then
  163. ethereal.grow_redwood_tree(pos)
  164. elseif node.name == "ethereal:orange_tree_sapling"
  165. and under == "ethereal:prairie_dirt" then
  166. ethereal.grow_orange_tree(pos)
  167. elseif node.name == "ethereal:bamboo_sprout"
  168. and under == "ethereal:bamboo_dirt" then
  169. ethereal.grow_bamboo_tree(pos)
  170. elseif node.name == "ethereal:birch_sapling"
  171. and under == "default:dirt_with_grass" then
  172. ethereal.grow_birch_tree(pos)
  173. elseif node.name == "ethereal:sakura_sapling"
  174. and under == "ethereal:bamboo_dirt" then
  175. ethereal.grow_sakura_tree(pos)
  176. end
  177. end
  178. -- Grow saplings
  179. minetest.register_abm({
  180. label = "Ethereal grow sapling",
  181. nodenames = {"group:ethereal_sapling"},
  182. interval = 10,
  183. chance = 50,
  184. catch_up = false,
  185. action = function(pos, node)
  186. local light_level = minetest.get_node_light(pos) or 0
  187. if light_level < 13 then
  188. return
  189. end
  190. grow_sapling(pos, node)
  191. end,
  192. })