compost.lua 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. minetest.register_node("renew:compost", {
  15. description = "Compost",
  16. tiles = {"renew-compost.png"},
  17. groups = {crumbly=3, soil=1},
  18. sounds = default.node_sound_dirt_defaults(),
  19. })
  20. minetest.register_craft({
  21. output = "renew:compost",
  22. recipe = {
  23. {"group:leaves", "group:leaves", "group:leaves"},
  24. {"group:leaves", "group:leaves", "group:leaves"},
  25. {"group:leaves", "group:leaves", "group:leaves"},
  26. }
  27. })
  28. minetest.register_abm({
  29. label = "Compost rotting",
  30. nodenames = {"renew:compost"},
  31. neighbors = {"group:spreading_dirt_type", "group:flora", "flowers:mushroom_brown", "flowers:mushroom_red"},
  32. interval = 60,
  33. chance = 60,
  34. catch_up = true,
  35. action = function(pos)
  36. -- If the node above is not air, a plant, or a decomposer (a mushroom),
  37. -- decomposition cannot occur.
  38. local node_above = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z})
  39. if node_above.name ~= "air"
  40. and node_above.name ~= "flowers:mushroom_brown"
  41. and node_above.name ~= "flowers:mushroom_red"
  42. and minetest.get_item_group(node_above.name, "flora") == 0 then
  43. return
  44. end
  45. -- Spreading dirt types will take over compost, converting it into
  46. -- their specific type of dirt.
  47. local spreader_pos = minetest.find_node_near(pos, 1, "group:spreading_dirt_type")
  48. if spreader_pos then
  49. local spreader = minetest.get_node(spreader_pos)
  50. minetest.set_node(pos, {name=spreader.name})
  51. return
  52. -- If a spreading dirt type isn't around, compost will simply decompose
  53. -- into regular dirt, but only if something is growing on it.
  54. elseif node_above.name ~= "air" then
  55. minetest.set_node(pos, {name="default:dirt"})
  56. end
  57. end,
  58. })