soil.lua 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. local S = farming.intllib
  2. -- normal soil
  3. minetest.register_node("farming:soil", {
  4. description = S("Soil"),
  5. tiles = {"default_dirt.png^farming_soil.png", "default_dirt.png"},
  6. drop = "default:dirt",
  7. groups = {crumbly = 3, not_in_creative_inventory = 1, soil = 2},
  8. sounds = default.node_sound_dirt_defaults(),
  9. })
  10. -- wet soil
  11. minetest.register_node("farming:soil_wet", {
  12. description = S("Wet Soil"),
  13. tiles = {"default_dirt.png^farming_soil_wet.png", "default_dirt.png^farming_soil_wet_side.png"},
  14. drop = "default:dirt",
  15. groups = {crumbly = 3, not_in_creative_inventory = 1, soil = 3},
  16. sounds = default.node_sound_dirt_defaults(),
  17. })
  18. -- sand is not soil, change existing sand-soil to use normal soil
  19. minetest.register_alias("farming:desert_sand_soil", "farming:soil")
  20. minetest.register_alias("farming:desert_sand_soil_wet", "farming:soil_wet")
  21. -- also change new dry soil to use normal soil
  22. minetest.register_alias("farming:dry_soil", "farming:soil")
  23. minetest.register_alias("farming:dry_soil_wet", "farming:soil_wet")
  24. -- if water near soil then change to wet soil
  25. minetest.register_abm({
  26. nodenames = {"farming:soil", "farming:soil_wet"},
  27. interval = 15,
  28. chance = 4,
  29. catch_up = false,
  30. action = function(pos, node)
  31. pos.y = pos.y + 1
  32. local nn = minetest.get_node_or_nil(pos)
  33. pos.y = pos.y - 1
  34. if nn then nn = nn.name else return end
  35. -- what's on top of soil, if solid/not plant change soil to dirt
  36. if minetest.registered_nodes[nn]
  37. and minetest.registered_nodes[nn].walkable
  38. and minetest.get_item_group(nn, "plant") == 0 then
  39. minetest.set_node(pos, {name = "default:dirt"})
  40. return
  41. end
  42. -- if map around soil not loaded then skip until loaded
  43. if minetest.find_node_near(pos, 3, {"ignore"}) then
  44. return
  45. end
  46. -- check if there is water nearby and change soil accordingly
  47. -- if minetest.find_node_near(pos, 3, {"group:water"}) then
  48. -- check if water is within 3 nodes horizontally and 1 below
  49. if #minetest.find_nodes_in_area(
  50. {x = pos.x + 3, y = pos.y - 1, z = pos.z + 3},
  51. {x = pos.x - 3, y = pos.y , z = pos.z - 3},
  52. {"group:water"}) > 0 then
  53. if node.name == "farming:soil" then
  54. minetest.set_node(pos, {name = "farming:soil_wet"})
  55. end
  56. elseif node.name == "farming:soil_wet" then
  57. minetest.set_node(pos, {name = "farming:soil"})
  58. elseif node.name == "farming:soil" and minetest.get_item_group(nn, "plant") == 0 then
  59. minetest.set_node(pos, {name = "default:dirt"})
  60. end
  61. end,
  62. })