sapling.lua 7.7 KB

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