kelp.lua 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. -- Renew mod for Minetest
  2. -- Copyright © 2020 Alex Yst <https://y.st./>
  3. -- This program is free software; you can redistribute it and/or
  4. -- modify it under the terms of the GNU Lesser General Public
  5. -- License as published by the Free Software Foundation; either
  6. -- version 2.1 of the License, or (at your option) any later version.
  7. -- This software is distributed in the hope that it will be useful,
  8. -- but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. -- Lesser General Public License for more details.
  11. -- You should have received a copy of the GNU Lesser General Public
  12. -- License along with this program. If not, see
  13. -- <https://www.gnu.org./licenses/>.
  14. minetest.register_abm({
  15. label = "Kelp Spread",
  16. nodenames = {"default:sand_with_kelp"},
  17. interval = 30,
  18. chance = 50,
  19. action = function(pos)
  20. local seeds = {}
  21. local potential_seeds = minetest.find_nodes_in_area({
  22. x = pos.x - 5,
  23. y = pos.y - 5,
  24. z = pos.z - 5,
  25. }, {
  26. x = pos.x + 5,
  27. y = pos.y + 5,
  28. z = pos.z + 5,
  29. }, "default:sand")
  30. for _, seed_pos in next, potential_seeds do
  31. local water = minetest.find_nodes_in_area({
  32. x = seed_pos.x,
  33. y = seed_pos.y + 1,
  34. z = seed_pos.z,
  35. }, {
  36. x = seed_pos.x,
  37. y = seed_pos.y + 6,
  38. z = seed_pos.z,
  39. }, "default:water_source")
  40. if #water == 6 then
  41. seeds[#seeds+1] = seed_pos
  42. end
  43. end
  44. if #seeds > 0 then
  45. minetest.set_node(seeds[math.random(#seeds)], {
  46. name = "default:sand_with_kelp",
  47. param2 = math.random(4, 6) * 16,
  48. })
  49. end
  50. end,
  51. })