soil.lua 4.8 KB

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