rubber_tree.lua 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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=8, z=2}
  7. local SCHEMATIC_RELP = {x=-2, y=0, z=-2}
  8. -- Localize for performance.
  9. local math_random = math.random
  10. minetest.register_node("moretrees:rubber_tree_tree", {
  11. drawtype = "nodebox",
  12. paramtype = "light",
  13. node_box = {
  14. type = "fixed",
  15. fixed = basictrees.trunk_nodebox,
  16. },
  17. description = "Rubber Tree",
  18. tiles = {
  19. "moretrees_rubber_tree_trunk_top.png",
  20. "moretrees_rubber_tree_trunk_top.png",
  21. "moretrees_rubber_tree_trunk.png"
  22. },
  23. paramtype2 = "facedir",
  24. groups = moretrees.tree_groups,
  25. sounds = default.node_sound_wood_defaults(),
  26. on_place = minetest.rotate_node,
  27. movement_speed_multiplier = default.NORM_SPEED,
  28. on_destruct = enhanced_leafdecay.make_tree_destructor({
  29. leaves = {
  30. "moretrees:rubber_tree_leaves",
  31. "group:dry_leaves",
  32. },
  33. }),
  34. })
  35. minetest.register_node("moretrees:rubber_tree_trunk_empty", {
  36. drawtype = "nodebox",
  37. paramtype = "light",
  38. node_box = {
  39. type = "fixed",
  40. fixed = basictrees.trunk_nodebox,
  41. },
  42. description = "Rubber Tree (Empty)",
  43. tiles = {
  44. "moretrees_rubber_tree_trunk_top.png",
  45. "moretrees_rubber_tree_trunk_top.png",
  46. "moretrees_rubber_tree_trunk_empty.png"
  47. },
  48. paramtype2 = "facedir",
  49. groups = moretrees.tree_groups,
  50. sounds = default.node_sound_wood_defaults(),
  51. on_place = minetest.rotate_node,
  52. movement_speed_multiplier = default.NORM_SPEED,
  53. on_destruct = enhanced_leafdecay.make_tree_destructor({
  54. leaves = {
  55. "moretrees:rubber_tree_leaves",
  56. "group:dry_leaves",
  57. },
  58. }),
  59. })
  60. minetest.register_node("moretrees:rubber_tree_leaves", {
  61. description = "Rubber Tree Leaves",
  62. drawtype = "allfaces_optional",
  63. tiles = {"moretrees_rubber_tree_leaves.png"},
  64. paramtype = "light",
  65. waving = 1,
  66. groups = moretrees.leaves_groups,
  67. drop = moretrees.get_leafdrop_table(SAPLING_CHANCE, "moretrees:rubber_tree_sapling", "moretrees:rubber_tree_leaves"),
  68. sounds = default.node_sound_leaves_defaults(),
  69. movement_speed_multiplier = default.SLOW_SPEED,
  70. on_construct = enhanced_leafdecay.make_leaf_constructor({}),
  71. on_timer = enhanced_leafdecay.make_leaf_nodetimer({
  72. tree = {
  73. "moretrees:rubber_tree_tree",
  74. "moretrees:rubber_tree_trunk_empty",
  75. },
  76. }),
  77. })
  78. minetest.register_node("moretrees:rubber_tree_wood", {
  79. description = "Rubber Tree Planks",
  80. paramtype2 = "facedir",
  81. place_param2 = 0,
  82. tiles = {"moretrees_rubber_tree_wood.png"},
  83. groups = moretrees.get_wood_groups({wood_light = 1}),
  84. sounds = default.node_sound_wood_defaults(),
  85. })
  86. minetest.register_node("moretrees:rubber_tree_sapling", {
  87. description = "Rubber Tree Sapling\n\nWill not grow in deep caves.\nGives raw latex.",
  88. drawtype = "plantlike",
  89. tiles = {"moretrees_rubber_tree_sapling.png"},
  90. paramtype = "light",
  91. sunlight_propagates = true,
  92. walkable = false,
  93. selection_box = moretrees.sapling_selection_box,
  94. groups = moretrees.sapling_groups,
  95. sounds = default.node_sound_leaves_defaults(),
  96. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  97. on_timer = function(pos, elapsed)
  98. if mtflower.can_grow(pos) then
  99. if mtflower.try_grow(pos, "moretrees:rubber_tree_tree", "moretrees:rubber_tree_leaves", "glowstone:minerals", "glowstone:minerals") then
  100. return
  101. end
  102. end
  103. if not moretrees.can_grow(pos) then
  104. minetest.get_node_timer(pos):start(math_random(SAPLING_TIME_MIN, SAPLING_TIME_MAX))
  105. return
  106. end
  107. minetest.set_node(pos, {name='air'}) -- Remove sapling first.
  108. local path = moretrees.modpath .. "/schematics/rubber_tree.mts"
  109. minetest.place_schematic(vector.add(vector.add(pos, {x=0, y=math_random(-1, 1), z=0}), SCHEMATIC_RELP), path, "random", nil, false)
  110. trunkgen.check_trunk(pos, 3, "moretrees:rubber_tree_tree")
  111. hb4.leafscatter.remove(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, "moretrees:rubber_tree_leaves", math_random(10, 30))
  112. hb4.leafscatter.add(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, "moretrees:rubber_tree_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. "moretrees:rubber_tree_sapling", SCHEMATIC_MINP, SCHEMATIC_MAXP, 4)
  122. return itemstack
  123. end,
  124. })
  125. minetest.register_craft({
  126. output = 'moretrees:rubber_tree_wood 4',
  127. recipe = {
  128. {'moretrees:rubber_tree_tree'},
  129. }
  130. })
  131. minetest.register_craft({
  132. output = "default:fence_wood 4",
  133. recipe = {
  134. {"moretrees:rubber_tree_wood", 'group:stick', "moretrees:rubber_tree_wood"},
  135. {"moretrees:rubber_tree_wood", 'group:stick', "moretrees:rubber_tree_wood"},
  136. }
  137. })
  138. minetest.register_craft({
  139. output = "doors:gate_wood_closed",
  140. recipe = {
  141. {"techcrafts:hinge_wood", "moretrees:rubber_tree_wood", "group:stick"},
  142. {"group:stick", "moretrees:rubber_tree_wood", "group:stick"}
  143. }
  144. })
  145. stairs.register_stair_and_slab(
  146. "rubber_tree",
  147. "moretrees:rubber_tree_wood",
  148. moretrees.stair_groups,
  149. {"moretrees_rubber_tree_wood.png"},
  150. "Rubber Tree Plank",
  151. default.node_sound_wood_defaults()
  152. )