init.lua 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. -- Bushes Mod by Mossmanikin, Evergreen, & Neuromancer
  2. -- The initial code for this was taken from Mossmanikin's Grasses Mod,
  3. -- then heavilly modified by Neuromancer for this mod.
  4. -- Mossmanikin also greatly helped with providing samples for coding.
  5. -- bush leaf textures are from VannessaE's moretrees mod.
  6. -- (Leaf texture created by RealBadAngel or VanessaE)
  7. -- Branch textures created by Neuromancer.
  8. -- support for i18n
  9. local S = minetest.get_translator("bushes")
  10. abstract_bushes = {}
  11. minetest.register_node("bushes:youngtree2_bottom", {
  12. description = S("Young Tree 2 (bottom)"),
  13. drawtype="nodebox",
  14. tiles = {"bushes_youngtree2trunk.png"},
  15. inventory_image = "bushes_youngtree2trunk_inv.png",
  16. wield_image = "bushes_youngtree2trunk_inv.png",
  17. paramtype = "light",
  18. walkable = false,
  19. is_ground_content = true,
  20. node_box = {
  21. type = "fixed",
  22. fixed = {
  23. --{0.375000,-0.500000,-0.500000,0.500000,0.500000,-0.375000}, --NodeBox 1
  24. {-0.0612,-0.500000,-0.500000,0.0612,0.500000,-0.375000}, --NodeBox 1
  25. }
  26. },
  27. groups = {snappy=3,flammable=2},
  28. sounds = default.node_sound_leaves_defaults(),
  29. drop = 'default:stick'
  30. })
  31. local BushBranchCenter = { {1,1}, {3,2} }
  32. for i in pairs(BushBranchCenter) do
  33. local Num = BushBranchCenter[i][1]
  34. local TexNum = BushBranchCenter[i][2]
  35. minetest.register_node("bushes:bushbranches"..Num, {
  36. description = S("Bush Branches @1", Num),
  37. drawtype = "nodebox",
  38. tiles = {
  39. "bushes_leaves_"..TexNum..".png",
  40. "bushes_branches_center_"..TexNum..".png"
  41. },
  42. node_box = {
  43. type = "fixed",
  44. fixed = {
  45. {0, -1/2, -1/2, -1/4, 1/2, 1/2},
  46. {0, -1/2, -1/2, 1/4, 1/2, 1/2}
  47. },
  48. },
  49. selection_box = {
  50. type = "fixed",
  51. fixed = {-1/2, -1/2, -1/2, 1/2, 1/2, 1/2},
  52. },
  53. inventory_image = "bushes_branches_center_"..TexNum..".png",
  54. paramtype = "light",
  55. paramtype2 = "facedir",
  56. sunlight_propagates = true,
  57. groups = {
  58. -- tree=1, -- MM: disabled because some recipes use group:tree for trunks
  59. snappy=3,
  60. flammable=2,
  61. leaves=1
  62. },
  63. sounds = default.node_sound_leaves_defaults(),
  64. drop = 'default:stick 4'
  65. })
  66. end
  67. local BushBranchSide = { {2,1}, {4,2} }
  68. for i in pairs(BushBranchSide) do
  69. local Num = BushBranchSide[i][1]
  70. local TexNum = BushBranchSide[i][2]
  71. minetest.register_node("bushes:bushbranches"..Num, {
  72. description = S("Bush Branches @1", Num),
  73. drawtype = "nodebox",
  74. tiles = {
  75. --[[top]] "bushes_leaves_"..TexNum..".png",
  76. --[[bottom]]"bushes_branches_center_"..TexNum..".png",
  77. --[[right]] "bushes_branches_left_"..TexNum..".png",
  78. --[[left]] "bushes_branches_right_"..TexNum..".png", -- MM: We could also mirror the previous here,
  79. --[[back]] "bushes_branches_center_"..TexNum..".png",-- unless U really want 'em 2 B different
  80. --[[front]] "bushes_branches_right_"..TexNum..".png"
  81. },
  82. node_box = {
  83. type = "fixed",
  84. fixed = {
  85. -- { left , bottom , front, right , top , back }
  86. {0.137748,-0.491944, 0.5 ,-0.125000,-0.179444,-0.007790}, --NodeBox 1
  87. {0.262748,-0.185995, 0.5 ,-0.237252, 0.126505,-0.260269}, --NodeBox 2
  88. {0.500000, 0.125000, 0.5 ,-0.500000, 0.500000,-0.500000}, --NodeBox 3
  89. },
  90. },
  91. selection_box = {
  92. type = "fixed",
  93. fixed = {-1/2, -1/2, -1/2, 1/2, 1/2, 1/2},
  94. },
  95. inventory_image = "bushes_branches_right_"..TexNum..".png",
  96. paramtype = "light",
  97. paramtype2 = "facedir",
  98. sunlight_propagates = true,
  99. groups = {
  100. -- tree=1, -- MM: disabled because some recipes use group:tree for trunks
  101. snappy=3,
  102. flammable=2,
  103. leaves=1
  104. },
  105. sounds = default.node_sound_leaves_defaults(),
  106. drop = 'default:stick 3'
  107. })
  108. end
  109. local BushLeafNode = { {1}, {2}}
  110. for i in pairs(BushLeafNode) do
  111. local Num = BushLeafNode[i][1]
  112. minetest.register_node("bushes:BushLeaves"..Num, {
  113. description = S("Bush Leaves @1", Num),
  114. drawtype = "allfaces_optional",
  115. tiles = {"bushes_leaves_"..Num..".png"},
  116. paramtype = "light",
  117. groups = { -- MM: Should we add leafdecay?
  118. snappy=3,
  119. flammable=2,
  120. attached_node=1
  121. },
  122. sounds = default.node_sound_leaves_defaults(),
  123. })
  124. end
  125. abstract_bushes.grow_bush = function(pos)
  126. local leaf_type = math.random(1,2)
  127. local bush_side_height = math.random(0,1)
  128. local chance_of_bush_node_right = math.random(1,10)
  129. if chance_of_bush_node_right> 5 then
  130. local right_pos = {x=pos.x+1, y=pos.y+bush_side_height, z=pos.z}
  131. abstract_bushes.grow_bush_node(right_pos,3,leaf_type)
  132. end
  133. local chance_of_bush_node_left = math.random(1,10)
  134. if chance_of_bush_node_left> 5 then
  135. bush_side_height = math.random(0,1)
  136. local left_pos = {x=pos.x-1, y=pos.y+bush_side_height, z=pos.z}
  137. abstract_bushes.grow_bush_node(left_pos,1,leaf_type)
  138. end
  139. local chance_of_bush_node_front = math.random(1,10)
  140. if chance_of_bush_node_front> 5 then
  141. bush_side_height = math.random(0,1)
  142. local front_pos = {x=pos.x, y=pos.y+bush_side_height, z=pos.z+1}
  143. abstract_bushes.grow_bush_node(front_pos,2,leaf_type)
  144. end
  145. local chance_of_bush_node_back = math.random(1,10)
  146. if chance_of_bush_node_back> 5 then
  147. bush_side_height = math.random(0,1)
  148. local back_pos = {x=pos.x, y=pos.y+bush_side_height, z=pos.z-1}
  149. abstract_bushes.grow_bush_node(back_pos,0,leaf_type)
  150. end
  151. abstract_bushes.grow_bush_node(pos,5,leaf_type)
  152. end
  153. abstract_bushes.grow_bush_node = function(pos,dir, leaf_type)
  154. local right_here = {x=pos.x, y=pos.y+1, z=pos.z}
  155. local above_right_here = {x=pos.x, y=pos.y+2, z=pos.z}
  156. local bush_branch_type = 2
  157. -- MM: I'm not sure if it's slower now than before...
  158. if dir ~= 5 and leaf_type == 1 then
  159. bush_branch_type = 2
  160. end
  161. if dir ~= 5 and leaf_type == 2 then
  162. bush_branch_type = 4
  163. end
  164. if dir == 5 and leaf_type == 1 then
  165. bush_branch_type = 1
  166. dir = 1
  167. end
  168. if dir == 5 and leaf_type == 2 then
  169. bush_branch_type = 3
  170. dir = 1
  171. end
  172. if minetest.get_node(right_here).name == "air" -- instead of check_air = true,
  173. or minetest.get_node(right_here).name == "default:junglegrass" then
  174. minetest.swap_node(right_here, {name="bushes:bushbranches"..bush_branch_type , param2=dir})
  175. --minetest.chat_send_all("leaf_type: (" .. leaf_type .. ")")
  176. minetest.swap_node(above_right_here, {name="bushes:BushLeaves"..leaf_type})
  177. local chance_of_high_leaves = math.random(1,10)
  178. if chance_of_high_leaves> 5 then
  179. local two_above_right_here = {x=pos.x, y=pos.y+3, z=pos.z}
  180. --minetest.chat_send_all("leaf_type: (" .. leaf_type .. ")")
  181. minetest.swap_node(two_above_right_here, {name="bushes:BushLeaves"..leaf_type})
  182. end
  183. end
  184. end
  185. biome_lib:register_generate_plant({
  186. surface = {
  187. "default:dirt_with_grass",
  188. "stoneage:grass_with_silex",
  189. "sumpf:peat",
  190. "sumpf:sumpf"
  191. },
  192. max_count = 15, --10,15
  193. rarity = 101 - 4, --3,4
  194. min_elevation = 1, -- above sea level
  195. plantlife_limit = -0.9,
  196. },
  197. abstract_bushes.grow_bush
  198. )
  199. abstract_bushes.grow_youngtree2 = function(pos)
  200. local height = math.random(4,5)
  201. abstract_bushes.grow_youngtree_node2(pos,height)
  202. end
  203. abstract_bushes.grow_youngtree_node2 = function(pos, height)
  204. local right_here = {x=pos.x, y=pos.y+1, z=pos.z}
  205. local above_right_here = {x=pos.x, y=pos.y+2, z=pos.z}
  206. local two_above_right_here = {x=pos.x, y=pos.y+3, z=pos.z}
  207. local three_above_right_here = {x=pos.x, y=pos.y+4, z=pos.z}
  208. if minetest.get_node(right_here).name == "air" -- instead of check_air = true,
  209. or minetest.get_node(right_here).name == "default:junglegrass" then
  210. if height == 4 then
  211. local two_above_right_here_south = {x=pos.x, y=pos.y+3, z=pos.z-1}
  212. local three_above_right_here_south = {x=pos.x, y=pos.y+4, z=pos.z-1}
  213. minetest.swap_node(right_here, {name="bushes:youngtree2_bottom"})
  214. minetest.swap_node(above_right_here, {name="bushes:youngtree2_bottom"})
  215. minetest.swap_node(two_above_right_here, {name="bushes:bushbranches2" , param2=2})
  216. minetest.swap_node(two_above_right_here_south, {name="bushes:bushbranches2" , param2=0})
  217. minetest.swap_node(three_above_right_here, {name="bushes:BushLeaves1" })
  218. minetest.swap_node(three_above_right_here_south, {name="bushes:BushLeaves1" })
  219. end
  220. end
  221. end
  222. biome_lib:register_generate_plant({
  223. surface = {
  224. "default:dirt_with_grass",
  225. "stoneage:grass_with_silex",
  226. "sumpf:peat",
  227. "sumpf:sumpf"
  228. },
  229. max_count = 55, --10,15
  230. rarity = 101 - 4, --3,4
  231. min_elevation = 1, -- above sea level
  232. plantlife_limit = -0.9,
  233. },
  234. abstract_bushes.grow_youngtree2
  235. )
  236. --http://dev.minetest.net/Node_Drawtypes