common.lua 2.1 KB

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