treefern.lua 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. -----------------------------------------------------------------------------------------------
  2. -- Ferns - Tree Fern 0.1.1
  3. -----------------------------------------------------------------------------------------------
  4. -- by Mossmanikin
  5. -- Contains code from: biome_lib
  6. -- Looked at code from: default , trees
  7. -----------------------------------------------------------------------------------------------
  8. -- support for i18n
  9. local S = minetest.get_translator("ferns")
  10. assert(abstract_ferns.config.enable_treefern == true)
  11. abstract_ferns.grow_tree_fern = function(pos)
  12. local pos_aux = {x = pos.x, y = pos.y + 1, z = pos.z}
  13. local name = minetest.get_node(pos_aux).name
  14. if name ~= "air" and name ~= "ferns:sapling_tree_fern"
  15. and name ~= "default:junglegrass" then
  16. return
  17. end
  18. local size = math.random(1, 4) + math.random(1, 4)
  19. if (size > 5) then
  20. size = 10 - size
  21. end
  22. size = size + 1
  23. local crown = ({ "ferns:tree_fern_leaves", "ferns:tree_fern_leaves_02" })[math.random(1, 2)]
  24. local i = 1
  25. local brk = false
  26. while (i < size) do
  27. pos_aux.y = pos.y + i
  28. name = minetest.get_node(pos_aux).name
  29. if not (name == "air" or (i == 1 and name == "ferns:sapling_tree_fern")) then
  30. brk = true
  31. break
  32. end
  33. minetest.swap_node({x = pos.x, y = pos.y + i, z = pos.z}, { name = "ferns:fern_trunk" })
  34. i = i + 1
  35. end
  36. if not brk then
  37. minetest.swap_node({x = pos.x, y = pos.y + i - 1, z = pos.z}, { name = crown })
  38. end
  39. end
  40. -----------------------------------------------------------------------------------------------
  41. -- TREE FERN LEAVES
  42. -----------------------------------------------------------------------------------------------
  43. -- TODO: Both of these nodes look the same?
  44. minetest.register_node("ferns:tree_fern_leaves", {
  45. description = S("Tree Fern Crown (Dicksonia)"),
  46. drawtype = "plantlike",
  47. visual_scale = math.sqrt(8),
  48. paramtype = "light",
  49. paramtype2 = "facedir",
  50. --tiles = {"[combine:32x32:0,0=top_left.png:0,16=bottom_left.png:16,0=top_right.png:16,16=bottom_right.png"},
  51. tiles = {"ferns_fern_tree.png"},
  52. inventory_image = "ferns_fern_tree_inv.png",
  53. walkable = false,
  54. groups = {snappy=3,flammable=2,attached_node=1},
  55. drop = {
  56. max_items = 2,
  57. items = {
  58. {
  59. -- occasionally, drop a second sapling instead of leaves
  60. -- (extra saplings can also be obtained by replanting and
  61. -- reharvesting leaves)
  62. items = {"ferns:sapling_tree_fern"},
  63. rarity = 10,
  64. },
  65. {
  66. items = {"ferns:sapling_tree_fern"},
  67. },
  68. {
  69. items = {"ferns:tree_fern_leaves"},
  70. }
  71. }
  72. },
  73. sounds = default.node_sound_leaves_defaults(),
  74. selection_box = {
  75. type = "fixed",
  76. fixed = {-7/16, -1/2, -7/16, 7/16, 0, 7/16},
  77. },
  78. })
  79. minetest.register_node("ferns:tree_fern_leaves_02", {
  80. drawtype = "plantlike",
  81. visual_scale = math.sqrt(8),
  82. paramtype = "light",
  83. tiles = {"ferns_fern_big.png"},
  84. walkable = false,
  85. groups = {snappy=3,flammable=2,attached_node=1,not_in_creative_inventory=1},
  86. drop = {
  87. max_items = 2,
  88. items = {
  89. {
  90. -- occasionally, drop a second sapling instead of leaves
  91. -- (extra saplings can also be obtained by replanting and
  92. -- reharvesting leaves)
  93. items = {"ferns:sapling_tree_fern"},
  94. rarity = 10,
  95. },
  96. {
  97. items = {"ferns:sapling_tree_fern"},
  98. },
  99. {
  100. items = {"ferns:tree_fern_leaves"},
  101. }
  102. }
  103. },
  104. sounds = default.node_sound_leaves_defaults(),
  105. selection_box = {
  106. type = "fixed",
  107. fixed = {-7/16, -1/2, -7/16, 7/16, 0, 7/16},
  108. },
  109. })
  110. -----------------------------------------------------------------------------------------------
  111. -- FERN TRUNK
  112. -----------------------------------------------------------------------------------------------
  113. minetest.register_node("ferns:fern_trunk", {
  114. description = S("Fern Trunk (Dicksonia)"),
  115. drawtype = "nodebox",
  116. paramtype = "light",
  117. tiles = {
  118. "ferns_fern_trunk_top.png",
  119. "ferns_fern_trunk_top.png",
  120. "ferns_fern_trunk.png"
  121. },
  122. node_box = {
  123. type = "fixed",
  124. fixed = {-1/8, -1/2, -1/8, 1/8, 1/2, 1/8},
  125. },
  126. selection_box = {
  127. type = "fixed",
  128. fixed = {-1/7, -1/2, -1/7, 1/7, 1/2, 1/7},
  129. },
  130. groups = {tree=1,choppy=2,oddly_breakable_by_hand=2,flammable=3,wood=1},
  131. sounds = default.node_sound_wood_defaults(),
  132. after_destruct = function(pos,oldnode)
  133. local node = minetest.get_node({x=pos.x,y=pos.y+1,z=pos.z})
  134. if node.name == "ferns:fern_trunk" then
  135. minetest.dig_node({x=pos.x,y=pos.y+1,z=pos.z})
  136. minetest.add_item(pos,"ferns:fern_trunk")
  137. end
  138. end,
  139. })
  140. -----------------------------------------------------------------------------------------------
  141. -- TREE FERN SAPLING
  142. -----------------------------------------------------------------------------------------------
  143. minetest.register_node("ferns:sapling_tree_fern", {
  144. description = S("Tree Fern Sapling (Dicksonia)"),
  145. drawtype = "plantlike",
  146. paramtype = "light",
  147. paramtype2 = "facedir",
  148. tiles = {"ferns_sapling_tree_fern.png"},
  149. inventory_image = "ferns_sapling_tree_fern.png",
  150. walkable = false,
  151. groups = {snappy=3,flammable=2,flora=1,attached_node=1},
  152. sounds = default.node_sound_leaves_defaults(),
  153. selection_box = {
  154. type = "fixed",
  155. fixed = {-7/16, -1/2, -7/16, 7/16, 0, 7/16},
  156. },
  157. })
  158. -- abm
  159. minetest.register_abm({
  160. nodenames = "ferns:sapling_tree_fern",
  161. interval = 1000,
  162. chance = 4,
  163. action = function(pos, node, _, _)
  164. abstract_ferns.grow_tree_fern({x = pos.x, y = pos.y-1, z = pos.z})
  165. end
  166. })
  167. -----------------------------------------------------------------------------------------------
  168. -- GENERATE TREE FERN
  169. -----------------------------------------------------------------------------------------------
  170. -- in jungles
  171. if abstract_ferns.config.enable_treeferns_in_jungle == true then
  172. biome_lib:register_generate_plant({
  173. surface = {
  174. "default:dirt_with_grass",
  175. "default:dirt_with_rainforest_litter", -- minetest >= 0.4.16
  176. "default:sand",
  177. "default:desert_sand",
  178. },
  179. max_count = 35,--27,
  180. avoid_nodes = {"default:tree"},
  181. avoid_radius = 4,
  182. rarity = 50,
  183. seed_diff = 329,
  184. min_elevation = -10,
  185. near_nodes = {"default:jungletree"},
  186. near_nodes_size = 6,
  187. near_nodes_vertical = 2,--4,
  188. near_nodes_count = 1,
  189. plantlife_limit = -0.9,
  190. humidity_max = -1.0,
  191. humidity_min = 0.4,
  192. temp_max = -0.5,
  193. temp_min = 0.13,
  194. },
  195. abstract_ferns.grow_tree_fern
  196. )
  197. end
  198. -- for oases & tropical beaches
  199. if abstract_ferns.config.enable_treeferns_in_oases == true then
  200. biome_lib:register_generate_plant({
  201. surface = {
  202. "default:sand"--,
  203. --"default:desert_sand"
  204. },
  205. max_count = 35,
  206. rarity = 50,
  207. seed_diff = 329,
  208. neighbors = {"default:desert_sand"},
  209. ncount = 1,
  210. min_elevation = 1,
  211. near_nodes = {"default:water_source","default:river_water_source"},
  212. near_nodes_size = 2,
  213. near_nodes_vertical = 1,
  214. near_nodes_count = 1,
  215. plantlife_limit = -0.9,
  216. humidity_max = -1.0,
  217. humidity_min = 1.0,
  218. temp_max = -1.0,
  219. temp_min = 1.0,
  220. },
  221. abstract_ferns.grow_tree_fern
  222. )
  223. end