acaciatree.lua 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. if not minetest.global_exists("basictrees") then basictrees = {} end
  2. local SAPLING_TIME_MIN = 60*15
  3. local SAPLING_TIME_MAX = 60*30
  4. local SAPLING_CHANCE = 25
  5. local SCHEMATIC_MINP = {x=-4, y=0, z=-4}
  6. local SCHEMATIC_MAXP = {x=4, y=6, z=4}
  7. local SCHEMATIC_RELP = {x=-4, y=-1, z=-4}
  8. -- Localize for performance.
  9. local math_random = math.random
  10. minetest.register_node("basictrees:acacia_trunk", {
  11. drawtype = "nodebox",
  12. paramtype = "light",
  13. node_box = {
  14. type = "fixed",
  15. fixed = basictrees.trunk_nodebox,
  16. },
  17. description = "Acacia Tree",
  18. tiles = {"default_acacia_tree_top.png", "default_acacia_tree_top.png", "default_acacia_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:acacia_leaves",
  27. "group:dry_leaves",
  28. },
  29. }),
  30. })
  31. minetest.register_node("basictrees:acacia_wood", {
  32. description = "Acacia Wood Planks",
  33. paramtype2 = "facedir",
  34. place_param2 = 0,
  35. tiles = {"default_acacia_wood.png"},
  36. groups = basictrees.get_wood_groups({wood_light = 1}),
  37. sounds = default.node_sound_wood_defaults(),
  38. })
  39. minetest.register_node("basictrees:acacia_leaves", {
  40. description = "Acacia Tree Leaves",
  41. drawtype = "allfaces_optional",
  42. tiles = {"default_acacia_leaves.png"},
  43. waving = 1,
  44. paramtype = "light",
  45. groups = basictrees.leaves_groups,
  46. drop = basictrees.get_leafdrop_table(SAPLING_CHANCE, "basictrees:acacia_sapling", "basictrees:acacia_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:acacia_trunk"}),
  51. })
  52. minetest.register_node("basictrees:acacia_sapling", {
  53. description = "Acacia Tree Sapling\n\nWill not grow in deep caves.",
  54. drawtype = "plantlike",
  55. tiles = {"default_acacia_sapling.png"},
  56. inventory_image = "default_acacia_sapling.png",
  57. wield_image = "default_acacia_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:acacia_trunk", "basictrees:acacia_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/acacia_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. serveressentials.fix_acacia_tree(vector.add(pos, SCHEMATIC_MINP), vector.add(pos, SCHEMATIC_MAXP))
  79. ambiance.spawn_sound_beacon_inside_area("soundbeacon:trees", pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, 40, 3)
  80. end,
  81. on_construct = function(pos)
  82. minetest.get_node_timer(pos):start(math_random(SAPLING_TIME_MIN, SAPLING_TIME_MAX))
  83. end,
  84. on_place = function(itemstack, placer, pointed_thing)
  85. itemstack = default.sapling_on_place(itemstack, placer, pointed_thing,
  86. "basictrees:acacia_sapling", SCHEMATIC_MINP, SCHEMATIC_MAXP, 4)
  87. return itemstack
  88. end,
  89. })
  90. minetest.register_craft({
  91. output = 'basictrees:acacia_wood 4',
  92. recipe = {
  93. {'basictrees:acacia_trunk'},
  94. }
  95. })
  96. minetest.register_alias("default:acacia_tree", "basictrees:acacia_trunk")
  97. minetest.register_alias("default:acacia_leaves", "basictrees:acacia_leaves")
  98. minetest.register_alias("default:acacia_sapling", "basictrees:acacia_sapling")
  99. minetest.register_alias("default:acacia_wood", "basictrees:acacia_wood")