soil.lua 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. if node.name == "farming:soil" then
  46. minetest.set_node(pos, {name = "farming:soil_wet"})
  47. end
  48. elseif node.name == "farming:soil_wet" then
  49. minetest.set_node(pos, {name = "farming:soil"})
  50. elseif node.name == "farming:soil" and minetest.get_item_group(nn, "plant") == 0 then
  51. minetest.set_node(pos, {name = "default:dirt"})
  52. end
  53. end,
  54. })