dirt.lua 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. local S = ethereal.intllib
  2. -- override default dirt (to stop caves cutting away dirt)
  3. minetest.override_item("default:dirt", {is_ground_content = ethereal.cavedirt})
  4. minetest.register_alias("ethereal:green_dirt", "default:dirt_with_grass")
  5. -- dry dirt
  6. minetest.register_node("ethereal:dry_dirt", {
  7. description = S("Dried Dirt"),
  8. tiles = {"ethereal_dry_dirt.png"},
  9. is_ground_content = ethereal.cavedirt,
  10. groups = {crumbly = 3},
  11. sounds = default.node_sound_dirt_defaults()
  12. })
  13. minetest.register_craft({
  14. type = "cooking",
  15. output = "ethereal:dry_dirt",
  16. recipe = "default:dirt",
  17. cooktime = 3,
  18. })
  19. local dirts = {
  20. "Bamboo", "Jungle", "Grove", "Prairie", "Cold",
  21. "Crystal", "Mushroom", "Fiery", "Gray"
  22. }
  23. for n = 1, #dirts do
  24. local desc = dirts[n]
  25. local name = desc:lower()
  26. minetest.register_node("ethereal:"..name.."_dirt", {
  27. description = S(desc.." Dirt"),
  28. tiles = {
  29. "ethereal_grass_"..name.."_top.png",
  30. "default_dirt.png",
  31. {
  32. name = "default_dirt.png^ethereal_grass_"
  33. .. name .."_side.png",
  34. tileable_vertical = false
  35. }
  36. },
  37. is_ground_content = ethereal.cavedirt,
  38. groups = {crumbly = 3, soil = 1, spreading_dirt_type = 1},
  39. soil = {
  40. base = "ethereal:"..name.."_dirt",
  41. dry = "farming:soil",
  42. wet = "farming:soil_wet"
  43. },
  44. drop = "default:dirt",
  45. sounds = default.node_sound_dirt_defaults({
  46. footstep = {name = "default_grass_footstep", gain = 0.25},
  47. }),
  48. })
  49. end
  50. -- flower spread, also crystal and fire flower regeneration
  51. local flower_spread = function(pos, node)
  52. if (minetest.get_node_light(pos) or 0) < 13 then
  53. return
  54. end
  55. local pos0 = {x = pos.x - 4, y = pos.y - 2, z = pos.z - 4}
  56. local pos1 = {x = pos.x + 4, y = pos.y + 2, z = pos.z + 4}
  57. local num = #minetest.find_nodes_in_area(pos0, pos1, "group:flora")
  58. -- stop flowers spreading too much just below top of map block
  59. if minetest.find_node_near(pos, 2, "ignore") then
  60. return
  61. end
  62. if num > 3
  63. and node.name == "ethereal:crystalgrass" then
  64. local grass = minetest.find_nodes_in_area_under_air(
  65. pos0, pos1, {"ethereal:crystalgrass"})
  66. if #grass > 4
  67. and not minetest.find_node_near(pos, 4, {"ethereal:crystal_spike"}) then
  68. pos = grass[math.random(#grass)]
  69. pos.y = pos.y - 1
  70. if minetest.get_node(pos).name == "ethereal:crystal_dirt" then
  71. pos.y = pos.y + 1
  72. minetest.swap_node(pos, {name = "ethereal:crystal_spike"})
  73. end
  74. end
  75. return
  76. elseif num > 3
  77. and node.name == "ethereal:dry_shrub" then
  78. local grass = minetest.find_nodes_in_area_under_air(
  79. pos0, pos1, {"ethereal:dry_shrub"})
  80. if #grass > 8
  81. and not minetest.find_node_near(pos, 4, {"ethereal:fire_flower"}) then
  82. pos = grass[math.random(#grass)]
  83. pos.y = pos.y - 1
  84. if minetest.get_node(pos).name == "ethereal:fiery_dirt" then
  85. pos.y = pos.y + 1
  86. minetest.swap_node(pos, {name = "ethereal:fire_flower"})
  87. end
  88. end
  89. return
  90. elseif num > 3 then
  91. return
  92. end
  93. local seedling = minetest.find_nodes_in_area_under_air(
  94. pos0, pos1, {"group:soil"})
  95. if #seedling > 0 then
  96. pos = seedling[math.random(#seedling)]
  97. -- default farming has desert sand as soil, so dont spread on this
  98. if minetest.get_node(pos).name == "default:desert_sand" then
  99. return
  100. end
  101. pos.y = pos.y + 1
  102. if (minetest.get_node_light(pos) or 0) < 13 then
  103. return
  104. end
  105. minetest.swap_node(pos, {name = node.name})
  106. end
  107. end
  108. -- grow papyrus up to 4 high and bamboo up to 8 high
  109. local grow_papyrus = function(pos, node)
  110. local oripos = pos.y
  111. local high = 4
  112. pos.y = pos.y - 1
  113. local nod = minetest.get_node_or_nil(pos)
  114. if not nod
  115. or minetest.get_item_group(nod.name, "soil") < 1
  116. or minetest.find_node_near(pos, 3, {"group:water"}) == nil then
  117. return
  118. end
  119. if node.name == "ethereal:bamboo" then
  120. high = 8
  121. end
  122. pos.y = pos.y + 1
  123. local height = 0
  124. while height < high
  125. and minetest.get_node(pos).name == node.name do
  126. height = height + 1
  127. pos.y = pos.y + 1
  128. end
  129. nod = minetest.get_node_or_nil(pos)
  130. if nod
  131. and nod.name == "air"
  132. and height < high then
  133. if node.name == "ethereal:bamboo"
  134. and height == (high - 1) then
  135. ethereal.grow_bamboo_tree({x = pos.x, y = oripos, z = pos.z})
  136. else
  137. minetest.swap_node(pos, {name = node.name})
  138. end
  139. end
  140. end
  141. -- loop through active abm's
  142. for _, ab in pairs(minetest.registered_abms) do
  143. local label = ab.label or ""
  144. local node1 = ab.nodenames and ab.nodenames[1] or ""
  145. local node2 = ab.nodenames and ab.nodenames[2] or ""
  146. local neigh = ab.neighbors and ab.neighbors[1] or ""
  147. if label == "Flower spread"
  148. or node1 == "group:flora" then
  149. --ab.interval = 1
  150. --ab.chance = 1
  151. ab.nodenames = {"group:flora"}
  152. ab.neighbors = {"group:soil"}
  153. ab.action = flower_spread
  154. -- find grow papyrus abm and change to grow_papyrus function
  155. elseif label == "Grow papyrus"
  156. or node1 == "default:papyrus" then
  157. --ab.interval = 2
  158. --ab.chance = 1
  159. ab.nodenames = {"default:papyrus", "ethereal:bamboo"}
  160. ab.neighbors = {"group:soil"}
  161. ab.action = grow_papyrus
  162. end
  163. end
  164. -- If Baked Clay mod not active, make Red, Orange and Grey nodes
  165. if not minetest.get_modpath("bakedclay") then
  166. minetest.register_node(":bakedclay:red", {
  167. description = S("Red Baked Clay"),
  168. tiles = {"baked_clay_red.png"},
  169. groups = {cracky = 3},
  170. is_ground_content = ethereal.cavedirt,
  171. sounds = default.node_sound_stone_defaults(),
  172. })
  173. minetest.register_node(":bakedclay:orange", {
  174. description = S("Orange Baked Clay"),
  175. tiles = {"baked_clay_orange.png"},
  176. groups = {cracky = 3},
  177. is_ground_content = ethereal.cavedirt,
  178. sounds = default.node_sound_stone_defaults(),
  179. })
  180. minetest.register_node(":bakedclay:grey", {
  181. description = S("Grey Baked Clay"),
  182. tiles = {"baked_clay_grey.png"},
  183. groups = {cracky = 3},
  184. is_ground_content = ethereal.cavedirt,
  185. sounds = default.node_sound_stone_defaults(),
  186. })
  187. end
  188. -- Quicksand (old style, sinking inside shows black instead of yellow effect,
  189. -- works ok with noclip enabled though)
  190. minetest.register_node("ethereal:quicksand", {
  191. description = S("Quicksand"),
  192. tiles = {"default_sand.png"},
  193. drop = "default:sand",
  194. liquid_viscosity = 15,
  195. liquidtype = "source",
  196. liquid_alternative_flowing = "ethereal:quicksand",
  197. liquid_alternative_source = "ethereal:quicksand",
  198. liquid_renewable = false,
  199. liquid_range = 0,
  200. drowning = 1,
  201. walkable = false,
  202. climbable = false,
  203. post_effect_color = {r = 230, g = 210, b = 160, a = 245},
  204. groups = {crumbly = 3, sand = 1, liquid = 3, disable_jump = 1},
  205. sounds = default.node_sound_sand_defaults(),
  206. })
  207. -- Quicksand (new style, sinking inside shows yellow effect with or without noclip,
  208. -- but old quicksand is shown as black until block placed nearby to update light)
  209. minetest.register_node("ethereal:quicksand2", {
  210. description = S("Quicksand"),
  211. tiles = {"default_sand.png"},
  212. drawtype = "glasslike",
  213. paramtype = "light",
  214. drop = "default:sand",
  215. liquid_viscosity = 15,
  216. liquidtype = "source",
  217. liquid_alternative_flowing = "ethereal:quicksand2",
  218. liquid_alternative_source = "ethereal:quicksand2",
  219. liquid_renewable = false,
  220. liquid_range = 0,
  221. drowning = 1,
  222. walkable = false,
  223. climbable = false,
  224. post_effect_color = {r = 230, g = 210, b = 160, a = 245},
  225. groups = {crumbly = 3, sand = 1, liquid = 3, disable_jump = 1},
  226. sounds = default.node_sound_sand_defaults(),
  227. })
  228. -- craft quicksand
  229. minetest.register_craft({
  230. output = "ethereal:quicksand2",
  231. recipe = {
  232. {"group:sand", "group:sand", "group:sand"},
  233. {"group:sand", "bucket:bucket_water", "group:sand"},
  234. {"group:sand", "group:sand", "group:sand"},
  235. },
  236. replacements = {
  237. {"bucket:bucket_water", "bucket:bucket_empty"}
  238. }
  239. })