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.

177 lines
4.5KB

  1. local S = farming.intllib
  2. -- add soil types to existing dirt blocks
  3. minetest.override_item("default:dirt", {
  4. soil = {
  5. base = "default:dirt",
  6. dry = "farming:soil",
  7. wet = "farming:soil_wet"
  8. }
  9. })
  10. minetest.override_item("default:dirt_with_grass", {
  11. soil = {
  12. base = "default:dirt_with_grass",
  13. dry = "farming:soil",
  14. wet = "farming:soil_wet"
  15. }
  16. })
  17. minetest.override_item("default:dirt_with_dry_grass", {
  18. soil = {
  19. base = "default:dirt_with_dry_grass",
  20. dry = "farming:soil",
  21. wet = "farming:soil_wet"
  22. }
  23. })
  24. minetest.override_item("default:dirt_with_rainforest_litter", {
  25. soil = {
  26. base = "default:dirt_with_rainforest_litter",
  27. dry = "farming:soil",
  28. wet = "farming:soil_wet"
  29. }
  30. })
  31. minetest.override_item("default:dirt_with_coniferous_litter", {
  32. soil = {
  33. base = "default:dirt_with_coniferous_litter",
  34. dry = "farming:soil",
  35. wet = "farming:soil_wet"
  36. }
  37. })
  38. minetest.override_item("default:dry_dirt", {
  39. soil = {
  40. base = "default:dry_dirt",
  41. dry = "farming:dry_soil",
  42. wet = "farming:dry_soil_wet"
  43. }
  44. })
  45. minetest.override_item("default:dry_dirt_with_dry_grass", {
  46. soil = {
  47. base = "default:dry_dirt_with_dry_grass",
  48. dry = "farming:dry_soil",
  49. wet = "farming:dry_soil_wet"
  50. }
  51. })
  52. -- normal soil
  53. minetest.register_node("farming:soil", {
  54. description = S("Soil"),
  55. tiles = {"default_dirt.png^farming_soil.png", "default_dirt.png"},
  56. drop = "default:dirt",
  57. groups = {crumbly = 3, not_in_creative_inventory = 1, soil = 2, field = 1},
  58. sounds = default.node_sound_dirt_defaults(),
  59. soil = {
  60. base = "default:dirt",
  61. dry = "farming:soil",
  62. wet = "farming:soil_wet"
  63. }
  64. })
  65. -- wet soil
  66. minetest.register_node("farming:soil_wet", {
  67. description = S("Wet Soil"),
  68. tiles = {
  69. "default_dirt.png^farming_soil_wet.png",
  70. "default_dirt.png^farming_soil_wet_side.png"},
  71. drop = "default:dirt",
  72. groups = {crumbly = 3, not_in_creative_inventory = 1, soil = 3, field = 1},
  73. sounds = default.node_sound_dirt_defaults(),
  74. soil = {
  75. base = "default:dirt",
  76. dry = "farming:soil",
  77. wet = "farming:soil_wet"
  78. }
  79. })
  80. -- savanna soil
  81. if minetest.registered_nodes["default:dry_dirt"] then
  82. minetest.register_node("farming:dry_soil", {
  83. description = S("Savanna Soil"),
  84. tiles = {
  85. "default_dry_dirt.png^farming_soil.png",
  86. "default_dry_dirt.png"},
  87. drop = "default:dry_dirt",
  88. groups = {crumbly = 3, not_in_creative_inventory = 1, soil = 2, field = 1},
  89. sounds = default.node_sound_dirt_defaults(),
  90. soil = {
  91. base = "default:dry_dirt",
  92. dry = "farming:dry_soil",
  93. wet = "farming:dry_soil_wet"
  94. }
  95. })
  96. minetest.register_node("farming:dry_soil_wet", {
  97. description = S("Wet Savanna Soil"),
  98. tiles = {
  99. "default_dry_dirt.png^farming_soil_wet.png",
  100. "default_dry_dirt.png^farming_soil_wet_side.png"},
  101. drop = "default:dry_dirt",
  102. groups = {crumbly = 3, not_in_creative_inventory = 1, soil = 3, field = 1},
  103. sounds = default.node_sound_dirt_defaults(),
  104. soil = {
  105. base = "default:dry_dirt",
  106. dry = "farming:dry_soil",
  107. wet = "farming:dry_soil_wet"
  108. }
  109. })
  110. end
  111. -- sand is not soil, change existing sand-soil to use dry soil
  112. minetest.register_alias("farming:desert_sand_soil", "farming:dry_soil")
  113. minetest.register_alias("farming:desert_sand_soil_wet", "farming:dry_soil_wet")
  114. -- if water near soil then change to wet soil
  115. minetest.register_abm({
  116. nodenames = {"group:field"},
  117. interval = 15,
  118. chance = 4,
  119. catch_up = false,
  120. action = function(pos, node)
  121. local ndef = minetest.registered_nodes[node.name]
  122. if not ndef or not ndef.soil or not ndef.soil.wet
  123. or not ndef.soil.base or not ndef.soil.dry then return end
  124. pos.y = pos.y + 1
  125. local nn = minetest.get_node_or_nil(pos)
  126. pos.y = pos.y - 1
  127. if nn then nn = nn.name else return end
  128. -- what's on top of soil, if solid/not plant change soil to dirt
  129. if minetest.registered_nodes[nn]
  130. and minetest.registered_nodes[nn].walkable
  131. and minetest.get_item_group(nn, "plant") == 0 then
  132. minetest.set_node(pos, {name = "default:dirt"})
  133. return
  134. end
  135. -- if map around soil not loaded then skip until loaded
  136. if minetest.find_node_near(pos, 3, {"ignore"}) then
  137. return
  138. end
  139. -- check if water is within 3 nodes horizontally and 1 below
  140. if #minetest.find_nodes_in_area(
  141. {x = pos.x + 3, y = pos.y - 1, z = pos.z + 3},
  142. {x = pos.x - 3, y = pos.y , z = pos.z - 3},
  143. {"group:water"}) > 0 then
  144. minetest.set_node(pos, {name = ndef.soil.wet})
  145. elseif node.name == ndef.soil.wet then
  146. minetest.set_node(pos, {name = ndef.soil.dry})
  147. elseif node.name == ndef.soil.dry
  148. and minetest.get_item_group(nn, "plant") == 0 then
  149. minetest.set_node(pos, {name = ndef.soil.base})
  150. end
  151. end,
  152. })