dirt.lua 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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. -- register ethereal dirt types
  20. local dirts = {
  21. "Bamboo", "Jungle", "Grove", "Prairie", "Cold",
  22. "Crystal", "Mushroom", "Fiery", "Gray"
  23. }
  24. for n = 1, #dirts do
  25. local desc = dirts[n]
  26. local name = desc:lower()
  27. minetest.register_node("ethereal:" .. name .. "_dirt", {
  28. description = S(desc .. " Dirt"),
  29. tiles = {
  30. "ethereal_grass_" .. name .. "_top.png",
  31. "default_dirt.png",
  32. {
  33. name = "default_dirt.png^ethereal_grass_" .. 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 and node.name == "ethereal:crystalgrass" then
  63. local grass = minetest.find_nodes_in_area_under_air(
  64. pos0, pos1, {"ethereal:crystalgrass"})
  65. if #grass > 4
  66. and not minetest.find_node_near(pos, 4, {"ethereal:crystal_spike"}) then
  67. pos = grass[math.random(#grass)]
  68. pos.y = pos.y - 1
  69. if minetest.get_node(pos).name == "ethereal:crystal_dirt" then
  70. pos.y = pos.y + 1
  71. minetest.swap_node(pos, {name = "ethereal:crystal_spike"})
  72. end
  73. end
  74. return
  75. elseif num > 3 and node.name == "ethereal:dry_shrub" then
  76. local grass = minetest.find_nodes_in_area_under_air(
  77. pos0, pos1, {"ethereal:dry_shrub"})
  78. if #grass > 8
  79. and not minetest.find_node_near(pos, 4, {"ethereal:fire_flower"}) then
  80. pos = grass[math.random(#grass)]
  81. pos.y = pos.y - 1
  82. if minetest.get_node(pos).name == "ethereal:fiery_dirt" then
  83. pos.y = pos.y + 1
  84. minetest.swap_node(pos, {name = "ethereal:fire_flower"})
  85. end
  86. end
  87. return
  88. elseif num > 3 then
  89. return
  90. end
  91. pos.y = pos.y - 1
  92. local under = minetest.get_node(pos)
  93. -- make sure we have soil underneath
  94. if minetest.get_item_group(under.name, "soil") == 0
  95. or under.name == "default:desert_sand" then
  96. return
  97. end
  98. local seedling = minetest.find_nodes_in_area_under_air(
  99. pos0, pos1, {under.name})
  100. if #seedling > 0 then
  101. pos = seedling[math.random(#seedling)]
  102. pos.y = pos.y + 1
  103. if (minetest.get_node_light(pos) or 0) < 13 then
  104. return
  105. end
  106. minetest.swap_node(pos, {name = node.name})
  107. end
  108. end
  109. -- grow papyrus up to 4 high and bamboo up to 8 high
  110. local grow_papyrus = function(pos, node)
  111. local oripos = pos.y
  112. local high = 4
  113. pos.y = pos.y - 1
  114. local nod = minetest.get_node_or_nil(pos)
  115. if not nod
  116. or minetest.get_item_group(nod.name, "soil") < 1
  117. or minetest.find_node_near(pos, 3, {"group:water"}) == nil then
  118. return
  119. end
  120. if node.name == "ethereal:bamboo" then
  121. high = 8
  122. end
  123. pos.y = pos.y + 1
  124. local height = 0
  125. while height < high
  126. and minetest.get_node(pos).name == node.name do
  127. height = height + 1
  128. pos.y = pos.y + 1
  129. end
  130. nod = minetest.get_node_or_nil(pos)
  131. if nod
  132. and nod.name == "air"
  133. and height < high then
  134. if node.name == "ethereal:bamboo"
  135. and height == (high - 1) then
  136. ethereal.grow_bamboo_tree({x = pos.x, y = oripos, z = pos.z})
  137. else
  138. minetest.swap_node(pos, {name = node.name})
  139. end
  140. end
  141. end
  142. -- loop through active abm's
  143. for _, ab in pairs(minetest.registered_abms) do
  144. local label = ab.label or ""
  145. local node1 = ab.nodenames and ab.nodenames[1] or ""
  146. local node2 = ab.nodenames and ab.nodenames[2] or ""
  147. local neigh = ab.neighbors and ab.neighbors[1] or ""
  148. if label == "Flower spread"
  149. or node1 == "group:flora" then
  150. --ab.interval = 1
  151. ab.chance = 96 -- back to original chance from 300
  152. ab.nodenames = {"group:flora"}
  153. ab.neighbors = {"group:soil"}
  154. ab.action = flower_spread
  155. -- find grow papyrus abm and change to grow_papyrus function
  156. elseif label == "Grow papyrus"
  157. or node1 == "default:papyrus" then
  158. --ab.interval = 2
  159. --ab.chance = 1
  160. ab.nodenames = {"default:papyrus", "ethereal:bamboo"}
  161. ab.neighbors = {"group:soil"}
  162. ab.action = grow_papyrus
  163. elseif label == "Mushroom spread" then
  164. --ab.interval = 1
  165. ab.chance = 50 -- back to original chance from 150
  166. ab.nodenames = {"group:mushroom"}
  167. end
  168. end
  169. -- If Baked Clay mod not active, make Red, Orange and Grey nodes
  170. if not minetest.get_modpath("bakedclay") then
  171. minetest.register_node(":bakedclay:red", {
  172. description = S("Red Baked Clay"),
  173. tiles = {"baked_clay_red.png"},
  174. groups = {cracky = 3},
  175. is_ground_content = ethereal.cavedirt,
  176. sounds = default.node_sound_stone_defaults()
  177. })
  178. minetest.register_node(":bakedclay:orange", {
  179. description = S("Orange Baked Clay"),
  180. tiles = {"baked_clay_orange.png"},
  181. groups = {cracky = 3},
  182. is_ground_content = ethereal.cavedirt,
  183. sounds = default.node_sound_stone_defaults()
  184. })
  185. minetest.register_node(":bakedclay:grey", {
  186. description = S("Grey Baked Clay"),
  187. tiles = {"baked_clay_grey.png"},
  188. groups = {cracky = 3},
  189. is_ground_content = ethereal.cavedirt,
  190. sounds = default.node_sound_stone_defaults()
  191. })
  192. end
  193. -- Quicksand (old style, sinking inside shows black instead of yellow effect,
  194. -- works ok with noclip enabled though)
  195. minetest.register_node("ethereal:quicksand", {
  196. description = S("Quicksand"),
  197. tiles = {"default_sand.png"},
  198. drop = "default:sand",
  199. liquid_viscosity = 15,
  200. liquidtype = "source",
  201. liquid_alternative_flowing = "ethereal:quicksand",
  202. liquid_alternative_source = "ethereal:quicksand",
  203. liquid_renewable = false,
  204. liquid_range = 0,
  205. drowning = 1,
  206. walkable = false,
  207. climbable = false,
  208. post_effect_color = {r = 230, g = 210, b = 160, a = 245},
  209. groups = {crumbly = 3, sand = 1, liquid = 3, disable_jump = 1},
  210. sounds = default.node_sound_sand_defaults()
  211. })
  212. -- Quicksand (new style, sinking inside shows yellow effect with or without noclip,
  213. -- but old quicksand is shown as black until block placed nearby to update light)
  214. minetest.register_node("ethereal:quicksand2", {
  215. description = S("Quicksand"),
  216. tiles = {"default_sand.png^[colorize:#00004F10"},
  217. drawtype = "glasslike",
  218. paramtype = "light",
  219. drop = "default:sand",
  220. liquid_viscosity = 15,
  221. liquidtype = "source",
  222. liquid_alternative_flowing = "ethereal:quicksand2",
  223. liquid_alternative_source = "ethereal:quicksand2",
  224. liquid_renewable = false,
  225. liquid_range = 0,
  226. drowning = 1,
  227. walkable = false,
  228. climbable = false,
  229. post_effect_color = {r = 230, g = 210, b = 160, a = 245},
  230. groups = {crumbly = 3, sand = 1, liquid = 3, disable_jump = 1},
  231. sounds = default.node_sound_sand_defaults()
  232. })
  233. -- craft quicksand
  234. minetest.register_craft({
  235. output = "ethereal:quicksand2",
  236. recipe = {
  237. {"group:sand", "group:sand", "group:sand"},
  238. {"group:sand", "bucket:bucket_water", "group:sand"},
  239. {"group:sand", "group:sand", "group:sand"}
  240. },
  241. replacements = {
  242. {"bucket:bucket_water", "bucket:bucket_empty"}
  243. }
  244. })