blossom.lua 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. -- support for i18n
  2. local S = minetest.get_translator("nature_classic")
  3. -- Blossoms and such
  4. local function spawn_apple_under(pos)
  5. local below = {
  6. x = pos.x,
  7. y = pos.y - 1,
  8. z = pos.z,
  9. }
  10. if minetest.get_node(below).name == "air" then
  11. minetest.swap_node(below, { name = "default:apple" })
  12. end
  13. end
  14. minetest.register_node(":"..nature.blossom_node, {
  15. description = S("Apple blossoms"),
  16. drawtype = "allfaces_optional",
  17. tiles = nature.blossom_textures,
  18. paramtype = "light",
  19. groups = nature.blossom_groups,
  20. sounds = default.node_sound_leaves_defaults(),
  21. waving = 1
  22. })
  23. default.register_leafdecay({
  24. trunks = { nature.blossom_trunk },
  25. leaves = { nature.blossom_node, nature.blossom_leaves },
  26. radius = nature.blossom_decay,
  27. })
  28. minetest.register_craft({
  29. type = "fuel",
  30. recipe = nature.blossom_node,
  31. burntime = 2,
  32. })
  33. -- these ABMs can get heavy, so just enqueue the nodes
  34. -- Adding Blossoms
  35. -- Limit mass changes after block has not been loaded for some time:
  36. -- Run ABM with higher frequency, but don't enqueue all blocks
  37. minetest.register_abm({
  38. nodenames = { nature.blossom_leaves },
  39. interval = nature.blossom_delay / nature.leaves_blossom_chance,
  40. chance = nature.leaves_blossom_chance,
  41. action = function(pos, node, active_object_count, active_object_count_wider)
  42. if math.random(nature.leaves_blossom_chance) == 1 then
  43. nature.enqueue_node(pos, node, nature.blossom_node)
  44. end
  45. end
  46. })
  47. -- Removing blossoms
  48. -- Limit mass changes after block has not been loaded for some time:
  49. -- Run ABM with higher frequency, but don't enqueue all blocks
  50. minetest.register_abm({
  51. nodenames = { nature.blossom_node },
  52. interval = nature.blossom_delay / nature.blossom_leaves_chance,
  53. chance = nature.blossom_leaves_chance,
  54. action = function(pos, node, active_object_count, active_object_count_wider)
  55. if math.random(nature.blossom_leaves_chance) == 1 then
  56. nature.enqueue_node(pos, node, nature.blossom_leaves)
  57. end
  58. end
  59. })
  60. -- Spawning apples
  61. -- Limit mass changes after block has not been loaded for some time:
  62. -- spawn apples with 25% chance, but with 4 times higher frequency
  63. minetest.register_abm({
  64. nodenames = { nature.blossom_node },
  65. interval = nature.apple_delay / 4,
  66. chance = nature.apple_chance,
  67. action = function(pos, node, active_object_count, active_object_count_wider)
  68. if math.random(4) == 1 and nature.dtime < 0.2 and not minetest.find_node_near(pos, nature.apple_spread, { "default:apple" }) then
  69. spawn_apple_under(pos)
  70. end
  71. end
  72. })