jungletree.lua 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. moretrees = moretrees or {}
  2. local SAPLING_TIME_MIN = 60*10
  3. local SAPLING_TIME_MAX = 60*20
  4. local SAPLING_CHANCE = 40
  5. local SCHEMATIC_MINP = {x=-2, y=0, z=-2}
  6. local SCHEMATIC_MAXP = {x=2, y=14, z=2}
  7. local SCHEMATIC_RELP = {x=-2, y=0, z=-2}
  8. -- Localize for performance.
  9. local math_random = math.random
  10. local leafcolors = {
  11. {name="red", capitalized="Red"},
  12. {name="green", capitalized="Green"},
  13. {name="yellow", capitalized="Yellow"}
  14. }
  15. for k, v in pairs(leafcolors) do
  16. local name = v.name
  17. local capitalized = v.capitalized
  18. minetest.register_node("moretrees:jungletree_leaves_" .. name, {
  19. description = capitalized .. " Jungletree Leaves",
  20. drawtype = "allfaces_optional",
  21. visual_scale = 1.3,
  22. tiles = {"moretrees_jungletree_leaves_" .. name .. ".png"},
  23. paramtype = "light",
  24. groups = moretrees.leaves_groups,
  25. drop = moretrees.get_leafdrop_table(SAPLING_CHANCE, "moretrees:jungletree_sapling", "moretrees:jungletree_leaves_" .. name),
  26. sounds = default.node_sound_leaves_defaults(),
  27. waving = 1,
  28. movement_speed_multiplier = default.SLOW_SPEED,
  29. on_construct = enhanced_leafdecay.make_leaf_constructor({}),
  30. on_timer = enhanced_leafdecay.make_leaf_nodetimer({tree="moretrees:jungletree_tree"}),
  31. })
  32. end
  33. minetest.register_node("moretrees:jungletree_tree", {
  34. drawtype = "nodebox",
  35. paramtype = "light",
  36. node_box = {
  37. type = "fixed",
  38. fixed = basictrees.trunk_nodebox,
  39. },
  40. description = "Jungletree Tree",
  41. tiles = {
  42. "moretrees_jungletree_trunk_top.png",
  43. "moretrees_jungletree_trunk_top.png",
  44. "moretrees_jungletree_trunk.png"
  45. },
  46. paramtype2 = "facedir",
  47. groups = moretrees.tree_groups,
  48. sounds = default.node_sound_wood_defaults(),
  49. on_place = minetest.rotate_node,
  50. movement_speed_multiplier = default.NORM_SPEED,
  51. on_destruct = enhanced_leafdecay.make_tree_destructor({
  52. leaves = {
  53. "moretrees:jungletree_leaves_red",
  54. "moretrees:jungletree_leaves_green",
  55. "moretrees:jungletree_leaves_yellow",
  56. "group:dry_leaves",
  57. },
  58. }),
  59. })
  60. minetest.register_node("moretrees:jungletree_sapling", {
  61. description = "Jungletree Sapling\n\nWill not grow in deep caves.",
  62. drawtype = "plantlike",
  63. --visual_scale = 1.0,
  64. tiles = {"moretrees_jungletree_sapling.png"},
  65. paramtype = "light",
  66. sunlight_propagates = true,
  67. walkable = false,
  68. selection_box = moretrees.sapling_selection_box,
  69. groups = moretrees.sapling_groups,
  70. sounds = default.node_sound_leaves_defaults(),
  71. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  72. on_timer = function(pos, elapsed)
  73. if mtflower.can_grow(pos) then
  74. if mtflower.try_grow(pos, "moretrees:jungletree_tree", "moretrees:jungletree_leaves_red", "glowstone:minerals", "glowstone:minerals") then
  75. return
  76. end
  77. end
  78. if not moretrees.can_grow(pos) then
  79. minetest.get_node_timer(pos):start(math_random(SAPLING_TIME_MIN, SAPLING_TIME_MAX))
  80. return
  81. end
  82. minetest.set_node(pos, {name='air'}) -- Remove sapling first.
  83. schems = {
  84. "jungletree_red.mts",
  85. "jungletree_yellow.mts",
  86. "jungletree_green.mts",
  87. }
  88. local path = moretrees.modpath .. "/schematics/" .. schems[math_random(1, #schems)]
  89. local schempos = vector.add(pos, SCHEMATIC_RELP)
  90. local subtract = math_random(0, math_random(0, 4))
  91. schempos.y = schempos.y - subtract
  92. minetest.place_schematic(schempos, path, "random", nil, false)
  93. trunkgen.generate_bole(pos, "moretrees:jungletree_tree")
  94. trunkgen.generate_jungletree_branches(
  95. pos, "moretrees:jungletree_tree",
  96. {"moretrees:jungletree_leaves_red", "moretrees:jungletree_leaves_green", "moretrees:jungletree_leaves_yellow"},
  97. 3, 10-subtract)
  98. hb4.leafscatter.remove(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, "moretrees:jungletree_leaves_green", math_random(10, 30))
  99. hb4.leafscatter.remove(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, "moretrees:jungletree_leaves_red", math_random(10, 30))
  100. hb4.leafscatter.remove(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, "moretrees:jungletree_leaves_yellow", math_random(10, 30))
  101. hb4.leafscatter.add(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, "moretrees:jungletree_leaves_green", math_random(10, 30))
  102. hb4.leafscatter.add(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, "moretrees:jungletree_leaves_red", math_random(10, 30))
  103. hb4.leafscatter.add(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, "moretrees:jungletree_leaves_yellow", math_random(10, 30))
  104. snowscatter.dump_snowdust_on_tree(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP)
  105. ambiance.spawn_sound_beacon_inside_area("soundbeacon:trees", pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, 40, 3)
  106. end,
  107. on_construct = function(pos)
  108. minetest.get_node_timer(pos):start(math_random(SAPLING_TIME_MIN, SAPLING_TIME_MAX))
  109. end,
  110. on_place = function(itemstack, placer, pointed_thing)
  111. itemstack = default.sapling_on_place(itemstack, placer, pointed_thing,
  112. "moretrees:jungletree_sapling", SCHEMATIC_MINP, SCHEMATIC_MAXP, 4)
  113. return itemstack
  114. end,
  115. })
  116. minetest.register_node("moretrees:jungletree_wood", {
  117. description = "Fine Jungle Planks",
  118. paramtype2 = "facedir",
  119. place_param2 = 0,
  120. tiles = {"moretrees_jungletree_wood.png"},
  121. groups = moretrees.get_wood_groups({wood_dark = 1}),
  122. sounds = default.node_sound_wood_defaults(),
  123. })
  124. minetest.register_craft({
  125. output = 'moretrees:jungletree_wood 4',
  126. recipe = {
  127. {'moretrees:jungletree_tree'},
  128. }
  129. })
  130. minetest.register_craft({
  131. output = "default:fence_junglewood 4",
  132. recipe = {
  133. {"moretrees:jungletree_wood", 'group:stick', "moretrees:jungletree_wood"},
  134. {"moretrees:jungletree_wood", 'group:stick', "moretrees:jungletree_wood"},
  135. }
  136. })
  137. minetest.register_craft({
  138. output = "doors:gate_junglewood_closed",
  139. recipe = {
  140. {"group:stick", "moretrees:jungletree_wood", "group:stick"},
  141. {"group:stick", "moretrees:jungletree_wood", "group:stick"}
  142. }
  143. })
  144. stairs.register_stair_and_slab(
  145. "jungletree_wood",
  146. "moretrees:jungletree_wood",
  147. moretrees.stair_groups,
  148. {"moretrees_jungletree_wood.png"},
  149. "Fine Jungle",
  150. default.node_sound_wood_defaults()
  151. )