soil.lua 2.3 KB

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