apple_tree.lua 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. if not minetest.global_exists("moretrees") then moretrees = {} end
  2. local SAPLING_TIME_MIN = 60*10
  3. local SAPLING_TIME_MAX = 60*15
  4. local SAPLING_CHANCE = 40
  5. local SCHEMATIC_MINP = {x=-3, y=0, z=-3}
  6. local SCHEMATIC_MAXP = {x=3, y=7, z=3}
  7. local SCHEMATIC_RELP = {x=-3, y=0, z=-3}
  8. -- Localize for performance.
  9. local math_random = math.random
  10. minetest.register_node("moretrees:apple_tree_tree", {
  11. drawtype = "nodebox",
  12. paramtype = "light",
  13. node_box = {
  14. type = "fixed",
  15. fixed = basictrees.trunk_nodebox,
  16. },
  17. description = "Apple Tree",
  18. tiles = {
  19. "moretrees_apple_tree_trunk_top.png",
  20. "moretrees_apple_tree_trunk_top.png",
  21. "moretrees_apple_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:apple_tree_leaves",
  31. "moretrees:apple_tree_blossoms",
  32. "basictrees:tree_apple",
  33. "group:dry_leaves",
  34. },
  35. }),
  36. })
  37. minetest.register_node("moretrees:apple_tree_leaves", {
  38. description = "Apple Tree Leaves",
  39. drawtype = "allfaces_optional",
  40. waving = 1,
  41. tiles = {"moretrees_apple_tree_leaves.png"},
  42. paramtype = "light",
  43. groups = moretrees.leaves_groups,
  44. drop = moretrees.get_leafdrop_table(SAPLING_CHANCE, "moretrees:apple_tree_sapling", "moretrees:apple_tree_leaves"),
  45. sounds = default.node_sound_leaves_defaults(),
  46. movement_speed_multiplier = default.SLOW_SPEED,
  47. on_construct = enhanced_leafdecay.make_leaf_constructor({}),
  48. on_timer = enhanced_leafdecay.make_leaf_nodetimer({tree="moretrees:apple_tree_tree"}),
  49. })
  50. minetest.register_node("moretrees:apple_tree_wood", {
  51. description = "Apple Tree Planks",
  52. paramtype2 = "facedir",
  53. place_param2 = 0,
  54. tiles = {"moretrees_apple_tree_wood.png"},
  55. groups = moretrees.get_wood_groups({wood_light = 1}),
  56. sounds = default.node_sound_wood_defaults(),
  57. })
  58. minetest.register_node("moretrees:apple_tree_sapling", {
  59. description = "Apple Tree Sapling\n\nWill not grow in deep caves.\nGrows lots of apples.",
  60. drawtype = "plantlike",
  61. tiles = {"moretrees_apple_tree_sapling.png"},
  62. paramtype = "light",
  63. sunlight_propagates = true,
  64. walkable = false,
  65. selection_box = moretrees.sapling_selection_box,
  66. groups = moretrees.sapling_groups,
  67. sounds = default.node_sound_leaves_defaults(),
  68. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  69. on_timer = function(pos, elapsed)
  70. if mtflower.can_grow(pos) then
  71. if mtflower.try_grow(pos, "moretrees:apple_tree_tree", "moretrees:apple_tree_leaves", "glowstone:minerals", "glowstone:minerals") then
  72. return
  73. end
  74. end
  75. if not moretrees.can_grow(pos) then
  76. minetest.get_node_timer(pos):start(math_random(SAPLING_TIME_MIN, SAPLING_TIME_MAX))
  77. return
  78. end
  79. minetest.set_node(pos, {name='air'}) -- Remove sapling first.
  80. local path = moretrees.modpath .. "/schematics/apple_tree.mts"
  81. minetest.place_schematic(vector.add(vector.add(pos, {x=0, y=math_random(-1, 1), z=0}), SCHEMATIC_RELP), path, "random", nil, false)
  82. trunkgen.check_trunk(pos, 3, "moretrees:apple_tree_tree")
  83. hb4.leafscatter.remove(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, "moretrees:apple_tree_leaves", math_random(10, 30))
  84. hb4.leafscatter.add(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, "moretrees:apple_tree_leaves", math_random(10, 30))
  85. snowscatter.dump_snowdust_on_tree(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP)
  86. ambiance.spawn_sound_beacon_inside_area("soundbeacon:trees", pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, 40, 3)
  87. fruitscatter.scatter_fruit_under_leaves(
  88. pos,
  89. "moretrees:apple_tree_leaves",
  90. "basictrees:tree_apple",
  91. SCHEMATIC_MINP,
  92. SCHEMATIC_MAXP,
  93. math_random(3, 6)
  94. )
  95. -- Randomly transform some of the leaves to blossoms.
  96. local minp = vector.add(pos, SCHEMATIC_MINP)
  97. local maxp = vector.add(pos, SCHEMATIC_MAXP)
  98. local p = {x=pos.x, y=pos.y, z=pos.z}
  99. for x = minp.x, maxp.x do
  100. for y = minp.y, maxp.y do
  101. for z = minp.z, maxp.z do
  102. if math_random(1, 5) == 1 then
  103. p.x = x
  104. p.y = y
  105. p.z = z
  106. local n = minetest.get_node(p).name
  107. if n == "moretrees:apple_tree_leaves" then
  108. minetest.set_node(p, {name="moretrees:apple_tree_blossoms"})
  109. end
  110. end
  111. end
  112. end
  113. end
  114. end,
  115. on_construct = function(pos)
  116. minetest.get_node_timer(pos):start(math_random(SAPLING_TIME_MIN, SAPLING_TIME_MAX))
  117. end,
  118. on_place = function(itemstack, placer, pointed_thing)
  119. itemstack = default.sapling_on_place(itemstack, placer, pointed_thing,
  120. "moretrees:apple_tree_sapling", SCHEMATIC_MINP, SCHEMATIC_MAXP, 4)
  121. return itemstack
  122. end,
  123. })
  124. minetest.register_craft({
  125. output = 'moretrees:apple_tree_wood 4',
  126. recipe = {
  127. {'moretrees:apple_tree_tree'},
  128. }
  129. })
  130. minetest.register_craft({
  131. output = "default:fence_wood 4",
  132. recipe = {
  133. {"moretrees:apple_tree_wood", 'group:stick', "moretrees:apple_tree_wood"},
  134. {"moretrees:apple_tree_wood", 'group:stick', "moretrees:apple_tree_wood"},
  135. }
  136. })
  137. minetest.register_craft({
  138. output = "doors:gate_wood_closed",
  139. recipe = {
  140. {"techcrafts:hinge_wood", "moretrees:apple_tree_wood", "group:stick"},
  141. {"group:stick", "moretrees:apple_tree_wood", "group:stick"}
  142. }
  143. })
  144. stairs.register_stair_and_slab(
  145. "apple_tree",
  146. "moretrees:apple_tree_wood",
  147. moretrees.stair_groups,
  148. {"moretrees_apple_tree_wood.png"},
  149. "Apple Tree Plank",
  150. default.node_sound_wood_defaults()
  151. )