jungletree.lua 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. if not minetest.global_exists("basictrees") then basictrees = {} end
  2. local SAPLING_TIME_MIN = 60*15
  3. local SAPLING_TIME_MAX = 60*25
  4. local SAPLING_CHANCE = 25
  5. local SCHEMATIC_MINP = {x=-2, y=0, z=-2}
  6. local SCHEMATIC_MAXP = {x=2, y=15, z=2}
  7. local SCHEMATIC_RELP = {x=-2, y=-1, z=-2}
  8. -- Localize for performance.
  9. local math_random = math.random
  10. minetest.register_node("basictrees:jungletree_trunk", {
  11. drawtype = "nodebox",
  12. paramtype = "light",
  13. node_box = {
  14. type = "fixed",
  15. fixed = basictrees.trunk_nodebox,
  16. },
  17. description = "Jungle Tree",
  18. tiles = {"default_jungletree_top.png", "default_jungletree_top.png", "default_jungletree.png"},
  19. paramtype2 = "facedir",
  20. groups = basictrees.tree_groups,
  21. sounds = default.node_sound_wood_defaults(),
  22. on_place = minetest.rotate_node,
  23. movement_speed_multiplier = default.NORM_SPEED,
  24. on_destruct = enhanced_leafdecay.make_tree_destructor({
  25. leaves = {
  26. "basictrees:jungletree_leaves",
  27. "group:dry_leaves",
  28. },
  29. }),
  30. })
  31. minetest.register_node("basictrees:jungletree_cube", {
  32. description = "Jungle Tree",
  33. tiles = {"default_jungletree_top.png", "default_jungletree_top.png", "default_jungletree.png"},
  34. paramtype2 = "facedir",
  35. groups = basictrees.cw_tree_groups,
  36. sounds = default.node_sound_wood_defaults(),
  37. on_place = minetest.rotate_node,
  38. movement_speed_multiplier = default.NORM_SPEED,
  39. drop = "basictrees:jungletree_trunk",
  40. on_destruct = enhanced_leafdecay.make_tree_destructor({
  41. leaves = {
  42. "basictrees:jungletree_leaves",
  43. "basictrees:jungletree_leaves2",
  44. "group:dry_leaves",
  45. },
  46. }),
  47. })
  48. minetest.register_node("basictrees:jungletree_wood", {
  49. description = "Jungle Wood Planks",
  50. paramtype2 = "facedir",
  51. place_param2 = 0,
  52. tiles = {"default_junglewood.png"},
  53. groups = basictrees.get_wood_groups({wood_dark = 1}),
  54. sounds = default.node_sound_wood_defaults(),
  55. })
  56. minetest.register_node("basictrees:jungletree_leaves", {
  57. description = "Jungle Tree Leaves",
  58. drawtype = "allfaces_optional",
  59. waving = 1,
  60. tiles = {"default_jungleleaves.png"},
  61. --special_tiles = {"default_jungleleaves_simple.png"},
  62. paramtype = "light",
  63. groups = basictrees.leaves_groups,
  64. drop = basictrees.get_leafdrop_table(SAPLING_CHANCE, "basictrees:jungletree_sapling", "basictrees:jungletree_leaves"),
  65. sounds = default.node_sound_leaves_defaults(),
  66. movement_speed_multiplier = default.SLOW_SPEED,
  67. on_construct = enhanced_leafdecay.make_leaf_constructor({}),
  68. on_timer = enhanced_leafdecay.make_leaf_nodetimer({tree="basictrees:jungletree_trunk"}),
  69. })
  70. -- Non-flammable version for Channelwood.
  71. minetest.register_node("basictrees:jungletree_leaves2", {
  72. description = "Jungle Tree Leaves",
  73. drawtype = "allfaces_optional",
  74. waving = 1,
  75. tiles = {"default_jungleleaves.png"},
  76. paramtype = "light",
  77. groups = basictrees.cw_leaves_groups,
  78. drop = basictrees.get_leafdrop_table(SAPLING_CHANCE, "basictrees:jungletree_sapling", "basictrees:jungletree_leaves"),
  79. sounds = default.node_sound_leaves_defaults(),
  80. movement_speed_multiplier = default.SLOW_SPEED,
  81. on_construct = enhanced_leafdecay.make_leaf_constructor({}),
  82. on_timer = enhanced_leafdecay.make_leaf_nodetimer({tree="basictrees:jungletree_cube"}),
  83. })
  84. minetest.register_node("basictrees:jungletree_sapling", {
  85. description = "Jungle Tree Sapling\n\nWill not grow in deep caves.",
  86. drawtype = "plantlike",
  87. tiles = {"default_junglesapling.png"},
  88. inventory_image = "default_junglesapling.png",
  89. wield_image = "default_junglesapling.png",
  90. paramtype = "light",
  91. sunlight_propagates = true,
  92. walkable = false,
  93. selection_box = basictrees.sapling_selection_box,
  94. groups = basictrees.sapling_groups,
  95. sounds = default.node_sound_leaves_defaults(),
  96. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  97. on_timer = function(pos)
  98. if mtflower.can_grow(pos) then
  99. if mtflower.try_grow(pos, "basictrees:jungletree_trunk", "basictrees:jungletree_leaves", "glowstone:minerals", "glowstone:minerals") then
  100. return
  101. end
  102. end
  103. if not basictrees.can_grow(pos) then
  104. minetest.get_node_timer(pos):start(math_random(SAPLING_TIME_MIN, SAPLING_TIME_MAX))
  105. return
  106. end
  107. local path = basictrees.modpath .. "/schematics/jungle_tree_from_sapling.mts"
  108. minetest.place_schematic(vector.add(pos, SCHEMATIC_RELP), path, "random", nil, false)
  109. hb4.leafscatter.remove(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, "basictrees:jungletree_leaves", math_random(10, 30))
  110. hb4.leafscatter.add(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, "basictrees:jungletree_leaves", math_random(10, 30))
  111. snowscatter.dump_snowdust_on_tree(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP)
  112. ambiance.spawn_sound_beacon_inside_area("soundbeacon:trees", pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, 40, 3)
  113. end,
  114. on_construct = function(pos)
  115. minetest.get_node_timer(pos):start(math_random(SAPLING_TIME_MIN, SAPLING_TIME_MAX))
  116. end,
  117. on_place = function(itemstack, placer, pointed_thing)
  118. itemstack = default.sapling_on_place(itemstack, placer, pointed_thing,
  119. "basictrees:jungletree_sapling", SCHEMATIC_MINP, SCHEMATIC_MAXP, 4)
  120. return itemstack
  121. end,
  122. })
  123. minetest.register_craft({
  124. output = 'basictrees:jungletree_wood 4',
  125. recipe = {
  126. {'basictrees:jungletree_trunk'},
  127. }
  128. })
  129. minetest.register_alias("default:jungletree", "basictrees:jungletree_trunk")
  130. minetest.register_alias("default:jungleleaves", "basictrees:jungletree_leaves")
  131. minetest.register_alias("default:junglesapling", "basictrees:jungletree_sapling")
  132. minetest.register_alias("default:junglewood", "basictrees:jungletree_wood")
  133. minetest.register_alias("basictrees:jungletree_tree", "basictrees:jungletree_trunk")