coral.lua 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. -- Renew mod for Minetest
  2. -- Copyright © 2018 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. if minetest.get_mapgen_params().mgname ~= "v6" then
  15. minetest.register_abm({
  16. label = "Coral Propagation",
  17. nodenames = {"default:coral_brown", "default:coral_orange"},
  18. neighbors = {"group:water"},
  19. interval = 1800,
  20. chance = 900,
  21. catch_up = true,
  22. action = function(pos)
  23. local new_pos = {
  24. {x=pos.x,y=pos.y+1,z=pos.z},
  25. {x=pos.x+1,y=pos.y,z=pos.z},
  26. {x=pos.x,y=pos.y,z=pos.z+1},
  27. {x=pos.x-1,y=pos.y,z=pos.z},
  28. {x=pos.x,y=pos.y,z=pos.z-1},
  29. {x=pos.x,y=pos.y-1,z=pos.z},
  30. }
  31. new_pos = new_pos[math.random(6)]
  32. local old_node = minetest.get_node_or_nil(new_pos)
  33. if new_pos.y >= -8 and new_pos.y <= 0 and old_node
  34. and minetest.get_item_group(old_node.name, "water") > 0
  35. and minetest.find_node_near(new_pos, 4, "group:sand")
  36. and not minetest.find_node_near(new_pos, 1, "air") then
  37. local new_node = {
  38. "default:coral_brown" ,
  39. "default:coral_orange",
  40. }
  41. minetest.set_node(new_pos, {name = new_node[math.random(2)]})
  42. end
  43. end,
  44. })
  45. minetest.register_abm({
  46. label = "Coral Seeding",
  47. nodenames = {"group:water"},
  48. neighbors = {"group:sand"},
  49. interval = 3600,
  50. chance = 7200,
  51. catch_up = false,
  52. action = function(pos)
  53. if pos.y >= -8 and pos.y <= 0
  54. and not minetest.find_node_near(pos, 1, "air") then
  55. local new_node = {
  56. "default:coral_brown" ,
  57. "default:coral_orange",
  58. }
  59. minetest.set_node(pos, {name = new_node[math.random(2)]})
  60. end
  61. end,
  62. })
  63. end