rubber_tree.lua 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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=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. visual_scale = 1.3,
  64. tiles = {"moretrees_rubber_tree_leaves.png"},
  65. paramtype = "light",
  66. waving = 1,
  67. groups = moretrees.leaves_groups,
  68. drop = moretrees.get_leafdrop_table(SAPLING_CHANCE, "moretrees:rubber_tree_sapling", "moretrees:rubber_tree_leaves"),
  69. sounds = default.node_sound_leaves_defaults(),
  70. movement_speed_multiplier = default.SLOW_SPEED,
  71. on_construct = enhanced_leafdecay.make_leaf_constructor({}),
  72. on_timer = enhanced_leafdecay.make_leaf_nodetimer({
  73. tree = {
  74. "moretrees:rubber_tree_tree",
  75. "moretrees:rubber_tree_trunk_empty",
  76. },
  77. }),
  78. })
  79. minetest.register_node("moretrees:rubber_tree_wood", {
  80. description = "Rubber Tree Planks",
  81. paramtype2 = "facedir",
  82. place_param2 = 0,
  83. tiles = {"moretrees_rubber_tree_wood.png"},
  84. groups = moretrees.get_wood_groups({wood_light = 1}),
  85. sounds = default.node_sound_wood_defaults(),
  86. })
  87. minetest.register_node("moretrees:rubber_tree_sapling", {
  88. description = "Rubber Tree Sapling\n\nWill not grow in deep caves.\nGives raw latex.",
  89. drawtype = "plantlike",
  90. --visual_scale = 1.0,
  91. tiles = {"moretrees_rubber_tree_sapling.png"},
  92. paramtype = "light",
  93. sunlight_propagates = true,
  94. walkable = false,
  95. selection_box = moretrees.sapling_selection_box,
  96. groups = moretrees.sapling_groups,
  97. sounds = default.node_sound_leaves_defaults(),
  98. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  99. on_timer = function(pos, elapsed)
  100. if mtflower.can_grow(pos) then
  101. if mtflower.try_grow(pos, "moretrees:rubber_tree_tree", "moretrees:rubber_tree_leaves", "glowstone:minerals", "glowstone:minerals") then
  102. return
  103. end
  104. end
  105. if not moretrees.can_grow(pos) then
  106. minetest.get_node_timer(pos):start(math_random(SAPLING_TIME_MIN, SAPLING_TIME_MAX))
  107. return
  108. end
  109. minetest.set_node(pos, {name='air'}) -- Remove sapling first.
  110. local path = moretrees.modpath .. "/schematics/rubber_tree.mts"
  111. minetest.place_schematic(vector.add(vector.add(pos, {x=0, y=math_random(-1, 1), z=0}), SCHEMATIC_RELP), path, "random", nil, false)
  112. trunkgen.check_trunk(pos, 3, "moretrees:rubber_tree_tree")
  113. hb4.leafscatter.remove(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, "moretrees:rubber_tree_leaves", math_random(10, 30))
  114. hb4.leafscatter.add(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, "moretrees:rubber_tree_leaves", math_random(10, 30))
  115. snowscatter.dump_snowdust_on_tree(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP)
  116. ambiance.spawn_sound_beacon_inside_area("soundbeacon:trees", pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, 40, 3)
  117. end,
  118. on_construct = function(pos)
  119. minetest.get_node_timer(pos):start(math_random(SAPLING_TIME_MIN, SAPLING_TIME_MAX))
  120. end,
  121. on_place = function(itemstack, placer, pointed_thing)
  122. itemstack = default.sapling_on_place(itemstack, placer, pointed_thing,
  123. "moretrees:rubber_tree_sapling", SCHEMATIC_MINP, SCHEMATIC_MAXP, 4)
  124. return itemstack
  125. end,
  126. })
  127. minetest.register_craft({
  128. output = 'moretrees:rubber_tree_wood 4',
  129. recipe = {
  130. {'moretrees:rubber_tree_tree'},
  131. }
  132. })
  133. minetest.register_craft({
  134. output = "default:fence_wood 4",
  135. recipe = {
  136. {"moretrees:rubber_tree_wood", 'group:stick', "moretrees:rubber_tree_wood"},
  137. {"moretrees:rubber_tree_wood", 'group:stick', "moretrees:rubber_tree_wood"},
  138. }
  139. })
  140. minetest.register_craft({
  141. output = "doors:gate_wood_closed",
  142. recipe = {
  143. {"group:stick", "moretrees:rubber_tree_wood", "group:stick"},
  144. {"group:stick", "moretrees:rubber_tree_wood", "group:stick"}
  145. }
  146. })
  147. stairs.register_stair_and_slab(
  148. "rubber_tree",
  149. "moretrees:rubber_tree_wood",
  150. moretrees.stair_groups,
  151. {"moretrees_rubber_tree_wood.png"},
  152. "Rubber Tree Plank",
  153. default.node_sound_wood_defaults()
  154. )