jungletree.lua 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. basictrees = basictrees or {}
  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=1, 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. visual_scale = 1.3,
  61. tiles = {"default_jungleleaves.png"},
  62. --special_tiles = {"default_jungleleaves_simple.png"},
  63. paramtype = "light",
  64. groups = basictrees.leaves_groups,
  65. drop = basictrees.get_leafdrop_table(SAPLING_CHANCE, "basictrees:jungletree_sapling", "basictrees:jungletree_leaves"),
  66. sounds = default.node_sound_leaves_defaults(),
  67. movement_speed_multiplier = default.SLOW_SPEED,
  68. on_construct = enhanced_leafdecay.make_leaf_constructor({}),
  69. on_timer = enhanced_leafdecay.make_leaf_nodetimer({tree="basictrees:jungletree_trunk"}),
  70. })
  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. --special_tiles = {"default_jungleleaves_simple.png"},
  77. paramtype = "light",
  78. groups = basictrees.cw_leaves_groups,
  79. drop = basictrees.get_leafdrop_table(SAPLING_CHANCE, "basictrees:jungletree_sapling", "basictrees:jungletree_leaves"),
  80. sounds = default.node_sound_leaves_defaults(),
  81. movement_speed_multiplier = default.SLOW_SPEED,
  82. on_construct = enhanced_leafdecay.make_leaf_constructor({}),
  83. on_timer = enhanced_leafdecay.make_leaf_nodetimer({tree="basictrees:jungletree_cube"}),
  84. })
  85. minetest.register_node("basictrees:jungletree_sapling", {
  86. description = "Jungle Tree Sapling\n\nWill not grow in deep caves.",
  87. drawtype = "plantlike",
  88. --visual_scale = 1.0,
  89. tiles = {"default_junglesapling.png"},
  90. inventory_image = "default_junglesapling.png",
  91. wield_image = "default_junglesapling.png",
  92. paramtype = "light",
  93. sunlight_propagates = true,
  94. walkable = false,
  95. selection_box = basictrees.sapling_selection_box,
  96. groups = basictrees.sapling_groups,
  97. sounds = default.node_sound_leaves_defaults(),
  98. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  99. on_timer = function(pos)
  100. if mtflower.can_grow(pos) then
  101. if mtflower.try_grow(pos, "basictrees:jungletree_trunk", "basictrees:jungletree_leaves", "glowstone:minerals", "glowstone:minerals") then
  102. return
  103. end
  104. end
  105. if not basictrees.can_grow(pos) then
  106. minetest.get_node_timer(pos):start(math_random(SAPLING_TIME_MIN, SAPLING_TIME_MAX))
  107. return
  108. end
  109. local path = basictrees.modpath .. "/schematics/jungle_tree_from_sapling.mts"
  110. minetest.place_schematic(vector.add(pos, SCHEMATIC_RELP), path, "random", nil, false)
  111. hb4.leafscatter.remove(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, "basictrees:jungletree_leaves", math_random(10, 30))
  112. hb4.leafscatter.add(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, "basictrees:jungletree_leaves", math_random(10, 30))
  113. snowscatter.dump_snowdust_on_tree(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP)
  114. ambiance.spawn_sound_beacon_inside_area("soundbeacon:trees", pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, 40, 3)
  115. end,
  116. on_construct = function(pos)
  117. minetest.get_node_timer(pos):start(math_random(SAPLING_TIME_MIN, SAPLING_TIME_MAX))
  118. end,
  119. on_place = function(itemstack, placer, pointed_thing)
  120. itemstack = default.sapling_on_place(itemstack, placer, pointed_thing,
  121. "basictrees:jungletree_sapling", SCHEMATIC_MINP, SCHEMATIC_MAXP, 4)
  122. return itemstack
  123. end,
  124. })
  125. minetest.register_craft({
  126. output = 'basictrees:jungletree_wood 4',
  127. recipe = {
  128. {'basictrees:jungletree_trunk'},
  129. }
  130. })
  131. minetest.register_alias("default:jungletree", "basictrees:jungletree_trunk")
  132. minetest.register_alias("default:jungleleaves", "basictrees:jungletree_leaves")
  133. minetest.register_alias("default:junglesapling", "basictrees:jungletree_sapling")
  134. minetest.register_alias("default:junglewood", "basictrees:jungletree_wood")
  135. minetest.register_alias("basictrees:jungletree_tree", "basictrees:jungletree_trunk")