jungletree.lua 5.7 KB

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