aspentree.lua 3.9 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. visual_scale = 1.3,
  43. tiles = {"default_aspen_leaves.png"},
  44. waving = 1,
  45. paramtype = "light",
  46. groups = basictrees.leaves_groups,
  47. drop = basictrees.get_leafdrop_table(SAPLING_CHANCE, "basictrees:aspen_sapling", "basictrees:aspen_leaves"),
  48. sounds = default.node_sound_leaves_defaults(),
  49. movement_speed_multiplier = default.SLOW_SPEED,
  50. on_construct = enhanced_leafdecay.make_leaf_constructor({}),
  51. on_timer = enhanced_leafdecay.make_leaf_nodetimer({tree="basictrees:aspen_trunk"}),
  52. })
  53. minetest.register_node("basictrees:aspen_sapling", {
  54. description = "Aspen Tree Sapling\n\nWill not grow in deep caves.",
  55. drawtype = "plantlike",
  56. --visual_scale = 1.0,
  57. tiles = {"default_aspen_sapling.png"},
  58. inventory_image = "default_aspen_sapling.png",
  59. wield_image = "default_aspen_sapling.png",
  60. paramtype = "light",
  61. sunlight_propagates = true,
  62. walkable = false,
  63. selection_box = basictrees.sapling_selection_box,
  64. groups = basictrees.sapling_groups,
  65. sounds = default.node_sound_leaves_defaults(),
  66. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  67. on_timer = function(pos)
  68. if mtflower.can_grow(pos) then
  69. if mtflower.try_grow(pos, "basictrees:aspen_trunk", "basictrees:aspen_leaves", "glowstone:minerals", "glowstone:minerals") then
  70. return
  71. end
  72. end
  73. if not basictrees.can_grow(pos) then
  74. minetest.get_node_timer(pos):start(math_random(SAPLING_TIME_MIN, SAPLING_TIME_MAX))
  75. return
  76. end
  77. local path = basictrees.modpath .. "/schematics/aspen_tree_from_sapling.mts"
  78. minetest.place_schematic(vector.add(pos, SCHEMATIC_RELP), path, "random", nil, false)
  79. snowscatter.dump_snowdust_on_tree(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP)
  80. ambiance.spawn_sound_beacon_inside_area("soundbeacon:trees", pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, 40, 3)
  81. end,
  82. on_construct = function(pos)
  83. minetest.get_node_timer(pos):start(math_random(SAPLING_TIME_MIN, SAPLING_TIME_MAX))
  84. end,
  85. on_place = function(itemstack, placer, pointed_thing)
  86. itemstack = default.sapling_on_place(itemstack, placer, pointed_thing,
  87. "basictrees:aspen_sapling", SCHEMATIC_MINP, SCHEMATIC_MAXP, 4)
  88. return itemstack
  89. end,
  90. })
  91. minetest.register_craft({
  92. output = 'basictrees:aspen_wood 4',
  93. recipe = {
  94. {'basictrees:aspen_trunk'},
  95. }
  96. })
  97. minetest.register_alias("default:aspen_tree", "basictrees:aspen_trunk")
  98. minetest.register_alias("default:aspen_leaves", "basictrees:aspen_leaves")
  99. minetest.register_alias("default:aspen_wood", "basictrees:aspen_wood")
  100. minetest.register_alias("default:aspen_sapling", "basictrees:aspen_sapling")