common.lua 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. basictrees = basictrees or {}
  2. -- Localize for performance.
  3. local math_random = math.random
  4. basictrees.sapling_selection_box = {
  5. type = "fixed",
  6. fixed = {-0.3, -0.5, -0.3, 0.3, 0.35, 0.3},
  7. }
  8. basictrees.trunk_nodebox = {
  9. {0, 0, 2, 16, 16, 14},
  10. {2, 0, 0, 14, 16, 16},
  11. }
  12. utility.transform_nodebox(basictrees.trunk_nodebox)
  13. basictrees.sapling_groups = utility.dig_groups("plant", {
  14. flammable = 2,
  15. attached_node = 1,
  16. sapling = 1,
  17. })
  18. basictrees.tree_groups = utility.dig_groups("tree", {
  19. tree = 1,
  20. flammable = 2,
  21. })
  22. basictrees.dead_tree_groups = utility.dig_groups("deadtree", {
  23. tree = 1,
  24. flammable = 2,
  25. })
  26. basictrees.cw_tree_groups = utility.dig_groups("tree", {
  27. tree = 1,
  28. })
  29. basictrees.get_wood_groups = function(extra)
  30. local groups = utility.dig_groups("wood", extra or {})
  31. groups.flammable = 2
  32. groups.wood = 1
  33. return groups
  34. end
  35. basictrees.leaves_groups = utility.dig_groups("leaves", {
  36. leafdecay = 3,
  37. flammable = 2,
  38. leaves = 1,
  39. green_leaves = 1,
  40. })
  41. basictrees.cw_leaves_groups = utility.dig_groups("leaves", {
  42. leafdecay = 3,
  43. leaves = 1,
  44. green_leaves = 1,
  45. })
  46. basictrees.can_grow = function(pos)
  47. -- Reduced chance to grow if cold/ice nearby.
  48. local below = {x=pos.x, y=pos.y-1, z=pos.z}
  49. local cold = minetest.find_nodes_in_area(vector.subtract(below, 1), vector.add(below, 1), "group:cold")
  50. if #cold > math_random(0, 18) then
  51. return false
  52. end
  53. if pos.y < math_random(-64, 0) then
  54. return false
  55. end
  56. local node_under = minetest.get_node_or_nil(below)
  57. if not node_under then
  58. return false
  59. end
  60. local name_under = node_under.name
  61. local is_soil = minetest.get_item_group(name_under, "soil")
  62. if is_soil == 0 then
  63. return false
  64. end
  65. local light_level = minetest.get_node_light(pos)
  66. if not light_level or light_level < 12 then
  67. return false
  68. end
  69. return true
  70. end
  71. basictrees.get_leafdrop_table = function(chance, sapling, leaves)
  72. local drop = {
  73. max_items = 1,
  74. items = {
  75. {items={sapling}, rarity=chance},
  76. {items={"default:stick"}, rarity=10},
  77. -- Player will get leaves only if he gets nothing else; this is because 'max_items' is 1.
  78. {items={leaves}},
  79. }
  80. }
  81. return drop
  82. end