init.lua 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. jungletree = jungletree or {}
  2. jungletree.modpath = minetest.get_modpath("jungletree")
  3. -- Localize for performance.
  4. local math_random = math.random
  5. local SAPLING_TIME_MIN = 60*15
  6. local SAPLING_TIME_MAX = 60*20
  7. local SAPLING_CHANCE = 25
  8. local SCHEMATIC_MINP = {x=-2, y=0, z=-2}
  9. local SCHEMATIC_MAXP = {x=2, y=12, z=2}
  10. local SCHEMATIC_RELP = {x=-2, y=0, z=-2}
  11. jungletree.can_grow = function(pos)
  12. return basictrees.can_grow(pos)
  13. end
  14. jungletree.sapling_selection_box = {
  15. type = "fixed",
  16. fixed = {-0.3, -0.5, -0.3, 0.3, 0.35, 0.3},
  17. }
  18. jungletree.sapling_groups = utility.dig_groups("plant", {
  19. flammable = 2,
  20. attached_node = 1,
  21. sapling = 1,
  22. })
  23. jungletree.tree_groups = utility.dig_groups("tree", {
  24. flammable = 2,
  25. tree = 1,
  26. })
  27. jungletree.get_wood_groups = function(extra)
  28. local groups = utility.dig_groups("wood", extra or {})
  29. groups.flammable = 2
  30. groups.wood = 1
  31. return groups
  32. end
  33. jungletree.stair_groups = utility.dig_groups("wood", {
  34. flammable = 2,
  35. })
  36. jungletree.leaves_groups = utility.dig_groups("leaves", {
  37. leafdecay = 3,
  38. flammable = 2,
  39. leaves = 1,
  40. green_leaves = 1,
  41. })
  42. jungletree.get_leafdrop_table = function(chance, sapling, leaves)
  43. local drop = {
  44. max_items = 1,
  45. items = {
  46. {items={sapling}, rarity=chance},
  47. {items={"default:stick"}, rarity=10},
  48. -- Player will get leaves only if he gets nothing else; this is because 'max_items' is 1.
  49. {items={leaves}},
  50. }
  51. }
  52. return drop
  53. end
  54. minetest.register_node("jungletree:jungletree_tree", {
  55. drawtype = "nodebox",
  56. paramtype = "light",
  57. node_box = {
  58. type = "fixed",
  59. fixed = basictrees.trunk_nodebox,
  60. },
  61. description = "White Jungletree",
  62. tiles = {
  63. "jungletree_jungletree_top.png",
  64. "jungletree_jungletree_top.png",
  65. "jungletree_jungletree_side.png"
  66. },
  67. paramtype2 = "facedir",
  68. groups = jungletree.tree_groups,
  69. sounds = default.node_sound_wood_defaults(),
  70. on_place = minetest.rotate_node,
  71. movement_speed_multiplier = default.NORM_SPEED,
  72. on_destruct = enhanced_leafdecay.make_tree_destructor({
  73. leaves = {
  74. "jungletree:jungletree_leaves",
  75. "group:dry_leaves",
  76. },
  77. }),
  78. })
  79. minetest.register_node("jungletree:jungletree_leaves", {
  80. description = "Jungletree Leaves",
  81. drawtype = "allfaces_optional",
  82. visual_scale = 1.3,
  83. tiles = {"jungletree_jungletree_leaves.png"},
  84. paramtype = "light",
  85. waving = 1,
  86. groups = jungletree.leaves_groups,
  87. drop = jungletree.get_leafdrop_table(SAPLING_CHANCE, "jungletree:jungletree_sapling", "jungletree:jungletree_leaves"),
  88. sounds = default.node_sound_leaves_defaults(),
  89. movement_speed_multiplier = default.SLOW_SPEED,
  90. on_construct = enhanced_leafdecay.make_leaf_constructor({}),
  91. on_timer = enhanced_leafdecay.make_leaf_nodetimer({tree="jungletree:jungletree_tree"}),
  92. })
  93. minetest.register_node("jungletree:jungletree_wood", {
  94. description = "Jungletree Planks",
  95. paramtype2 = "facedir",
  96. place_param2 = 0,
  97. tiles = {"jungletree_jungletree_wood.png"},
  98. groups = jungletree.get_wood_groups({wood_dark = 1}),
  99. sounds = default.node_sound_wood_defaults(),
  100. })
  101. minetest.register_node("jungletree:jungletree_sapling", {
  102. description = "White Jungletree Sapling\n\nWill not grow in deep caves.",
  103. drawtype = "plantlike",
  104. --visual_scale = 1.0,
  105. tiles = {"jungletree_jungletree_sapling.png"},
  106. paramtype = "light",
  107. sunlight_propagates = true,
  108. walkable = false,
  109. selection_box = jungletree.sapling_selection_box,
  110. groups = jungletree.sapling_groups,
  111. sounds = default.node_sound_leaves_defaults(),
  112. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  113. on_timer = function(pos, elapsed)
  114. if mtflower.can_grow(pos) then
  115. if mtflower.try_grow(pos, "jungletree:jungletree_tree", "jungletree:jungletree_leaves", "glowstone:minerals", "glowstone:minerals") then
  116. return
  117. end
  118. end
  119. if not jungletree.can_grow(pos) then
  120. minetest.get_node_timer(pos):start(math_random(SAPLING_TIME_MIN, SAPLING_TIME_MAX))
  121. return
  122. end
  123. minetest.set_node(pos, {name='air'}) -- Remove sapling first.
  124. local path = jungletree.modpath .. "/schematics/jungletree_jungletree.mts"
  125. local schempos = vector.add(pos, SCHEMATIC_RELP)
  126. local subtract = math_random(0, math_random(0, 2))
  127. schempos.y = schempos.y - subtract
  128. minetest.place_schematic(schempos, path, "0", nil, false)
  129. trunkgen.generate_bole(pos, "jungletree:jungletree_tree")
  130. trunkgen.generate_jungletree_branches(
  131. pos,
  132. "jungletree:jungletree_tree",
  133. "jungletree:jungletree_leaves",
  134. 4, 7-subtract)
  135. snowscatter.dump_snowdust_on_tree(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP)
  136. ambiance.spawn_sound_beacon_inside_area("soundbeacon:trees", pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, 40, 3)
  137. end,
  138. on_construct = function(pos)
  139. minetest.get_node_timer(pos):start(math_random(SAPLING_TIME_MIN, SAPLING_TIME_MAX))
  140. end,
  141. on_place = function(itemstack, placer, pointed_thing)
  142. itemstack = default.sapling_on_place(itemstack, placer, pointed_thing,
  143. "jungletree:jungletree_sapling", SCHEMATIC_MINP, SCHEMATIC_MAXP, 4)
  144. return itemstack
  145. end,
  146. })
  147. minetest.register_craft({
  148. output = 'jungletree:jungletree_wood 4',
  149. recipe = {
  150. {'jungletree:jungletree_tree'},
  151. }
  152. })
  153. minetest.register_craft({
  154. output = "default:fence_junglewood 4",
  155. recipe = {
  156. {"jungletree:jungletree_wood", 'group:stick', "jungletree:jungletree_wood"},
  157. {"jungletree:jungletree_wood", 'group:stick', "jungletree:jungletree_wood"},
  158. }
  159. })
  160. minetest.register_craft({
  161. output = "doors:gate_junglewood_closed",
  162. recipe = {
  163. {"group:stick", "jungletree:jungletree_wood", "group:stick"},
  164. {"group:stick", "jungletree:jungletree_wood", "group:stick"}
  165. }
  166. })
  167. stairs.register_stair_and_slab(
  168. "white_jungletree",
  169. "jungletree:jungletree_wood",
  170. jungletree.stair_groups,
  171. {"jungletree_jungletree_wood.png"},
  172. "Jungletree Plank",
  173. default.node_sound_wood_defaults()
  174. )
  175. local find_surface = function(xz, b, t)
  176. for j=t, b, -1 do
  177. local pos = {x=xz.x, y=j, z=xz.z}
  178. local n = minetest.get_node(pos).name
  179. if snow.is_snow(n) then
  180. local pb = {x=pos.x, y=pos.y-1, z=pos.z}
  181. local nb = minetest.get_node(pb).name
  182. if nb == "default:stone" then
  183. return pos, pb -- Position, position below.
  184. else
  185. break
  186. end
  187. elseif n == "default:stone" then
  188. break
  189. end
  190. end
  191. end
  192. local chose_sapling = function(pr, pos)
  193. local name = "jungletree:jungletree_sapling"
  194. minetest.set_node(pos, {name=name})
  195. end
  196. jungletree.generate_flowers = function(minp, maxp, seed)
  197. if maxp.y < -50 or minp.y > 300 then
  198. return
  199. end
  200. local pr = PseudoRandom(seed + 7192)
  201. local count = pr:next(1, 4)
  202. if count == 1 then
  203. local xz = {x=pr:next(minp.x, maxp.x), z=pr:next(minp.z, maxp.z)}
  204. local pos, posb = find_surface(xz, minp.y, maxp.y)
  205. -- Highlands only.
  206. if pos then
  207. if pos.y < 10 then return end
  208. chose_sapling(pr, pos)
  209. minetest.set_node(posb, {name="default:mossycobble"})
  210. end
  211. end
  212. end
  213. minetest.register_on_generated(function(minp, maxp, seed)
  214. jungletree.generate_flowers(minp, maxp, seed) end)