sapling.lua 6.5 KB

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