registrations.lua 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408
  1. -- File is reloadable.
  2. -- Nodes update to their environment every 5 minutes to 60 minutes.
  3. local MIN_TIME = 60*5
  4. local MAX_TIME = 60*60
  5. local INTERACTION_DATA = {
  6. ["default:dirt"] = {
  7. -- Node turns to this if buried (node surrounded by nodes that block light).
  8. if_buried = "darkage:darkdirt",
  9. if_covered = {
  10. -- Ignore these nodes when checking whether node is covered by something.
  11. -- Note: non-walkable/buildable_to nodes are always ignored by default.
  12. ignore = {
  13. "group:snow", "group:leaves", "group:fence", "group:door", "group:trapdoor", "group:tree",
  14. "xdecor:stonepath",
  15. },
  16. },
  17. -- If present, this table informs the algorithm what order to apply `when_*_near` checks.
  18. -- This may be needed in order to break endless looping interactions.
  19. -- Checks are performed in the order in which they appear here.
  20. -- Note that if you use this table, then all checks MUST be listed. Checks which are
  21. -- not listed will not be applied!
  22. action_ordering = {
  23. "lava",
  24. "fire",
  25. "ice",
  26. "snow1",
  27. "snow2",
  28. "sand",
  29. "flora",
  30. "tree",
  31. "leaves",
  32. "grass",
  33. },
  34. -- The key name doesn't actually matter, it can be anything,
  35. -- as long as it begins with "when_" and ends with "_near".
  36. when_lava_near = {
  37. nodenames = {"group:lava", "group:rockmelt"},
  38. if_nearby = "darkage:darkdirt",
  39. },
  40. when_fire_near = {
  41. nodenames = "group:fire",
  42. if_nearby = "default:dry_dirt",
  43. },
  44. when_ice_near = {
  45. nodenames = "group:ice",
  46. if_nearby = "default:permafrost",
  47. },
  48. when_snow1_near = {
  49. nodenames = {"group:snow"},
  50. if_above = "default:dirt_with_snow",
  51. if_below = "default:permafrost",
  52. },
  53. when_snow2_near = {
  54. nodenames = {"group:snow", "group:snowy"},
  55. if_nearby = "default:dirt_with_snow",
  56. require_not_covered = true,
  57. },
  58. when_sand_near = {
  59. nodenames = "group:sand",
  60. if_above = "darkage:darkdirt",
  61. if_below = "default:dry_dirt",
  62. if_nearby = "default:dry_dirt",
  63. },
  64. when_grass_near = {
  65. nodenames = {"default:dirt_with_grass", "default:dirt_with_grass_footsteps", "default:dirt_with_dry_grass", "moregrass:darkgrass"},
  66. require_not_covered = true,
  67. -- If value is not a string, then it must be a function.
  68. -- The signature is `pos`, `light`, `loc`, `name`, `def`, `groups`.
  69. -- `pos` is the position of the current node, `loc` is the triggering neighbor position.
  70. -- Can return nothing if nothing is to be done.
  71. if_adjacent_side = function(pos, light, loc, name, def, groups)
  72. if light < 13 then
  73. return "", true -- Wait a bit.
  74. end
  75. -- Special case.
  76. if name == "default:dirt_with_grass_footsteps" then
  77. name = "default:dirt_with_grass"
  78. end
  79. return name
  80. end,
  81. },
  82. -- Shall return the nodename to set, or "" to leave unchanged.
  83. -- Return boolean second parameter to indicate whether to wait.
  84. when_flora_near = {
  85. nodenames = {"group:flora", "default:dry_shrub"},
  86. require_not_covered = true,
  87. if_above = function(pos, light, loc, name, def, groups)
  88. if name == "default:dry_shrub" then
  89. return "default:dry_dirt"
  90. end
  91. if groups.junglegrass and groups.junglegrass > 0 then
  92. if light >= 13 then
  93. return "moregrass:darkgrass"
  94. else
  95. return "", true
  96. end
  97. elseif groups.dry_grass and groups.dry_grass > 0 then
  98. if light >= 13 then
  99. return "default:dirt_with_dry_grass"
  100. else
  101. return "", true
  102. end
  103. elseif groups.grass and groups.grass > 0 then
  104. if light >= 13 then
  105. return "default:dirt_with_grass"
  106. else
  107. return "", true
  108. end
  109. end
  110. end,
  111. },
  112. when_leaves_near = {
  113. nodenames = "group:leaves",
  114. if_above = function(pos, light, loc, name, def, groups)
  115. local water = minetest.find_node_near(pos, 5, "group:water")
  116. if water then
  117. return "default:dirt_with_rainforest_litter"
  118. else
  119. return "default:dirt_with_coniferous_litter"
  120. end
  121. end,
  122. },
  123. when_tree_near = {
  124. nodenames = "group:tree",
  125. if_above = function(pos, light, loc, name, def, groups)
  126. return "default:dirt_with_rainforest_litter"
  127. end,
  128. },
  129. },
  130. ["default:dirt_with_grass"] = {
  131. if_buried = "default:dirt",
  132. if_covered = {
  133. ignore = {"group:fence", "group:door", "group:trapdoor", "xdecor:stonepath"},
  134. action = "default:dirt",
  135. },
  136. action_ordering = {
  137. "lava",
  138. "fire",
  139. "snow",
  140. "ice",
  141. "sand",
  142. },
  143. when_lava_near = {
  144. nodenames = {"group:lava", "group:rockmelt"},
  145. if_nearby = "darkage:darkdirt",
  146. },
  147. when_fire_near = {
  148. nodenames = "group:fire",
  149. if_nearby = "default:dirt_with_dry_grass",
  150. require_not_covered = true,
  151. },
  152. when_snow_near = {
  153. nodenames = "group:snow",
  154. if_adjacent_side = "default:dirt_with_dry_grass",
  155. require_not_covered = true,
  156. },
  157. when_ice_near = {
  158. nodenames = "group:ice",
  159. if_nearby = "default:dirt_with_dry_grass",
  160. require_not_covered = true,
  161. },
  162. when_sand_near = {
  163. nodenames = "group:sand",
  164. if_adjacent_side = "default:dirt_with_dry_grass",
  165. require_not_covered = true,
  166. },
  167. },
  168. ["default:dirt_with_dry_grass"] = {
  169. if_buried = "default:dirt",
  170. if_covered = {
  171. ignore = {"group:fence", "group:door", "group:trapdoor", "xdecor:stonepath"},
  172. action = "default:dirt",
  173. },
  174. action_ordering = {
  175. "lava",
  176. "fire",
  177. "snow",
  178. "ice",
  179. "sand",
  180. },
  181. when_lava_near = {
  182. nodenames = {"group:lava", "group:rockmelt"},
  183. if_nearby = "darkage:darkdirt",
  184. },
  185. when_fire_near = {
  186. nodenames = "group:fire",
  187. if_nearby = "default:dirt",
  188. },
  189. when_snow_near = {
  190. nodenames = "group:snow",
  191. if_above = "default:dirt_with_snow",
  192. require_not_covered = true,
  193. },
  194. when_ice_near = {
  195. nodenames = "group:ice",
  196. if_nearby = "default:dirt",
  197. require_not_covered = true,
  198. },
  199. when_sand_near = {
  200. nodenames = "group:sand",
  201. if_adjacent_side = "default:dry_dirt_with_dry_grass",
  202. require_not_covered = true,
  203. },
  204. },
  205. ["moregrass:darkgrass"] = {
  206. if_buried = "default:dirt",
  207. if_covered = {
  208. ignore = {"group:fence", "group:door", "group:trapdoor", "xdecor:stonepath"},
  209. action = "default:dirt",
  210. },
  211. action_ordering = {
  212. "lava",
  213. "fire",
  214. "snow",
  215. "cold",
  216. "sand",
  217. "dry",
  218. "stonepath",
  219. "junglegrass",
  220. },
  221. when_junglegrass_near = {
  222. nodenames = "default:junglegrass",
  223. if_above = "default:dirt_with_rainforest_litter",
  224. },
  225. when_lava_near = {
  226. nodenames = {"group:lava", "group:rockmelt"},
  227. if_nearby = "darkage:darkdirt",
  228. },
  229. when_fire_near = {
  230. nodenames = "group:fire",
  231. if_nearby = "default:dirt_with_dry_grass",
  232. require_not_covered = true,
  233. },
  234. when_snow_near = {
  235. nodenames = "group:snow",
  236. if_above = "default:dirt_with_snow",
  237. require_not_covered = true,
  238. },
  239. when_cold_near = {
  240. nodenames = {"group:ice", "group:cold", "group:snowy"},
  241. if_nearby = "default:dirt_with_grass",
  242. require_not_covered = true,
  243. },
  244. when_sand_near = {
  245. nodenames = "group:sand",
  246. if_adjacent_side = "default:dirt_with_dry_grass",
  247. require_not_covered = true,
  248. },
  249. when_dry_near = {
  250. nodenames = {"default:dirt_with_dry_grass", "default:dry_dirt_with_dry_grass", "darkage:darkdirt", "default:dry_dirt"},
  251. if_nearby = "default:dirt_with_grass",
  252. require_not_covered = true,
  253. },
  254. when_stonepath_near = {
  255. nodenames = "xdecor:stonepath",
  256. if_above = "default:dirt_with_grass",
  257. },
  258. },
  259. ["default:dirt_with_snow"] = {
  260. if_buried = "default:dirt",
  261. if_covered = {
  262. ignore = {"group:snow", "group:fence", "group:door", "group:trapdoor", "xdecor:stonepath"},
  263. action = "default:dirt",
  264. },
  265. action_ordering = {
  266. "lava",
  267. "fire",
  268. },
  269. when_lava_near = {
  270. nodenames = {"group:lava", "group:rockmelt"},
  271. if_nearby = "darkage:darkdirt",
  272. },
  273. when_fire_near = {
  274. nodenames = "group:fire",
  275. if_nearby = "default:dirt",
  276. },
  277. },
  278. ["darkage:darkdirt"] = {
  279. if_covered = {
  280. ignore = {"group:snow", "group:ice", "group:leaves"},
  281. },
  282. action_ordering = {"snow", "ice", "leaves", "minerals"},
  283. when_snow_near = {
  284. nodenames = "group:snow",
  285. if_above = "default:dark_dirt_with_snow",
  286. if_adjacent_side = "default:dark_dirt_with_snow",
  287. require_not_covered = true,
  288. },
  289. when_minerals_near = {
  290. nodenames = "glowstone:minerals",
  291. require_not_covered = true,
  292. if_below = function(pos, light, loc, name, def, groups)
  293. -- The minerals are used up.
  294. minetest.remove_node(loc)
  295. -- But regular dirt is made.
  296. return "default:dirt"
  297. end,
  298. },
  299. when_ice_near = {
  300. nodenames = "group:ice",
  301. if_above = "default:permafrost",
  302. if_below = "default:permafrost",
  303. if_adjacent_side = "default:permafrost",
  304. },
  305. when_leaves_near = {
  306. nodenames = "group:leaves",
  307. if_above = function(pos, light, loc, name, def, groups)
  308. local water = minetest.find_node_near(pos, 5, "group:water")
  309. if water then
  310. return "default:dark_dirt_with_rainforest_litter"
  311. else
  312. return "default:dark_dirt_with_coniferous_litter"
  313. end
  314. end,
  315. },
  316. },
  317. ["default:dark_dirt_with_snow"] = {
  318. if_covered = {
  319. ignore = {"group:snow", "group:fence", "group:door", "group:trapdoor", "xdecor:stonepath"},
  320. action = "darkage:darkdirt",
  321. },
  322. action_ordering = {"lava", "fire"},
  323. when_lava_near = {
  324. nodenames = {"group:lava", "group:rockmelt"},
  325. if_nearby = "darkage:darkdirt",
  326. },
  327. when_fire_near = {
  328. nodenames = "group:fire",
  329. if_nearby = "darkage:darkdirt",
  330. },
  331. },
  332. ["default:dry_dirt"] = {
  333. if_buried = "darkage:darkdirt",
  334. if_covered = {
  335. ignore = {"group:snow", "group:leaves"},
  336. },
  337. action_ordering = {"lava", "water", "snow", "leaves"},
  338. when_lava_near = {
  339. nodenames = {"group:lava", "group:rockmelt"},
  340. if_nearby = "darkage:darkdirt",
  341. },
  342. when_water_near = {
  343. nodenames = "group:water",
  344. if_nearby = "default:dirt",
  345. },
  346. when_snow_near = {
  347. nodenames = "group:snow",
  348. if_nearby = "default:dry_dirt_with_snow",
  349. },
  350. when_leaves_near = {
  351. nodenames = "group:leaves",
  352. if_above = function(pos, light, loc, name, def, groups)
  353. local water = minetest.find_node_near(pos, 5, "group:water")
  354. if water then
  355. return "default:dry_dirt_with_rainforest_litter"
  356. else
  357. return "default:dry_dirt_with_coniferous_litter"
  358. end
  359. end,
  360. },
  361. },
  362. ["default:dry_dirt_with_snow"] = {
  363. if_buried = "default:dry_dirt",
  364. if_covered = {
  365. ignore = {"group:snow", "group:door", "group:trapdoor", "group:fence", "xdecor:stonepath"},
  366. action = "default:dry_dirt",
  367. },
  368. action_ordering = {"lava", "water", "fire"},
  369. when_lava_near = {
  370. nodenames = {"group:lava", "group:rockmelt"},
  371. if_nearby = "darkage:darkdirt",
  372. },
  373. when_water_near = {
  374. nodenames = "group:water",
  375. if_nearby = "default:dirt_with_snow",
  376. },
  377. when_fire_near = {
  378. nodenames = "group:fire",
  379. if_nearby = "default:dry_dirt",
  380. },
  381. },
  382. ["default:dirt_with_rainforest_litter"] = {
  383. if_buried = "default:dirt",
  384. if_covered = {
  385. ignore = {"group:leaves", "group:tree", "group:door", "group:trapdoor", "group:fence", "xdecor:stonepath"},
  386. action = "default:dirt",
  387. },
  388. action_ordering = {"lava", "fire"},
  389. when_lava_near = {
  390. nodenames = {"group:lava", "group:rockmelt"},
  391. if_nearby = "darkage:darkdirt",
  392. },
  393. when_fire_near = {
  394. nodenames = "group:fire",
  395. if_nearby = "default:dry_dirt_with_rainforest_litter",
  396. },
  397. },
  398. ["default:dirt_with_coniferous_litter"] = {
  399. if_buried = "default:dirt",
  400. if_covered = {
  401. ignore = {"group:leaves", "group:door", "group:trapdoor", "group:fence", "xdecor:stonepath"},
  402. action = "default:dirt",
  403. },
  404. action_ordering = {"lava", "fire"},
  405. when_lava_near = {
  406. nodenames = {"group:lava", "group:rockmelt"},
  407. if_nearby = "darkage:darkdirt",
  408. },
  409. when_fire_near = {
  410. nodenames = "group:fire",
  411. if_nearby = "default:dry_dirt_with_coniferous_litter",
  412. },
  413. },
  414. ["default:dark_dirt_with_rainforest_litter"] = {
  415. if_buried = "darkage:darkdirt",
  416. if_covered = {
  417. ignore = {"group:leaves", "group:door", "group:trapdoor", "group:fence", "xdecor:stonepath"},
  418. action = "darkage:darkdirt",
  419. },
  420. action_ordering = {"lava", "fire"},
  421. when_lava_near = {
  422. nodenames = {"group:lava", "group:rockmelt"},
  423. if_nearby = "darkage:darkdirt",
  424. },
  425. when_fire_near = {
  426. nodenames = "group:fire",
  427. if_nearby = "darkage:darkdirt",
  428. },
  429. },
  430. ["default:dark_dirt_with_coniferous_litter"] = {
  431. if_buried = "darkage:darkdirt",
  432. if_covered = {
  433. ignore = {"group:leaves", "group:door", "group:trapdoor", "group:fence", "xdecor:stonepath"},
  434. action = "darkage:darkdirt",
  435. },
  436. action_ordering = {"lava", "fire"},
  437. when_lava_near = {
  438. nodenames = {"group:lava", "group:rockmelt"},
  439. if_nearby = "darkage:darkdirt",
  440. },
  441. when_fire_near = {
  442. nodenames = "group:fire",
  443. if_nearby = "darkage:darkdirt",
  444. },
  445. },
  446. ["default:dry_dirt_with_rainforest_litter"] = {
  447. if_buried = "default:dry_dirt",
  448. if_covered = {
  449. ignore = {"group:leaves", "group:door", "group:trapdoor", "group:fence", "xdecor:stonepath"},
  450. action = "default:dry_dirt",
  451. },
  452. action_ordering = {"lava", "water", "fire"},
  453. when_lava_near = {
  454. nodenames = {"group:lava", "group:rockmelt"},
  455. if_nearby = "darkage:darkdirt",
  456. },
  457. when_water_near = {
  458. nodenames = "group:water",
  459. if_nearby = "default:dirt_with_rainforest_litter",
  460. },
  461. when_fire_near = {
  462. nodenames = "group:fire",
  463. if_nearby = "default:dry_dirt",
  464. },
  465. },
  466. ["default:dry_dirt_with_coniferous_litter"] = {
  467. if_buried = "default:dry_dirt",
  468. if_covered = {
  469. ignore = {"group:leaves", "group:door", "group:trapdoor", "group:fence", "xdecor:stonepath"},
  470. action = "default:dry_dirt",
  471. },
  472. action_ordering = {"lava", "water", "fire"},
  473. when_lava_near = {
  474. nodenames = {"group:lava", "group:rockmelt"},
  475. if_nearby = "darkage:darkdirt",
  476. },
  477. when_water_near = {
  478. nodenames = "group:water",
  479. if_nearby = "default:dirt_with_coniferous_litter",
  480. },
  481. when_fire_near = {
  482. nodenames = "group:fire",
  483. if_nearby = "default:dry_dirt",
  484. },
  485. },
  486. ["default:dry_dirt_with_dry_grass"] = {
  487. if_buried = "default:dry_dirt",
  488. if_covered = {
  489. ignore = {"group:door", "group:trapdoor", "group:fence", "xdecor:stonepath"},
  490. action = "default:dry_dirt",
  491. },
  492. action_ordering = {"lava", "water", "fire"},
  493. when_lava_near = {
  494. nodenames = {"group:lava", "group:rockmelt"},
  495. if_nearby = "darkage:darkdirt",
  496. },
  497. when_water_near = {
  498. nodenames = "group:water",
  499. if_nearby = "default:dirt_with_dry_grass",
  500. },
  501. when_fire_near = {
  502. nodenames = "group:fire",
  503. if_nearby = "default:dry_dirt",
  504. },
  505. },
  506. ["default:permafrost"] = {
  507. if_covered = {
  508. ignore = {
  509. "group:snow",
  510. "default:cobble",
  511. "cavestuff:cobble_with_moss",
  512. "cavestuff:cobble_with_lichen",
  513. "cavestuff:cobble_with_algae",
  514. "cavestuff:cobble_with_salt",
  515. "cavestuff:cobble",
  516. "group:ice",
  517. },
  518. },
  519. action_ordering = {
  520. "lava",
  521. "fire",
  522. "snow",
  523. "cobble",
  524. "grass",
  525. "flora",
  526. },
  527. when_lava_near = {
  528. nodenames = {"group:lava", "group:rockmelt"},
  529. if_nearby = "darkage:darkdirt",
  530. },
  531. when_fire_near = {
  532. nodenames = "group:fire",
  533. if_nearby = "darkage:darkdirt",
  534. },
  535. when_snow_near = {
  536. nodenames = "group:snow",
  537. if_above = "default:permafrost_with_snow",
  538. require_not_covered = true,
  539. },
  540. when_cobble_near = {
  541. nodenames = {
  542. "default:cobble",
  543. "cavestuff:cobble_with_moss",
  544. "cavestuff:cobble_with_lichen",
  545. "cavestuff:cobble_with_algae",
  546. "cavestuff:cobble_with_salt",
  547. "cavestuff:cobble",
  548. "group:ice", -- Also brings stone in permafrost to the surface.
  549. },
  550. if_above = "default:permafrost_with_stones",
  551. },
  552. when_flora_near = {
  553. nodenames = "group:flora",
  554. if_above = "default:permafrost_with_moss",
  555. require_not_covered = true,
  556. },
  557. when_grass_near = {
  558. nodenames = {"moregrass:darkgrass", "default:dirt_with_grass"},
  559. if_adjacent_side = "default:permafrost_with_moss",
  560. require_not_covered = true,
  561. },
  562. },
  563. ["default:permafrost_with_snow"] = {
  564. if_covered = {
  565. ignore = {
  566. "group:snow",
  567. "default:cobble",
  568. "cavestuff:cobble_with_moss",
  569. "cavestuff:cobble_with_lichen",
  570. "cavestuff:cobble_with_algae",
  571. "cavestuff:cobble_with_salt",
  572. "cavestuff:cobble",
  573. "group:door", "group:trapdoor", "group:fence", "xdecor:stonepath",
  574. },
  575. action = "default:permafrost",
  576. },
  577. action_ordering = {
  578. "lava",
  579. "fire",
  580. "cobble",
  581. },
  582. when_lava_near = {
  583. nodenames = {"group:lava", "group:rockmelt"},
  584. if_nearby = "darkage:darkdirt",
  585. },
  586. when_fire_near = {
  587. nodenames = "group:fire",
  588. if_nearby = "default:permafrost",
  589. },
  590. when_cobble_near = {
  591. nodenames = {
  592. "default:cobble",
  593. "cavestuff:cobble_with_moss",
  594. "cavestuff:cobble_with_lichen",
  595. "cavestuff:cobble_with_algae",
  596. "cavestuff:cobble_with_salt",
  597. "cavestuff:cobble",
  598. },
  599. if_above = "default:permafrost_with_snow_and_stones",
  600. },
  601. },
  602. ["default:permafrost_with_stones"] = {
  603. if_buried = "default:permafrost",
  604. if_covered = {
  605. ignore = {"group:snow", "group:door", "group:trapdoor", "group:fence", "xdecor:stonepath"},
  606. },
  607. action_ordering = {
  608. "lava",
  609. "snow",
  610. "flora",
  611. },
  612. when_lava_near = {
  613. nodenames = {"group:lava", "group:rockmelt"},
  614. if_nearby = "darkage:darkdirt",
  615. },
  616. when_snow_near = {
  617. nodenames = "group:snow",
  618. if_above = "default:permafrost_with_snow_and_stones",
  619. },
  620. when_flora_near = {
  621. nodenames = "group:flora",
  622. if_above = "default:permafrost_with_moss_and_stones",
  623. require_not_covered = true,
  624. },
  625. },
  626. ["default:permafrost_with_snow_and_stones"] = {
  627. if_covered = {
  628. ignore = {
  629. "group:snow",
  630. "default:cobble",
  631. "cavestuff:cobble_with_moss",
  632. "cavestuff:cobble_with_lichen",
  633. "cavestuff:cobble_with_algae",
  634. "cavestuff:cobble_with_salt",
  635. "cavestuff:cobble",
  636. "group:door", "group:trapdoor", "group:fence", "xdecor:stonepath",
  637. },
  638. action = "default:permafrost_with_stones",
  639. },
  640. action_ordering = {
  641. "lava",
  642. "fire",
  643. "cobble",
  644. },
  645. when_lava_near = {
  646. nodenames = {"group:lava", "group:rockmelt"},
  647. if_nearby = "darkage:darkdirt",
  648. },
  649. when_fire_near = {
  650. nodenames = "group:fire",
  651. if_nearby = "default:permafrost_with_stones",
  652. },
  653. when_cobble_near = {
  654. nodenames = {
  655. "default:cobble",
  656. "cavestuff:cobble_with_moss",
  657. "cavestuff:cobble_with_lichen",
  658. "cavestuff:cobble_with_algae",
  659. "cavestuff:cobble_with_salt",
  660. "cavestuff:cobble",
  661. },
  662. if_above = "default:permafrost_with_stones",
  663. },
  664. },
  665. ["default:permafrost_with_moss"] = {
  666. if_buried = "default:permafrost",
  667. if_covered = {
  668. ignore = {
  669. "group:snow",
  670. "default:cobble",
  671. "cavestuff:cobble_with_moss",
  672. "cavestuff:cobble_with_lichen",
  673. "cavestuff:cobble_with_algae",
  674. "cavestuff:cobble_with_salt",
  675. "cavestuff:cobble",
  676. "group:door", "group:trapdoor", "group:fence", "xdecor:stonepath",
  677. },
  678. action = "default:permafrost",
  679. },
  680. action_ordering = {
  681. "lava",
  682. "fire",
  683. "snow",
  684. "cobble",
  685. "junglegrass",
  686. },
  687. when_lava_near = {
  688. nodenames = {"group:lava", "group:rockmelt"},
  689. if_nearby = "darkage:darkdirt",
  690. },
  691. when_fire_near = {
  692. nodenames = "group:fire",
  693. if_nearby = "default:permafrost",
  694. },
  695. when_snow_near = {
  696. nodenames = "group:snow",
  697. if_above = "default:permafrost_with_snow",
  698. if_adjacent_side = "default:permafrost_with_snow",
  699. require_not_covered = true,
  700. },
  701. when_junglegrass_near = {
  702. nodenames = {"default:junglegrass", "group:grass"},
  703. if_above = "default:permafrost_with_moss_and_stones",
  704. },
  705. when_cobble_near = {
  706. nodenames = {
  707. "default:cobble",
  708. "cavestuff:cobble_with_moss",
  709. "cavestuff:cobble_with_lichen",
  710. "cavestuff:cobble_with_algae",
  711. "cavestuff:cobble_with_salt",
  712. "cavestuff:cobble",
  713. },
  714. if_above = "default:permafrost_with_stones",
  715. },
  716. },
  717. ["default:permafrost_with_moss_and_stones"] = {
  718. if_buried = "default:permafrost",
  719. if_covered = {
  720. ignore = {
  721. "group:snow", "group:door", "group:trapdoor", "group:fence", "xdecor:stonepath",
  722. },
  723. action = "default:permafrost_with_stones",
  724. },
  725. action_ordering = {
  726. "lava",
  727. "fire",
  728. "snow",
  729. },
  730. when_lava_near = {
  731. nodenames = {"group:lava", "group:rockmelt"},
  732. if_nearby = "darkage:darkdirt",
  733. },
  734. when_fire_near = {
  735. nodenames = "group:fire",
  736. if_nearby = "default:permafrost_with_stones",
  737. },
  738. when_snow_near = {
  739. nodenames = "group:snow",
  740. if_above = "default:permafrost_with_snow_and_stones",
  741. require_not_covered = true,
  742. },
  743. },
  744. ["default:sand"] = {
  745. when_snow_near = {
  746. nodenames = {"group:snow", "group:ice"},
  747. if_nearby = "sand:sand_with_ice_crystals",
  748. },
  749. },
  750. ["default:snow"] = {
  751. action_ordering = {"lava", "fire"},
  752. when_lava_near = {
  753. nodenames = {"group:lava", "group:rockmelt"},
  754. if_nearby = "fire:basic_flame",
  755. },
  756. when_fire_near = {
  757. nodenames = "group:fire",
  758. if_nearby = "air",
  759. },
  760. },
  761. ["default:snowblock"] = {
  762. action_ordering = {"lava", "fire"},
  763. when_lava_near = {
  764. nodenames = {"group:lava", "group:rockmelt"},
  765. if_nearby = "fire:basic_flame",
  766. },
  767. when_fire_near = {
  768. nodenames = "group:fire",
  769. if_nearby = "air",
  770. },
  771. },
  772. ["snow:footprints"] = {
  773. action_ordering = {"lava", "fire"},
  774. when_lava_near = {
  775. nodenames = {"group:lava", "group:rockmelt"},
  776. if_nearby = "fire:basic_flame",
  777. },
  778. when_fire_near = {
  779. nodenames = "group:fire",
  780. if_nearby = "air",
  781. },
  782. },
  783. ["cavestuff:cobble_with_moss"] = {
  784. action_ordering = {"lava", "fire", "snow"},
  785. if_covered = {
  786. ignore = {
  787. "group:snow", "group:door", "group:trapdoor", "group:fence", "xdecor:stonepath",
  788. },
  789. action = "default:cobble",
  790. },
  791. when_lava_near = {
  792. nodenames = {"group:lava", "group:rockmelt"},
  793. if_nearby = "default:cobble",
  794. },
  795. when_fire_near = {
  796. nodenames = "group:fire",
  797. if_nearby = "default:cobble",
  798. },
  799. when_snow_near = {
  800. nodenames = "group:snow",
  801. if_nearby = "default:cobble",
  802. },
  803. },
  804. ["cavestuff:cobble_with_lichen"] = {
  805. action_ordering = {"lava", "fire", "snow"},
  806. if_covered = {
  807. ignore = {
  808. "group:snow", "group:door", "group:trapdoor", "group:fence", "xdecor:stonepath",
  809. },
  810. action = "default:cobble",
  811. },
  812. when_lava_near = {
  813. nodenames = {"group:lava", "group:rockmelt"},
  814. if_nearby = "default:cobble",
  815. },
  816. when_fire_near = {
  817. nodenames = "group:fire",
  818. if_nearby = "default:cobble",
  819. },
  820. when_snow_near = {
  821. nodenames = "group:snow",
  822. if_nearby = "default:cobble",
  823. },
  824. },
  825. ["cavestuff:cobble_with_algae"] = {
  826. action_ordering = {"lava", "fire", "snow"},
  827. if_covered = {
  828. ignore = {
  829. "group:snow", "group:door", "group:trapdoor", "group:fence", "xdecor:stonepath",
  830. },
  831. action = "default:cobble",
  832. },
  833. when_lava_near = {
  834. nodenames = {"group:lava", "group:rockmelt"},
  835. if_nearby = "default:cobble",
  836. },
  837. when_fire_near = {
  838. nodenames = "group:fire",
  839. if_nearby = "default:cobble",
  840. },
  841. when_snow_near = {
  842. nodenames = "group:snow",
  843. if_nearby = "default:cobble",
  844. },
  845. },
  846. ["cavestuff:cobble_with_salt"] = {
  847. action_ordering = {"lava", "fire", "snow"},
  848. if_covered = {
  849. ignore = {
  850. "group:snow", "group:door", "group:trapdoor", "group:fence", "xdecor:stonepath",
  851. },
  852. action = "default:cobble",
  853. },
  854. when_lava_near = {
  855. nodenames = {"group:lava", "group:rockmelt"},
  856. if_nearby = "default:cobble",
  857. },
  858. when_fire_near = {
  859. nodenames = "group:fire",
  860. if_nearby = "default:cobble",
  861. },
  862. when_snow_near = {
  863. nodenames = "group:snow",
  864. if_nearby = "default:cobble",
  865. },
  866. },
  867. }
  868. -- Copy.
  869. INTERACTION_DATA["default:dirt_with_grass_footsteps"] = INTERACTION_DATA["default:dirt_with_grass"]
  870. -- If function uses `minetest.add_node`, neighbor nodes will be notified again.
  871. -- This can create a cascade effect, which may or may not be desired.
  872. -- Return `true` to restart the timer and call this function again later (useful if you need to wait before changing the node).
  873. local HANDLER = function(pos, node)
  874. -- Get the interaction data table for this active block.
  875. local interaction_data = INTERACTION_DATA[node.name]
  876. if not interaction_data then
  877. return
  878. end
  879. local above = {x=pos.x, y=pos.y+1, z=pos.z}
  880. local below = {x=pos.x, y=pos.y-1, z=pos.z}
  881. -- Get current light level above node.
  882. local light_above = minetest.get_node_light(above) or 0
  883. -- Action when node is in complete darkness (is buried, no light).
  884. if interaction_data.if_buried then
  885. local sides_6 = {
  886. {x=pos.x+1, y=pos.y, z=pos.z},
  887. {x=pos.x-1, y=pos.y, z=pos.z},
  888. {x=pos.x, y=pos.y+1, z=pos.z},
  889. {x=pos.x, y=pos.y-1, z=pos.z},
  890. {x=pos.x, y=pos.y, z=pos.z+1},
  891. {x=pos.x, y=pos.y, z=pos.z-1},
  892. }
  893. local light = 0
  894. for k, v in ipairs(sides_6) do
  895. local ll = minetest.get_node_light(v, 0.5) or 0
  896. light = light + ll
  897. -- Early exit if light is detected quickly.
  898. if light > 0 then
  899. break
  900. end
  901. end
  902. if light == 0 then
  903. if interaction_data.if_buried ~= node.name then
  904. node.name = interaction_data.if_buried
  905. minetest.add_node(pos, node)
  906. minetest.check_for_falling(pos)
  907. return
  908. end
  909. end
  910. end
  911. local node_has_name_or_group = function(nn, name)
  912. local tt = type(name)
  913. if tt == "string" then
  914. if nn == name then
  915. return true
  916. elseif name:find("^group:") then
  917. local g = name:sub(7)
  918. local d = minetest.registered_nodes[nn]
  919. if d then
  920. local g2 = d.groups or {}
  921. if g2[g] and g2[g] > 0 then
  922. return true
  923. end
  924. end
  925. end
  926. elseif tt == "table" then
  927. local d
  928. local g2
  929. for _, n in ipairs(name) do
  930. if nn == n then
  931. return true
  932. elseif n:find("^group:") then
  933. local g = n:sub(7)
  934. -- No mater how many groups/names to test against, get the node def and groups only once.
  935. if not d then
  936. d = minetest.registered_nodes[nn]
  937. end
  938. if not g2 then
  939. g2 = d and d.groups or {}
  940. end
  941. if g2[g] and g2[g] > 0 then
  942. return true
  943. end
  944. end
  945. end
  946. end
  947. end
  948. -- Action when the node is covered (by liquid or walkable node).
  949. -- A node is covered if the node above it takes up a whole block.
  950. -- There shall be a seperate facility for handling partial nodes.
  951. local is_covered = false
  952. -- Check whether the node is covered.
  953. do
  954. local n2 = minetest.get_node(above)
  955. local ignore = false
  956. local dt = interaction_data.if_covered
  957. if type(dt) == "table" then
  958. if dt.ignore and node_has_name_or_group(n2.name, dt.ignore) then
  959. ignore = true
  960. end
  961. end
  962. if not ignore then
  963. local d2 = minetest.registered_nodes[n2.name]
  964. if d2 then
  965. local walkable = d2.walkable
  966. local liquid = d2.liquidtype or "none"
  967. -- buildable_to nodes cannot cover other nodes (even if walkable).
  968. if not d2.buildable_to then
  969. if walkable then
  970. is_covered = true
  971. end
  972. end
  973. -- Liquid nodes cover other nodes (unless ignored).
  974. -- This check needs to be separate from above because liquids are buildable_to.
  975. if liquid ~= "none" then
  976. is_covered = true
  977. end
  978. end
  979. end
  980. end
  981. -- Action to take if the node is covered by liquid or walkable (and not ignored).
  982. if interaction_data.if_covered and is_covered then
  983. local dt = interaction_data.if_covered
  984. if type(dt) == "string" then
  985. if node.name ~= dt then
  986. node.name = dt
  987. minetest.add_node(pos, node)
  988. minetest.check_for_falling(pos)
  989. return
  990. end
  991. elseif type(dt) == "table" then
  992. if dt.action then
  993. if type(dt.action) == "string" then
  994. if dt.action ~= node.name then
  995. node.name = dt.action
  996. minetest.add_node(pos, node)
  997. minetest.check_for_falling(pos)
  998. return
  999. end
  1000. elseif type(dt.action) == "function" then
  1001. local p2 = {x=pos.x, y=pos.y+1, z=pos.z}
  1002. local n2 = minetest.get_node(p2)
  1003. local d2 = minetest.registered_nodes[n2.name]
  1004. local g2 = d2 and d2.groups or {}
  1005. if d2 then
  1006. local ret, wait = dt.action(pos, light_above, p2, n2.name, d2, g2)
  1007. if ret and ret ~= "" then
  1008. if node.name ~= ret then
  1009. node.name = ret
  1010. minetest.add_node(pos, node)
  1011. minetest.check_for_falling(pos)
  1012. return -- Don't wait, done.
  1013. end
  1014. elseif wait then
  1015. return true-- Wait, not done.
  1016. end
  1017. end
  1018. end
  1019. end
  1020. end
  1021. end
  1022. -- Get what's to the 4 sides (not including center or corners).
  1023. local all_neighbors = {
  1024. -- Adjacent horizontal sides.
  1025. {x=pos.x-1, y=pos.y, z=pos.z },
  1026. {x=pos.x+1, y=pos.y, z=pos.z },
  1027. {x=pos.x, y=pos.y, z=pos.z-1},
  1028. {x=pos.x, y=pos.y, z=pos.z+1},
  1029. -- Horizontal diagonals.
  1030. {x=pos.x+1, y=pos.y, z=pos.z+1},
  1031. {x=pos.x-1, y=pos.y, z=pos.z+1},
  1032. {x=pos.x+1, y=pos.y, z=pos.z-1},
  1033. {x=pos.x-1, y=pos.y, z=pos.z-1},
  1034. -- Directly below.
  1035. {x=pos.x, y=pos.y-1, z=pos.z },
  1036. -- Adjacent sides below.
  1037. {x=pos.x+1, y=pos.y-1, z=pos.z },
  1038. {x=pos.x-1, y=pos.y-1, z=pos.z },
  1039. {x=pos.x, y=pos.y-1, z=pos.z+1},
  1040. {x=pos.x, y=pos.y-1, z=pos.z-1},
  1041. -- Adjacent diagonals below.
  1042. {x=pos.x+1, y=pos.y-1, z=pos.z+1},
  1043. {x=pos.x-1, y=pos.y-1, z=pos.z+1},
  1044. {x=pos.x+1, y=pos.y-1, z=pos.z-1},
  1045. {x=pos.x-1, y=pos.y-1, z=pos.z-1},
  1046. -- Directly above.
  1047. {x=pos.x, y=pos.y+1, z=pos.z },
  1048. -- Adjacent sides above.
  1049. {x=pos.x+1, y=pos.y+1, z=pos.z },
  1050. {x=pos.x-1, y=pos.y+1, z=pos.z },
  1051. {x=pos.x, y=pos.y+1, z=pos.z+1},
  1052. {x=pos.x, y=pos.y+1, z=pos.z-1},
  1053. -- Adjacent diagonals above.
  1054. {x=pos.x+1, y=pos.y+1, z=pos.z+1},
  1055. {x=pos.x-1, y=pos.y+1, z=pos.z+1},
  1056. {x=pos.x+1, y=pos.y+1, z=pos.z-1},
  1057. {x=pos.x-1, y=pos.y+1, z=pos.z-1},
  1058. }
  1059. -- This is needed so that the order in which neighbors are checked is random.
  1060. table.shuffle(all_neighbors)
  1061. local neighbors_above = {
  1062. {x=pos.x, y=pos.y+1, z=pos.z},
  1063. }
  1064. local neighbors_below = {
  1065. {x=pos.x, y=pos.y-1, z=pos.z},
  1066. }
  1067. local neighbors_beside_4 = {
  1068. {x=pos.x-1, y=pos.y, z=pos.z },
  1069. {x=pos.x+1, y=pos.y, z=pos.z },
  1070. {x=pos.x, y=pos.y, z=pos.z-1},
  1071. {x=pos.x, y=pos.y, z=pos.z+1},
  1072. }
  1073. table.shuffle(neighbors_beside_4)
  1074. local find_nearby = function(neighbors, names)
  1075. for k, v in ipairs(neighbors) do
  1076. local n2 = minetest.get_node(v)
  1077. if node_has_name_or_group(n2.name, names) then
  1078. return v
  1079. end
  1080. end
  1081. end
  1082. local function do_nodecheck(callback, neighbors, nodenames)
  1083. local p2 = find_nearby(neighbors, nodenames)
  1084. if p2 then
  1085. if type(callback) == "string" then
  1086. if node.name ~= callback then
  1087. node.name = callback
  1088. minetest.add_node(pos, node)
  1089. minetest.check_for_falling(pos)
  1090. return false, true -- Don't wait, done.
  1091. end
  1092. elseif type(callback) == "function" then
  1093. local n2 = minetest.get_node(p2)
  1094. local d2 = minetest.registered_nodes[n2.name]
  1095. if d2 then
  1096. local g2 = d2.groups or {}
  1097. local ret, wait = callback(pos, light_above, p2, n2.name, d2, g2)
  1098. if ret and ret ~= "" then
  1099. if node.name ~= ret then
  1100. node.name = ret
  1101. minetest.add_node(pos, node)
  1102. minetest.check_for_falling(pos)
  1103. return false, true -- Don't wait, done.
  1104. end
  1105. elseif wait then
  1106. return true, false -- Wait, not done.
  1107. end
  1108. end
  1109. end
  1110. end
  1111. end
  1112. local execute_action = function(data)
  1113. -- Action above.
  1114. if data.if_above then
  1115. local wait, done = do_nodecheck(data.if_above, neighbors_above, data.nodenames)
  1116. if wait or done then
  1117. return wait, done
  1118. end
  1119. end
  1120. -- Action below.
  1121. if data.if_below then
  1122. local wait, done = do_nodecheck(data.if_below, neighbors_below, data.nodenames)
  1123. if wait or done then
  1124. return wait, done
  1125. end
  1126. end
  1127. -- Action if adjacent to 1 of 4 sides.
  1128. if data.if_adjacent_side then
  1129. local wait, done = do_nodecheck(data.if_adjacent_side, neighbors_beside_4, data.nodenames)
  1130. if wait or done then
  1131. return wait, done
  1132. end
  1133. end
  1134. -- Action nearby.
  1135. if data.if_nearby then
  1136. local wait, done = do_nodecheck(data.if_nearby, all_neighbors, data.nodenames)
  1137. if wait or done then
  1138. return wait, done
  1139. end
  1140. end
  1141. end
  1142. -- Apply checks in specific order.
  1143. if interaction_data.action_ordering then
  1144. for _, key in ipairs(interaction_data.action_ordering) do
  1145. local data = interaction_data["when_" .. key .. "_near"]
  1146. if data then
  1147. if not (data.require_not_covered and is_covered) then
  1148. local wait, done = execute_action(data)
  1149. if wait then
  1150. return true
  1151. elseif done then
  1152. return
  1153. end
  1154. end
  1155. end
  1156. end
  1157. else
  1158. -- Apply checks in whatever order the keys happen to be stored in.
  1159. for key, data in pairs(interaction_data) do
  1160. if key:find("^when_") and key:find("_near$") then
  1161. if not (data.require_not_covered and is_covered) then
  1162. local wait, done = execute_action(data)
  1163. if wait then
  1164. return true
  1165. elseif done then
  1166. return
  1167. end
  1168. end
  1169. end
  1170. end
  1171. end
  1172. end
  1173. -- Register a common handler for all dirt/soil/permafrost/sand nodes.
  1174. for NODE_NAME, DATA in pairs(INTERACTION_DATA) do
  1175. dirtspread.register_active_block(NODE_NAME, {
  1176. min_time = MIN_TIME,
  1177. max_time = MAX_TIME,
  1178. func = function(...)
  1179. return HANDLER(...)
  1180. end,
  1181. })
  1182. end