poplar.lua 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. moretrees = moretrees or {}
  2. local SAPLING_TIME_MIN = 60*15
  3. local SAPLING_TIME_MAX = 60*30
  4. local SAPLING_CHANCE = 40
  5. local SCHEMATIC_MINP = {x=-2, y=0, z=-2}
  6. local SCHEMATIC_MAXP = {x=2, y=10, 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:poplar_tree", {
  11. drawtype = "nodebox",
  12. paramtype = "light",
  13. node_box = {
  14. type = "fixed",
  15. fixed = basictrees.trunk_nodebox,
  16. },
  17. description = "Poplar Tree",
  18. tiles = {
  19. "moretrees_poplar_trunk_top.png",
  20. "moretrees_poplar_trunk_top.png",
  21. "moretrees_poplar_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:poplar_leaves",
  31. "group:dry_leaves",
  32. },
  33. }),
  34. })
  35. minetest.register_node("moretrees:poplar_leaves", {
  36. description = "Poplar Leaves",
  37. drawtype = "allfaces_optional",
  38. visual_scale = 1.3,
  39. tiles = {"moretrees_poplar_leaves.png"},
  40. paramtype = "light",
  41. waving = 1,
  42. groups = moretrees.leaves_groups,
  43. drop = moretrees.get_leafdrop_table(SAPLING_CHANCE, "moretrees:poplar_sapling", "moretrees:poplar_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:poplar_tree"}),
  48. })
  49. minetest.register_node("moretrees:poplar_wood", {
  50. description = "Poplar Planks",
  51. paramtype2 = "facedir",
  52. place_param2 = 0,
  53. tiles = {"moretrees_poplar_wood.png"},
  54. groups = moretrees.get_wood_groups({wood_light = 1}),
  55. sounds = default.node_sound_wood_defaults(),
  56. })
  57. minetest.register_node("moretrees:poplar_sapling", {
  58. description = "Poplar Sapling\n\nWill not grow in deep caves.",
  59. drawtype = "plantlike",
  60. --visual_scale = 1.0,
  61. tiles = {"moretrees_poplar_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:poplar_tree", "moretrees:poplar_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/poplar.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:poplar_tree")
  83. hb4.leafscatter.remove(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, "moretrees:poplar_leaves", math_random(10, 30))
  84. hb4.leafscatter.add(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, "moretrees:poplar_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. end,
  88. on_construct = function(pos)
  89. minetest.get_node_timer(pos):start(math_random(SAPLING_TIME_MIN, SAPLING_TIME_MAX))
  90. end,
  91. on_place = function(itemstack, placer, pointed_thing)
  92. itemstack = default.sapling_on_place(itemstack, placer, pointed_thing,
  93. "moretrees:poplar_sapling", SCHEMATIC_MINP, SCHEMATIC_MAXP, 4)
  94. return itemstack
  95. end,
  96. })
  97. minetest.register_craft({
  98. output = 'moretrees:poplar_wood 4',
  99. recipe = {
  100. {'moretrees:poplar_tree'},
  101. }
  102. })
  103. minetest.register_craft({
  104. output = "default:fence_wood 4",
  105. recipe = {
  106. {"moretrees:poplar_wood", 'group:stick', "moretrees:poplar_wood"},
  107. {"moretrees:poplar_wood", 'group:stick', "moretrees:poplar_wood"},
  108. }
  109. })
  110. minetest.register_craft({
  111. output = "doors:gate_wood_closed",
  112. recipe = {
  113. {"group:stick", "moretrees:poplar_wood", "group:stick"},
  114. {"group:stick", "moretrees:poplar_wood", "group:stick"}
  115. }
  116. })
  117. stairs.register_stair_and_slab(
  118. "poplar",
  119. "moretrees:poplar_wood",
  120. moretrees.stair_groups,
  121. {"moretrees_poplar_wood.png"},
  122. "Poplar Plank",
  123. default.node_sound_wood_defaults()
  124. )