aspentree.lua 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. basictrees = basictrees or {}
  2. local SAPLING_TIME_MIN = 60*15
  3. local SAPLING_TIME_MAX = 60*25
  4. local SAPLING_CHANCE = 20
  5. local SCHEMATIC_MINP = {x=-2, y=1, z=-2}
  6. local SCHEMATIC_MAXP = {x=2, y=12, z=2}
  7. local SCHEMATIC_RELP = {x=-2, y=-1, z=-2}
  8. -- Localize for performance.
  9. local math_random = math.random
  10. minetest.register_node("basictrees:aspen_trunk", {
  11. drawtype = "nodebox",
  12. paramtype = "light",
  13. node_box = {
  14. type = "fixed",
  15. fixed = basictrees.trunk_nodebox,
  16. },
  17. description = "Aspen Tree",
  18. tiles = {"default_aspen_tree_top.png", "default_aspen_tree_top.png", "default_aspen_tree.png"},
  19. paramtype2 = "facedir",
  20. groups = basictrees.tree_groups,
  21. sounds = default.node_sound_wood_defaults(),
  22. on_place = minetest.rotate_node,
  23. movement_speed_multiplier = default.NORM_SPEED,
  24. on_destruct = enhanced_leafdecay.make_tree_destructor({
  25. leaves = {
  26. "basictrees:aspen_leaves",
  27. "group:dry_leaves",
  28. },
  29. }),
  30. })
  31. minetest.register_node("basictrees:aspen_wood", {
  32. description = "Aspen Wood Planks",
  33. paramtype2 = "facedir",
  34. place_param2 = 0,
  35. tiles = {"default_aspen_wood.png"},
  36. groups = basictrees.get_wood_groups({wood_light = 1}),
  37. sounds = default.node_sound_wood_defaults(),
  38. })
  39. minetest.register_node("basictrees:aspen_leaves", {
  40. description = "Aspen Leaves",
  41. drawtype = "allfaces_optional",
  42. tiles = {"default_aspen_leaves.png"},
  43. waving = 1,
  44. paramtype = "light",
  45. groups = basictrees.leaves_groups,
  46. drop = basictrees.get_leafdrop_table(SAPLING_CHANCE, "basictrees:aspen_sapling", "basictrees:aspen_leaves"),
  47. sounds = default.node_sound_leaves_defaults(),
  48. movement_speed_multiplier = default.SLOW_SPEED,
  49. on_construct = enhanced_leafdecay.make_leaf_constructor({}),
  50. on_timer = enhanced_leafdecay.make_leaf_nodetimer({tree="basictrees:aspen_trunk"}),
  51. })
  52. minetest.register_node("basictrees:aspen_sapling", {
  53. description = "Aspen Tree Sapling\n\nWill not grow in deep caves.",
  54. drawtype = "plantlike",
  55. tiles = {"default_aspen_sapling.png"},
  56. inventory_image = "default_aspen_sapling.png",
  57. wield_image = "default_aspen_sapling.png",
  58. paramtype = "light",
  59. sunlight_propagates = true,
  60. walkable = false,
  61. selection_box = basictrees.sapling_selection_box,
  62. groups = basictrees.sapling_groups,
  63. sounds = default.node_sound_leaves_defaults(),
  64. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  65. on_timer = function(pos)
  66. if mtflower.can_grow(pos) then
  67. if mtflower.try_grow(pos, "basictrees:aspen_trunk", "basictrees:aspen_leaves", "glowstone:minerals", "glowstone:minerals") then
  68. return
  69. end
  70. end
  71. if not basictrees.can_grow(pos) then
  72. minetest.get_node_timer(pos):start(math_random(SAPLING_TIME_MIN, SAPLING_TIME_MAX))
  73. return
  74. end
  75. local path = basictrees.modpath .. "/schematics/aspen_tree_from_sapling.mts"
  76. minetest.place_schematic(vector.add(pos, SCHEMATIC_RELP), path, "random", nil, false)
  77. snowscatter.dump_snowdust_on_tree(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP)
  78. ambiance.spawn_sound_beacon_inside_area("soundbeacon:trees", pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, 40, 3)
  79. end,
  80. on_construct = function(pos)
  81. minetest.get_node_timer(pos):start(math_random(SAPLING_TIME_MIN, SAPLING_TIME_MAX))
  82. end,
  83. on_place = function(itemstack, placer, pointed_thing)
  84. itemstack = default.sapling_on_place(itemstack, placer, pointed_thing,
  85. "basictrees:aspen_sapling", SCHEMATIC_MINP, SCHEMATIC_MAXP, 4)
  86. return itemstack
  87. end,
  88. })
  89. minetest.register_craft({
  90. output = 'basictrees:aspen_wood 4',
  91. recipe = {
  92. {'basictrees:aspen_trunk'},
  93. }
  94. })
  95. minetest.register_alias("default:aspen_tree", "basictrees:aspen_trunk")
  96. minetest.register_alias("default:aspen_leaves", "basictrees:aspen_leaves")
  97. minetest.register_alias("default:aspen_wood", "basictrees:aspen_wood")
  98. minetest.register_alias("default:aspen_sapling", "basictrees:aspen_sapling")