apple_tree.lua 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. minetest.register_node("moretrees:apple_tree_tree", {
  9. drawtype = "nodebox",
  10. paramtype = "light",
  11. node_box = {
  12. type = "fixed",
  13. fixed = basictrees.trunk_nodebox,
  14. },
  15. description = "Apple Tree",
  16. tiles = {
  17. "moretrees_apple_tree_trunk_top.png",
  18. "moretrees_apple_tree_trunk_top.png",
  19. "moretrees_apple_tree_trunk.png"
  20. },
  21. paramtype2 = "facedir",
  22. groups = moretrees.tree_groups,
  23. sounds = default.node_sound_wood_defaults(),
  24. on_place = minetest.rotate_node,
  25. movement_speed_multiplier = default.NORM_SPEED,
  26. on_destruct = enhanced_leafdecay.make_tree_destructor({
  27. leaves = {
  28. "moretrees:apple_tree_leaves",
  29. "moretrees:apple_tree_blossoms",
  30. "basictrees:tree_apple",
  31. "group:dry_leaves",
  32. },
  33. }),
  34. })
  35. minetest.register_node("moretrees:apple_tree_leaves", {
  36. description = "Apple Tree Leaves",
  37. drawtype = "allfaces_optional",
  38. visual_scale = 1.3,
  39. waving = 1,
  40. tiles = {"moretrees_apple_tree_leaves.png"},
  41. paramtype = "light",
  42. groups = moretrees.leaves_groups,
  43. drop = moretrees.get_leafdrop_table(SAPLING_CHANCE, "moretrees:apple_tree_sapling", "moretrees:apple_tree_leaves"),
  44. sounds = default.node_sound_leaves_defaults(),
  45. movement_speed_multiplier = default.SLOW_SPEED,
  46. on_construct = enhanced_leafdecay.make_leaf_constructor({}),
  47. on_timer = enhanced_leafdecay.make_leaf_nodetimer({tree="moretrees:apple_tree_tree"}),
  48. })
  49. minetest.register_node("moretrees:apple_tree_wood", {
  50. description = "Apple Tree Planks",
  51. paramtype2 = "facedir",
  52. place_param2 = 0,
  53. tiles = {"moretrees_apple_tree_wood.png"},
  54. groups = moretrees.get_wood_groups({wood_light = 1}),
  55. sounds = default.node_sound_wood_defaults(),
  56. })
  57. minetest.register_node("moretrees:apple_tree_sapling", {
  58. description = "Apple Tree Sapling\n\nWill not grow in deep caves.\nGrows lots of apples.",
  59. drawtype = "plantlike",
  60. --visual_scale = 1.0,
  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. {"group:stick", "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. )