You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

338 lines
11KB

  1. -- More trees! 2013-04-07
  2. --
  3. -- This mod adds more types of trees to the game
  4. --
  5. -- Some of the node definitions and textures came from cisoun's conifers mod
  6. -- and bas080's jungle trees mod.
  7. --
  8. -- Brought together into one mod and made L-systems compatible by Vanessa
  9. -- Ezekowitz.
  10. --
  11. -- Firs and Jungle tree axioms/rules by Vanessa Dannenberg, with the
  12. -- latter having been tweaked by RealBadAngel, most other axioms/rules written
  13. -- by RealBadAngel.
  14. --
  15. moretrees = {}
  16. minetest.override_item("default:sapling", {
  17. description = "Sapling"
  18. })
  19. minetest.override_item("default:tree", {
  20. description = "Tree"
  21. })
  22. minetest.override_item("default:wood", {
  23. description = "Wooden Planks"
  24. })
  25. minetest.override_item("default:leaves", {
  26. description = "Leaves"
  27. })
  28. minetest.override_item("default:fence_wood", {
  29. description = "Wooden Fence"
  30. })
  31. minetest.override_item("default:fence_rail_wood", {
  32. description = "Wooden Fence Rail"
  33. })
  34. if minetest.get_modpath("doors") then
  35. minetest.override_item("doors:gate_wood_closed", {
  36. description = "Wooden Fence Gate"
  37. })
  38. minetest.override_item("doors:gate_wood_open", {
  39. description = "Wooden Fence Gate"
  40. })
  41. end
  42. -- Read the default config file (and if necessary, copy it to the world folder).
  43. local worldpath=minetest.get_worldpath()
  44. local modpath=minetest.get_modpath("moretrees")
  45. dofile(modpath.."/default_settings.txt")
  46. if io.open(worldpath.."/moretrees_settings.txt","r") then
  47. io.close()
  48. dofile(worldpath.."/moretrees_settings.txt")
  49. end
  50. -- Boilerplate to support localized strings if intllib mod is installed.
  51. local S
  52. if minetest.get_modpath("intllib") then
  53. S = intllib.Getter()
  54. else
  55. S = function(s) return s end
  56. end
  57. moretrees.intllib = S
  58. -- infinite stacks checking
  59. if minetest.get_modpath("unified_inventory") or not
  60. minetest.settings:get_bool("creative_mode") then
  61. moretrees.expect_infinite_stacks = false
  62. else
  63. moretrees.expect_infinite_stacks = true
  64. end
  65. -- tables, load other files
  66. moretrees.cutting_tools = {
  67. "default:axe_bronze",
  68. "default:axe_diamond",
  69. "default:axe_mese",
  70. "default:axe_steel",
  71. "glooptest:axe_alatro",
  72. "glooptest:axe_arol",
  73. "moreores:axe_mithril",
  74. "moreores:axe_silver",
  75. "titanium:axe",
  76. }
  77. dofile(modpath.."/tree_models.lua")
  78. dofile(modpath.."/node_defs.lua")
  79. dofile(modpath.."/date_palm.lua")
  80. dofile(modpath.."/cocos_palm.lua")
  81. dofile(modpath.."/biome_defs.lua")
  82. dofile(modpath.."/saplings.lua")
  83. dofile(modpath.."/crafts.lua")
  84. -- tree spawning setup
  85. if moretrees.spawn_saplings then
  86. moretrees.spawn_beech_object = "moretrees:beech_sapling_ongen"
  87. moretrees.spawn_apple_tree_object = "moretrees:apple_tree_sapling_ongen"
  88. moretrees.spawn_oak_object = "moretrees:oak_sapling_ongen"
  89. moretrees.spawn_sequoia_object = "moretrees:sequoia_sapling_ongen"
  90. moretrees.spawn_palm_object = "moretrees:palm_sapling_ongen"
  91. moretrees.spawn_date_palm_object = "moretrees:date_palm_sapling_ongen"
  92. moretrees.spawn_cedar_object = "moretrees:cedar_sapling_ongen"
  93. moretrees.spawn_rubber_tree_object = "moretrees:rubber_tree_sapling_ongen"
  94. moretrees.spawn_willow_object = "moretrees:willow_sapling_ongen"
  95. moretrees.spawn_birch_object = "moretrees:birch_sapling_ongen"
  96. moretrees.spawn_spruce_object = "moretrees:spruce_sapling_ongen"
  97. moretrees.spawn_jungletree_object = "moretrees:jungletree_sapling_ongen"
  98. moretrees.spawn_fir_object = "moretrees:fir_sapling_ongen"
  99. moretrees.spawn_fir_snow_object = "snow:sapling_pine"
  100. moretrees.spawn_poplar_object = "moretrees:poplar_sapling_ongen"
  101. moretrees.spawn_poplar_small_object = "moretrees:poplar_small_sapling_ongen"
  102. else
  103. moretrees.spawn_beech_object = moretrees.beech_model
  104. moretrees.spawn_apple_tree_object = moretrees.apple_tree_model
  105. moretrees.spawn_oak_object = moretrees.oak_model
  106. moretrees.spawn_sequoia_object = moretrees.sequoia_model
  107. moretrees.spawn_palm_object = moretrees.palm_model
  108. moretrees.spawn_date_palm_object = moretrees.date_palm_model
  109. moretrees.spawn_cedar_object = moretrees.cedar_model
  110. moretrees.spawn_rubber_tree_object = moretrees.rubber_tree_model
  111. moretrees.spawn_willow_object = moretrees.willow_model
  112. moretrees.spawn_birch_object = "moretrees.grow_birch"
  113. moretrees.spawn_spruce_object = "moretrees.grow_spruce"
  114. moretrees.spawn_jungletree_object = "moretrees.grow_jungletree"
  115. moretrees.spawn_fir_object = "moretrees.grow_fir"
  116. moretrees.spawn_fir_snow_object = "moretrees.grow_fir_snow"
  117. moretrees.spawn_poplar_object = moretrees.poplar_model
  118. moretrees.spawn_poplar_small_object = moretrees.poplar_small_model
  119. end
  120. if moretrees.enable_beech then
  121. biome_lib:register_generate_plant(moretrees.beech_biome, moretrees.spawn_beech_object)
  122. end
  123. if moretrees.enable_apple_tree then
  124. biome_lib:register_generate_plant(moretrees.apple_tree_biome, moretrees.spawn_apple_tree_object)
  125. end
  126. if moretrees.enable_oak then
  127. biome_lib:register_generate_plant(moretrees.oak_biome, moretrees.spawn_oak_object)
  128. end
  129. if moretrees.enable_sequoia then
  130. biome_lib:register_generate_plant(moretrees.sequoia_biome, moretrees.spawn_sequoia_object)
  131. end
  132. if moretrees.enable_palm then
  133. biome_lib:register_generate_plant(moretrees.palm_biome, moretrees.spawn_palm_object)
  134. end
  135. if moretrees.enable_date_palm then
  136. biome_lib:register_generate_plant(moretrees.date_palm_biome, moretrees.spawn_date_palm_object)
  137. biome_lib:register_generate_plant(moretrees.date_palm_biome_2, moretrees.spawn_date_palm_object)
  138. end
  139. if moretrees.enable_cedar then
  140. biome_lib:register_generate_plant(moretrees.cedar_biome, moretrees.spawn_cedar_object)
  141. end
  142. if moretrees.enable_rubber_tree then
  143. biome_lib:register_generate_plant(moretrees.rubber_tree_biome, moretrees.spawn_rubber_tree_object)
  144. end
  145. if moretrees.enable_willow then
  146. biome_lib:register_generate_plant(moretrees.willow_biome, moretrees.spawn_willow_object)
  147. end
  148. if moretrees.enable_birch then
  149. biome_lib:register_generate_plant(moretrees.birch_biome, moretrees.spawn_birch_object)
  150. end
  151. if moretrees.enable_spruce then
  152. biome_lib:register_generate_plant(moretrees.spruce_biome, moretrees.spawn_spruce_object)
  153. end
  154. if moretrees.enable_jungle_tree then
  155. biome_lib:register_generate_plant(moretrees.jungletree_biome, moretrees.spawn_jungletree_object)
  156. end
  157. if moretrees.enable_fir then
  158. biome_lib:register_generate_plant(moretrees.fir_biome, moretrees.spawn_fir_object)
  159. if minetest.get_modpath("snow") then
  160. biome_lib:register_generate_plant(moretrees.fir_biome_snow, moretrees.spawn_fir_snow_object)
  161. end
  162. end
  163. if moretrees.enable_poplar then
  164. biome_lib:register_generate_plant(moretrees.poplar_biome, moretrees.spawn_poplar_object)
  165. biome_lib:register_generate_plant(moretrees.poplar_biome_2, moretrees.spawn_poplar_object)
  166. biome_lib:register_generate_plant(moretrees.poplar_biome_3, moretrees.spawn_poplar_object)
  167. biome_lib:register_generate_plant(moretrees.poplar_small_biome, moretrees.spawn_poplar_small_object)
  168. biome_lib:register_generate_plant(moretrees.poplar_small_biome_2, moretrees.spawn_poplar_small_object)
  169. end
  170. -- Code to spawn a birch tree
  171. function moretrees.grow_birch(pos)
  172. minetest.swap_node(pos, biome_lib.air)
  173. if math.random(1,2) == 1 then
  174. minetest.spawn_tree(pos, moretrees.birch_model1)
  175. else
  176. minetest.spawn_tree(pos, moretrees.birch_model2)
  177. end
  178. end
  179. -- Code to spawn a spruce tree
  180. function moretrees.grow_spruce(pos)
  181. minetest.swap_node(pos, biome_lib.air)
  182. if math.random(1,2) == 1 then
  183. minetest.spawn_tree(pos, moretrees.spruce_model1)
  184. else
  185. minetest.spawn_tree(pos, moretrees.spruce_model2)
  186. end
  187. end
  188. -- Code to spawn jungle trees
  189. moretrees.jt_axiom1 = "FFFA"
  190. moretrees.jt_rules_a1 = "FFF[&&-FBf[&&&Ff]^^^Ff][&&+FBFf[&&&FFf]^^^Ff][&&---FBFf[&&&Ff]^^^Ff][&&+++FBFf[&&&Ff]^^^Ff]F/A"
  191. moretrees.jt_rules_b1 = "[-Ff&f][+Ff&f]B"
  192. moretrees.jt_axiom2 = "FFFFFA"
  193. moretrees.jt_rules_a2 = "FFFFF[&&-FFFBF[&&&FFff]^^^FFf][&&+FFFBFF[&&&FFff]^^^FFf][&&---FFFBFF[&&&FFff]^^^FFf][&&+++FFFBFF[&&&FFff]^^^FFf]FF/A"
  194. moretrees.jt_rules_b2 = "[-FFf&ff][+FFf&ff]B"
  195. moretrees.ct_rules_a1 = "FF[FF][&&-FBF][&&+FBF][&&---FBF][&&+++FBF]F/A"
  196. moretrees.ct_rules_b1 = "[-FBf][+FBf]"
  197. moretrees.ct_rules_a2 = "FF[FF][&&-FBF][&&+FBF][&&---FBF][&&+++FBF]F/A"
  198. moretrees.ct_rules_b2 = "[-fB][+fB]"
  199. function moretrees.grow_jungletree(pos)
  200. local r1 = math.random(2)
  201. local r2 = math.random(3)
  202. if r1 == 1 then
  203. moretrees.jungletree_model.leaves2 = "moretrees:jungletree_leaves_red"
  204. else
  205. moretrees.jungletree_model.leaves2 = "moretrees:jungletree_leaves_yellow"
  206. end
  207. moretrees.jungletree_model.leaves2_chance = math.random(25, 75)
  208. if r2 == 1 then
  209. moretrees.jungletree_model.trunk_type = "single"
  210. moretrees.jungletree_model.iterations = 2
  211. moretrees.jungletree_model.axiom = moretrees.jt_axiom1
  212. moretrees.jungletree_model.rules_a = moretrees.jt_rules_a1
  213. moretrees.jungletree_model.rules_b = moretrees.jt_rules_b1
  214. elseif r2 == 2 then
  215. moretrees.jungletree_model.trunk_type = "double"
  216. moretrees.jungletree_model.iterations = 4
  217. moretrees.jungletree_model.axiom = moretrees.jt_axiom2
  218. moretrees.jungletree_model.rules_a = moretrees.jt_rules_a2
  219. moretrees.jungletree_model.rules_b = moretrees.jt_rules_b2
  220. elseif r2 == 3 then
  221. moretrees.jungletree_model.trunk_type = "crossed"
  222. moretrees.jungletree_model.iterations = 4
  223. moretrees.jungletree_model.axiom = moretrees.jt_axiom2
  224. moretrees.jungletree_model.rules_a = moretrees.jt_rules_a2
  225. moretrees.jungletree_model.rules_b = moretrees.jt_rules_b2
  226. end
  227. minetest.swap_node(pos, biome_lib.air)
  228. local leaves = minetest.find_nodes_in_area({x = pos.x-1, y = pos.y, z = pos.z-1}, {x = pos.x+1, y = pos.y+10, z = pos.z+1}, "default:leaves")
  229. for leaf in ipairs(leaves) do
  230. minetest.swap_node(leaves[leaf], biome_lib.air)
  231. end
  232. minetest.spawn_tree(pos, moretrees.jungletree_model)
  233. end
  234. -- code to spawn fir trees
  235. function moretrees.grow_fir(pos)
  236. if math.random(2) == 1 then
  237. moretrees.fir_model.leaves="moretrees:fir_leaves"
  238. else
  239. moretrees.fir_model.leaves="moretrees:fir_leaves_bright"
  240. end
  241. if math.random(2) == 1 then
  242. moretrees.fir_model.rules_a = moretrees.ct_rules_a1
  243. moretrees.fir_model.rules_b = moretrees.ct_rules_b1
  244. else
  245. moretrees.fir_model.rules_a = moretrees.ct_rules_a2
  246. moretrees.fir_model.rules_b = moretrees.ct_rules_b2
  247. end
  248. moretrees.fir_model.iterations = 7
  249. moretrees.fir_model.random_level = 5
  250. minetest.swap_node(pos, biome_lib.air)
  251. local leaves = minetest.find_nodes_in_area({x = pos.x, y = pos.y, z = pos.z}, {x = pos.x, y = pos.y+5, z = pos.z}, "default:leaves")
  252. for leaf in ipairs(leaves) do
  253. minetest.swap_node(leaves[leaf], biome_lib.air)
  254. end
  255. minetest.spawn_tree(pos,moretrees.fir_model)
  256. end
  257. -- same thing, but a smaller version that grows only in snow biomes
  258. function moretrees.grow_fir_snow(pos)
  259. if math.random(2) == 1 then
  260. moretrees.fir_model.leaves="moretrees:fir_leaves"
  261. else
  262. moretrees.fir_model.leaves="moretrees:fir_leaves_bright"
  263. end
  264. if math.random(2) == 1 then
  265. moretrees.fir_model.rules_a = moretrees.ct_rules_a1
  266. moretrees.fir_model.rules_b = moretrees.ct_rules_b1
  267. else
  268. moretrees.fir_model.rules_a = moretrees.ct_rules_a2
  269. moretrees.fir_model.rules_b = moretrees.ct_rules_b2
  270. end
  271. moretrees.fir_model.iterations = 2
  272. moretrees.fir_model.random_level = 2
  273. minetest.swap_node(pos, biome_lib.air)
  274. local leaves = minetest.find_nodes_in_area({x = pos.x, y = pos.y, z = pos.z}, {x = pos.x, y = pos.y+5, z = pos.z}, "default:leaves")
  275. for leaf in ipairs(leaves) do
  276. minetest.swap_node(leaves[leaf], biome_lib.air)
  277. end
  278. minetest.spawn_tree(pos,moretrees.fir_model)
  279. end
  280. print(S("[Moretrees] Loaded (2013-02-11)"))