apple_tree.lua 5.4 KB

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