gianttreefern.lua 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. -----------------------------------------------------------------------------------------------
  2. -- Ferns - Giant Tree Fern 0.1.1
  3. -----------------------------------------------------------------------------------------------
  4. -- by Mossmanikin
  5. -- Contains code from: biome_lib
  6. -- Looked at code from: 4seasons, default
  7. -- Supports: vines
  8. -----------------------------------------------------------------------------------------------
  9. assert(abstract_ferns.config.enable_giant_treefern == true)
  10. -- support for i18n
  11. local S = minetest.get_translator("ferns")
  12. -- lot of code, lot to load
  13. abstract_ferns.grow_giant_tree_fern = function(pos)
  14. local pos_aux = {x = pos.x, y = pos.y + 1, z = pos.z}
  15. local name = minetest.get_node(pos_aux).name
  16. if name ~= "air" and name ~= "ferns:sapling_giant_tree_fern"
  17. and name ~= "default:junglegrass" then
  18. return
  19. end
  20. local size = math.random(12,16) -- min of range must be >= 4
  21. local leafchecks = {
  22. {
  23. direction = 3,
  24. positions = {
  25. {x = pos.x + 1, y = pos.y + size - 1, z = pos.z },
  26. {x = pos.x + 2, y = pos.y + size , z = pos.z },
  27. {x = pos.x + 3, y = pos.y + size - 1, z = pos.z },
  28. {x = pos.x + 4, y = pos.y + size - 2, z = pos.z }
  29. }
  30. },
  31. {
  32. direction = 1,
  33. positions = {
  34. {x = pos.x - 1, y = pos.y + size - 1, z = pos.z },
  35. {x = pos.x - 2, y = pos.y + size, z = pos.z },
  36. {x = pos.x - 3, y = pos.y + size - 1, z = pos.z },
  37. {x = pos.x - 4, y = pos.y + size - 2, z = pos.z }
  38. }
  39. },
  40. {
  41. direction = 2,
  42. positions = {
  43. {x = pos.x , y = pos.y + size - 1, z = pos.z + 1},
  44. {x = pos.x , y = pos.y + size , z = pos.z + 2},
  45. {x = pos.x , y = pos.y + size - 1, z = pos.z + 3},
  46. {x = pos.x , y = pos.y + size - 2, z = pos.z + 4}
  47. }
  48. },
  49. {
  50. direction = 0,
  51. positions = {
  52. {x = pos.x , y = pos.y + size - 1, z = pos.z - 1},
  53. {x = pos.x , y = pos.y + size , z = pos.z - 2},
  54. {x = pos.x , y = pos.y + size - 1, z = pos.z - 3},
  55. {x = pos.x , y = pos.y + size - 2, z = pos.z - 4}
  56. }
  57. }
  58. }
  59. local brk = false
  60. for i = 1, size-3 do
  61. pos_aux.y = pos.y + i
  62. local name = minetest.get_node(pos_aux).name
  63. if not (name == "air" or (i == 1 and name == "ferns:sapling_giant_tree_fern")) then
  64. brk = true
  65. break
  66. end
  67. minetest.swap_node({x = pos.x, y = pos.y + i, z = pos.z}, {name="ferns:fern_trunk_big"})
  68. end
  69. if not brk then
  70. minetest.swap_node({x = pos.x, y = pos.y + size-2, z = pos.z}, {name="ferns:fern_trunk_big_top"})
  71. minetest.swap_node({x = pos.x, y = pos.y + size-1, z = pos.z}, {name="ferns:tree_fern_leaves_giant"})
  72. -- all the checking for air below is to prevent some ugly bugs (incomplete trunks of neighbouring trees), it's a bit slower, but worth the result
  73. -- assert(#leafchecks == 4)
  74. for i = 1, 4 do
  75. local positions = leafchecks[i].positions
  76. local rot = leafchecks[i].direction
  77. local endpos = 4 -- If the loop below adds all intermediate leaves then the "terminating" leaf will be at positions[4]
  78. -- assert(#positions == 4)
  79. -- add leaves so long as the destination nodes are air
  80. for j = 1, 3 do
  81. if minetest.get_node(positions[j]).name == "air" then
  82. minetest.swap_node(positions[j], {name="ferns:tree_fern_leave_big"})
  83. else
  84. endpos = j
  85. break
  86. end
  87. end
  88. -- add the terminating leaf if required and possible
  89. if endpos == 4 and minetest.get_node(positions[endpos]).name == "air" then
  90. minetest.swap_node(positions[endpos], {name="ferns:tree_fern_leave_big_end", param2=rot})
  91. end
  92. end
  93. end
  94. end
  95. -----------------------------------------------------------------------------------------------
  96. -- GIANT TREE FERN LEAVES
  97. -----------------------------------------------------------------------------------------------
  98. minetest.register_node("ferns:tree_fern_leaves_giant", {
  99. description = S("Tree Fern Crown (Dicksonia)"),
  100. drawtype = "plantlike",
  101. visual_scale = math.sqrt(11),
  102. wield_scale = {x=0.175, y=0.175, z=0.175},
  103. paramtype = "light",
  104. tiles = {"ferns_fern_tree_giant.png"},
  105. inventory_image = "ferns_fern_tree.png",
  106. walkable = false,
  107. groups = {
  108. snappy=3,
  109. flammable=2,
  110. attached_node=1,
  111. not_in_creative_inventory=1
  112. },
  113. drop = {
  114. max_items = 2,
  115. items = {
  116. {
  117. -- occasionally, drop a second sapling instead of leaves
  118. -- (extra saplings can also be obtained by replanting and
  119. -- reharvesting leaves)
  120. items = {"ferns:sapling_giant_tree_fern"},
  121. rarity = 10,
  122. },
  123. {
  124. items = {"ferns:sapling_giant_tree_fern"},
  125. },
  126. {
  127. items = {"ferns:tree_fern_leaves_giant"},
  128. }
  129. }
  130. },
  131. sounds = default.node_sound_leaves_defaults(),
  132. selection_box = {
  133. type = "fixed",
  134. fixed = {-7/16, -1/2, -7/16, 7/16, 0, 7/16},
  135. },
  136. })
  137. -----------------------------------------------------------------------------------------------
  138. -- GIANT TREE FERN LEAVE PART
  139. -----------------------------------------------------------------------------------------------
  140. minetest.register_node("ferns:tree_fern_leave_big", {
  141. description = S("Giant Tree Fern Leaves"),
  142. drawtype = "raillike",
  143. paramtype = "light",
  144. tiles = {
  145. "ferns_tree_fern_leave_big.png",
  146. },
  147. walkable = false,
  148. groups = {
  149. snappy=3,
  150. flammable=2,
  151. attached_node=1,
  152. not_in_creative_inventory=1
  153. },
  154. drop = "",
  155. sounds = default.node_sound_leaves_defaults(),
  156. })
  157. -----------------------------------------------------------------------------------------------
  158. -- GIANT TREE FERN LEAVE END
  159. -----------------------------------------------------------------------------------------------
  160. minetest.register_node("ferns:tree_fern_leave_big_end", {
  161. description = S("Giant Tree Fern Leave End"),
  162. drawtype = "nodebox",
  163. paramtype = "light",
  164. paramtype2 = "facedir",
  165. tiles = { "ferns_tree_fern_leave_big_end.png" },
  166. walkable = false,
  167. node_box = {
  168. type = "fixed",
  169. -- {left, bottom, front, right, top, back }
  170. fixed = {-1/2, -1/2, 1/2, 1/2, 33/64, 1/2},
  171. },
  172. selection_box = {
  173. type = "fixed",
  174. fixed = {-1/2, -1/2, 1/2, 1/2, 33/64, 1/2},
  175. },
  176. groups = {
  177. snappy=3,
  178. flammable=2,
  179. attached_node=1,
  180. not_in_creative_inventory=1
  181. },
  182. drop = "",
  183. sounds = default.node_sound_leaves_defaults(),
  184. })
  185. -----------------------------------------------------------------------------------------------
  186. -- GIANT TREE FERN TRUNK TOP
  187. -----------------------------------------------------------------------------------------------
  188. minetest.register_node("ferns:fern_trunk_big_top", {
  189. description = S("Giant Fern Trunk"),
  190. drawtype = "nodebox",
  191. paramtype = "light",
  192. tiles = {
  193. "ferns_fern_trunk_big_top.png^ferns_tree_fern_leave_big_cross.png",
  194. "ferns_fern_trunk_big_top.png^ferns_tree_fern_leave_big_cross.png",
  195. "ferns_fern_trunk_big.png"
  196. },
  197. node_box = {
  198. type = "fixed",
  199. -- {left, bottom, front, right, top, back }
  200. fixed = {
  201. {-1/2, 33/64, -1/2, 1/2, 33/64, 1/2},
  202. {-1/4, -1/2, -1/4, 1/4, 1/2, 1/4},
  203. }
  204. },
  205. selection_box = {
  206. type = "fixed",
  207. fixed = {-1/4, -1/2, -1/4, 1/4, 1/2, 1/4},
  208. },
  209. groups = {
  210. tree=1,
  211. choppy=2,
  212. oddly_breakable_by_hand=2,
  213. flammable=3,
  214. wood=1,
  215. not_in_creative_inventory=1,
  216. leafdecay=3 -- to support vines
  217. },
  218. drop = "ferns:fern_trunk_big",
  219. sounds = default.node_sound_wood_defaults(),
  220. })
  221. -----------------------------------------------------------------------------------------------
  222. -- GIANT TREE FERN TRUNK
  223. -----------------------------------------------------------------------------------------------
  224. minetest.register_node("ferns:fern_trunk_big", {
  225. description = S("Giant Fern Trunk"),
  226. drawtype = "nodebox",
  227. paramtype = "light",
  228. tiles = {
  229. "ferns_fern_trunk_big_top.png",
  230. "ferns_fern_trunk_big_top.png",
  231. "ferns_fern_trunk_big.png"
  232. },
  233. node_box = {
  234. type = "fixed",
  235. fixed = {-1/4, -1/2, -1/4, 1/4, 1/2, 1/4},
  236. },
  237. selection_box = {
  238. type = "fixed",
  239. fixed = {-1/4, -1/2, -1/4, 1/4, 1/2, 1/4},
  240. },
  241. groups = {tree=1,choppy=2,oddly_breakable_by_hand=2,flammable=3,wood=1},
  242. sounds = default.node_sound_wood_defaults(),
  243. after_destruct = function(pos,oldnode)
  244. local node = minetest.get_node({x=pos.x,y=pos.y+1,z=pos.z})
  245. if node.name == "ferns:fern_trunk_big" or node.name == "ferns:fern_trunk_big_top" then
  246. minetest.dig_node({x=pos.x,y=pos.y+1,z=pos.z})
  247. minetest.add_item(pos,"ferns:fern_trunk_big")
  248. end
  249. end,
  250. })
  251. -----------------------------------------------------------------------------------------------
  252. -- GIANT TREE FERN SAPLING
  253. -----------------------------------------------------------------------------------------------
  254. minetest.register_node("ferns:sapling_giant_tree_fern", {
  255. description = S("Giant Tree Fern Sapling"),
  256. drawtype = "plantlike",
  257. paramtype = "light",
  258. tiles = {"ferns_sapling_tree_fern_giant.png"},
  259. inventory_image = "ferns_sapling_tree_fern_giant.png",
  260. walkable = false,
  261. groups = {snappy=3,flammable=2,flora=1,attached_node=1},
  262. sounds = default.node_sound_leaves_defaults(),
  263. selection_box = {
  264. type = "fixed",
  265. fixed = {-7/16, -1/2, -7/16, 7/16, 0, 7/16},
  266. },
  267. })
  268. -- abm
  269. minetest.register_abm({
  270. nodenames = "ferns:sapling_giant_tree_fern",
  271. interval = 1000,
  272. chance = 4,
  273. action = function(pos, node, _, _)
  274. abstract_ferns.grow_giant_tree_fern({x = pos.x, y = pos.y-1, z = pos.z})
  275. end
  276. })
  277. -----------------------------------------------------------------------------------------------
  278. -- GENERATE GIANT TREE FERN
  279. -----------------------------------------------------------------------------------------------
  280. -- in jungles
  281. if abstract_ferns.config.enable_giant_treeferns_in_jungle == true then
  282. biome_lib:register_generate_plant({
  283. surface = {
  284. "default:dirt_with_grass",
  285. "default:dirt_with_rainforest_litter", -- minetest >= 0.4.16
  286. "default:sand",
  287. "default:desert_sand"--,
  288. --"dryplants:grass_short"
  289. },
  290. max_count = 12,--27,
  291. avoid_nodes = {"group:tree"},
  292. avoid_radius = 3,--4,
  293. rarity = 85,
  294. seed_diff = 329,
  295. min_elevation = 1,
  296. near_nodes = {"default:jungletree"},
  297. near_nodes_size = 6,
  298. near_nodes_vertical = 2,--4,
  299. near_nodes_count = 1,
  300. plantlife_limit = -0.9,
  301. },
  302. abstract_ferns.grow_giant_tree_fern
  303. )
  304. end
  305. -- for oases & tropical beaches
  306. if abstract_ferns.config.enable_giant_treeferns_in_oases == true then
  307. biome_lib:register_generate_plant({
  308. surface = {
  309. "default:sand"--,
  310. --"default:desert_sand"
  311. },
  312. max_count = 10,--27,
  313. rarity = 90,
  314. seed_diff = 329,
  315. neighbors = {"default:desert_sand"},
  316. ncount = 1,
  317. min_elevation = 1,
  318. near_nodes = {"default:water_source", "default:river_water_source"},
  319. near_nodes_size = 2,
  320. near_nodes_vertical = 1,
  321. near_nodes_count = 1,
  322. plantlife_limit = -0.9,
  323. humidity_max = -1.0,
  324. humidity_min = 1.0,
  325. temp_max = -1.0,
  326. temp_min = 1.0,
  327. },
  328. abstract_ferns.grow_giant_tree_fern
  329. )
  330. end