sapling.lua 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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 = {"ethereal_bamboo_sprout.png"},
  7. inventory_image = "ethereal_bamboo_sprout.png",
  8. wield_image = "ethereal_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", "ethereal_willow_sapling", 14)
  49. register_sapling("ethereal:yellow_tree", "Healing", "ethereal_yellow_tree_sapling", 19)
  50. register_sapling("ethereal:big_tree", "Big", "ethereal_big_tree_sapling", 7)
  51. register_sapling("ethereal:banana_tree", "Banana", "ethereal_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:giant_redwood", "Giant Redwood",
  56. "ethereal_giant_redwood_sapling", 33)
  57. register_sapling("ethereal:redwood", "Redwood", "ethereal_redwood_sapling", 21)
  58. register_sapling("ethereal:orange_tree", "Orange", "ethereal_orange_tree_sapling", 6)
  59. register_sapling("ethereal:birch", "Birch", "moretrees_birch_sapling", 7)
  60. register_sapling("ethereal:sakura", "Sakura", "ethereal_sakura_sapling", 10)
  61. register_sapling("ethereal:lemon_tree", "Lemon", "ethereal_lemon_tree_sapling", 7)
  62. register_sapling("ethereal:olive_tree", "Olive", "ethereal_olive_tree_sapling", 10)
  63. local add_tree = function (pos, ofx, ofy, ofz, schem, replace)
  64. -- check for schematic
  65. if not schem then
  66. print (S("Schematic not found"))
  67. return
  68. end
  69. -- remove sapling and place schematic
  70. minetest.swap_node(pos, {name = "air"})
  71. minetest.place_schematic(
  72. {x = pos.x - ofx, y = pos.y - ofy, z = pos.z - ofz},
  73. schem, 0, replace, false)
  74. end
  75. local path = minetest.get_modpath("ethereal") .. "/schematics/"
  76. -- grow tree functions
  77. function ethereal.grow_yellow_tree(pos)
  78. add_tree(pos, 4, 0, 4, ethereal.yellowtree)
  79. end
  80. function ethereal.grow_big_tree(pos)
  81. add_tree(pos, 4, 0, 4, ethereal.bigtree)
  82. end
  83. function ethereal.grow_banana_tree(pos)
  84. if math.random(3) == 1
  85. and minetest.find_node_near(pos, 1, {"farming:soil_wet"}) then
  86. add_tree(pos, 3, 0, 3, ethereal.bananatree,
  87. {{"ethereal:banana", "ethereal:banana_bunch"}})
  88. else
  89. add_tree(pos, 3, 0, 3, ethereal.bananatree)
  90. end
  91. end
  92. function ethereal.grow_frost_tree(pos)
  93. add_tree(pos, 4, 0, 4, ethereal.frosttrees)
  94. end
  95. function ethereal.grow_mushroom_tree(pos)
  96. add_tree(pos, 4, 0, 4, ethereal.mushroomone)
  97. end
  98. function ethereal.grow_palm_tree(pos)
  99. add_tree(pos, 4, 0, 4, ethereal.palmtree)
  100. end
  101. function ethereal.grow_willow_tree(pos)
  102. add_tree(pos, 5, 0, 5, ethereal.willow)
  103. end
  104. function ethereal.grow_redwood_tree(pos)
  105. add_tree(pos, 4, 0, 4, ethereal.redwood_small_tree)
  106. end
  107. function ethereal.grow_giant_redwood_tree(pos)
  108. add_tree(pos, 7, 0, 7, ethereal.redwood_tree)
  109. end
  110. function ethereal.grow_orange_tree(pos)
  111. add_tree(pos, 2, 0, 2, ethereal.orangetree)
  112. end
  113. function ethereal.grow_bamboo_tree(pos)
  114. add_tree(pos, 1, 0, 1, ethereal.bambootree)
  115. end
  116. function ethereal.grow_birch_tree(pos)
  117. add_tree(pos, 2, 0, 2, ethereal.birchtree)
  118. end
  119. function ethereal.grow_sakura_tree(pos)
  120. if math.random(10) == 1 then
  121. add_tree(pos, 4, 0, 3, ethereal.sakura_tree,
  122. {{"ethereal:sakura_leaves", "ethereal:sakura_leaves2"}})
  123. else
  124. add_tree(pos, 4, 0, 3, ethereal.sakura_tree)
  125. end
  126. end
  127. function ethereal.grow_lemon_tree(pos)
  128. add_tree(pos, 2, 0, 2, ethereal.lemontree)
  129. end
  130. function ethereal.grow_olive_tree(pos)
  131. add_tree(pos, 3, 0, 3, ethereal.olivetree)
  132. end
  133. -- check if sapling has enough height room to grow
  134. local enough_height = function(pos, height)
  135. local nod = minetest.line_of_sight(
  136. {x = pos.x, y = pos.y + 1, z = pos.z},
  137. {x = pos.x, y = pos.y + height, z = pos.z})
  138. if not nod then
  139. return false -- obstructed
  140. else
  141. return true -- can grow
  142. end
  143. end
  144. local grow_sapling = function(pos, node)
  145. local under = minetest.get_node({
  146. x = pos.x,
  147. y = pos.y - 1,
  148. z = pos.z
  149. }).name
  150. if not minetest.registered_nodes[node.name] then
  151. return
  152. end
  153. local height = minetest.registered_nodes[node.name].grown_height
  154. -- do we have enough height to grow sapling into tree?
  155. if not height or not enough_height(pos, height) then
  156. return
  157. end
  158. -- Check if Ethereal Sapling is growing on correct substrate
  159. if node.name == "ethereal:yellow_tree_sapling"
  160. and minetest.get_item_group(under, "soil") > 0 then
  161. ethereal.grow_yellow_tree(pos)
  162. elseif node.name == "ethereal:big_tree_sapling"
  163. and under == "default:dirt_with_grass" then
  164. ethereal.grow_big_tree(pos)
  165. elseif node.name == "ethereal:banana_tree_sapling"
  166. and under == "ethereal:grove_dirt" then
  167. ethereal.grow_banana_tree(pos)
  168. elseif node.name == "ethereal:frost_tree_sapling"
  169. and under == "ethereal:crystal_dirt" then
  170. ethereal.grow_frost_tree(pos)
  171. elseif node.name == "ethereal:mushroom_sapling"
  172. and under == "ethereal:mushroom_dirt" then
  173. ethereal.grow_mushroom_tree(pos)
  174. elseif node.name == "ethereal:palm_sapling"
  175. and under == "default:sand" then
  176. ethereal.grow_palm_tree(pos)
  177. elseif node.name == "ethereal:willow_sapling"
  178. and under == "ethereal:gray_dirt" then
  179. ethereal.grow_willow_tree(pos)
  180. elseif node.name == "ethereal:redwood_sapling"
  181. and under == "default:dirt_with_dry_grass" then
  182. ethereal.grow_redwood_tree(pos)
  183. elseif node.name == "ethereal:giant_redwood_sapling"
  184. and under == "default:dirt_with_dry_grass" then
  185. ethereal.grow_giant_redwood_tree(pos)
  186. elseif node.name == "ethereal:orange_tree_sapling"
  187. and under == "ethereal:prairie_dirt" then
  188. ethereal.grow_orange_tree(pos)
  189. elseif node.name == "ethereal:bamboo_sprout"
  190. and under == "ethereal:bamboo_dirt" then
  191. ethereal.grow_bamboo_tree(pos)
  192. elseif node.name == "ethereal:birch_sapling"
  193. and under == "default:dirt_with_grass" then
  194. ethereal.grow_birch_tree(pos)
  195. elseif node.name == "ethereal:sakura_sapling"
  196. and under == "ethereal:bamboo_dirt" then
  197. ethereal.grow_sakura_tree(pos)
  198. elseif node.name == "ethereal:olive_tree_sapling"
  199. and under == "ethereal:grove_dirt" then
  200. ethereal.grow_olive_tree(pos)
  201. elseif node.name == "ethereal:lemon_tree_sapling"
  202. and under == "ethereal:grove_dirt" then
  203. ethereal.grow_lemon_tree(pos)
  204. end
  205. end
  206. -- Grow saplings
  207. minetest.register_abm({
  208. label = "Ethereal grow sapling",
  209. nodenames = {"group:ethereal_sapling"},
  210. interval = 10,
  211. chance = 50,
  212. catch_up = false,
  213. action = function(pos, node)
  214. local light_level = minetest.get_node_light(pos) or 0
  215. if light_level < 13 then
  216. return
  217. end
  218. grow_sapling(pos, node)
  219. end
  220. })
  221. -- 2x redwood saplings make 1x giant redwood sapling
  222. minetest.register_craft({
  223. output = "ethereal:giant_redwood_sapling",
  224. recipe = {{"ethereal:redwood_sapling", "ethereal:redwood_sapling"}}
  225. })