coral.lua 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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_setting("mgname") ~= "v6" then
  15. local coral_colour = {
  16. "default:coral_brown" ,
  17. "default:coral_orange",
  18. }
  19. local rooted_coral_colour = {
  20. "default:coral_cyan",
  21. "default:coral_green",
  22. "default:coral_pink",
  23. }
  24. minetest.register_abm({
  25. label = "Coral Propagation",
  26. nodenames = {"default:coral_brown", "default:coral_orange"},
  27. neighbors = {"group:water"},
  28. interval = 1800,
  29. chance = 900,
  30. catch_up = true,
  31. action = function(pos)
  32. local new_pos = {
  33. {x=pos.x,y=pos.y+1,z=pos.z},
  34. {x=pos.x+1,y=pos.y,z=pos.z},
  35. {x=pos.x,y=pos.y,z=pos.z+1},
  36. {x=pos.x-1,y=pos.y,z=pos.z},
  37. {x=pos.x,y=pos.y,z=pos.z-1},
  38. {x=pos.x,y=pos.y-1,z=pos.z},
  39. }
  40. new_pos = new_pos[math.random(6)]
  41. local old_node = minetest.get_node_or_nil(new_pos)
  42. if new_pos.y >= -8 and new_pos.y <= 0 and old_node
  43. and minetest.get_item_group(old_node.name, "water") > 0
  44. and minetest.find_node_near(new_pos, 4, "group:sand")
  45. and not minetest.find_node_near(new_pos, 1, "air") then
  46. minetest.set_node(new_pos, {name = coral_colour[math.random(2)]})
  47. end
  48. end,
  49. })
  50. minetest.register_abm({
  51. label = "Coral Seeding",
  52. nodenames = {"group:water"},
  53. neighbors = {"group:sand"},
  54. interval = 3600,
  55. chance = 7200,
  56. catch_up = false,
  57. action = function(pos)
  58. if pos.y >= -8 and pos.y <= 0
  59. and not minetest.find_node_near(pos, 1, "air") then
  60. minetest.set_node(pos, {name = coral_colour[math.random(2)]})
  61. end
  62. end,
  63. })
  64. minetest.register_abm({
  65. label = "Rooted Coral Propagation",
  66. nodenames = {"default:coral_skeleton"},
  67. neighbors = {"group:water"},
  68. interval = 1800,
  69. chance = 900,
  70. catch_up = true,
  71. action = function(pos)
  72. if minetest.get_node({
  73. x = pos.x,
  74. y = pos.y + 1,
  75. z = pos.z,
  76. }).name == "default:water_source" then
  77. minetest.set_node(new_pos, {
  78. name = rooted_coral_colour[math.random(3)],
  79. })
  80. end
  81. end,
  82. })
  83. end