You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.2KB

  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. -- if water near soil then change to wet soil
  22. minetest.register_abm({
  23. nodenames = {"farming:soil", "farming:soil_wet"},
  24. interval = 15,
  25. chance = 4,
  26. catch_up = false,
  27. action = function(pos, node)
  28. pos.y = pos.y + 1
  29. local nn = minetest.get_node_or_nil(pos)
  30. pos.y = pos.y - 1
  31. if nn then nn = nn.name else return end
  32. -- what's on top of soil, if solid/not plant change soil to dirt
  33. if minetest.registered_nodes[nn]
  34. and minetest.registered_nodes[nn].walkable
  35. and minetest.get_item_group(nn, "plant") == 0 then
  36. minetest.set_node(pos, {name = "default:dirt"})
  37. return
  38. end
  39. -- if map around soil not loaded then skip until loaded
  40. if minetest.find_node_near(pos, 3, {"ignore"}) then
  41. return
  42. end
  43. -- check if there is water nearby and change soil accordingly
  44. -- if minetest.find_node_near(pos, 3, {"group:water"}) then
  45. -- check if water is within 3 nodes horizontally and 1 below
  46. if #minetest.find_nodes_in_area(
  47. {x = pos.x + 3, y = pos.y - 1, z = pos.z + 3},
  48. {x = pos.x - 3, y = pos.y , z = pos.z - 3},
  49. {"group:water"}) > 0 then
  50. if node.name == "farming:soil" then
  51. minetest.set_node(pos, {name = "farming:soil_wet"})
  52. end
  53. elseif node.name == "farming:soil_wet" then
  54. minetest.set_node(pos, {name = "farming:soil"})
  55. elseif node.name == "farming:soil" and minetest.get_item_group(nn, "plant") == 0 then
  56. minetest.set_node(pos, {name = "default:dirt"})
  57. end
  58. end,
  59. })