wet.lua 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. -- LUALOCALS < ---------------------------------------------------------
  2. local math, minetest, nodecore
  3. = math, minetest, nodecore
  4. local math_random
  5. = math.random
  6. -- LUALOCALS > ---------------------------------------------------------
  7. local function concdef(name)
  8. local def = minetest.registered_items[name]
  9. return def and def.concrete_def
  10. end
  11. local function wetname(name)
  12. local def = concdef(name)
  13. def = def and def.basename
  14. return def and (def .. "_wet_source")
  15. end
  16. nodecore.register_limited_abm({
  17. label = "concrete wet",
  18. interval = 1,
  19. chance = 2,
  20. limited_max = 100,
  21. nodenames = {"group:concrete_powder"},
  22. neighbors = {"group:water"},
  23. action = function(pos, node)
  24. local wet = wetname(node.name)
  25. if wet then return nodecore.set_loud(pos, {name = wet}) end
  26. end
  27. })
  28. nodecore.register_aism({
  29. label = "concrete stack wet",
  30. interval = 1,
  31. chance = 2,
  32. itemnames = {"group:concrete_powder"},
  33. action = function(stack, data)
  34. local wet = wetname(stack:get_name())
  35. if not wet then return end
  36. local found = minetest.find_node_near(data.pos, 1, {"group:water"})
  37. if not found then return end
  38. if stack:get_count() == 1 and data.node then
  39. local ndef = minetest.registered_nodes[
  40. data.node.name]
  41. if ndef and ndef.groups and ndef.groups.is_stack_only then
  42. found = data.pos
  43. end
  44. end
  45. nodecore.set_loud(found, {name = wet})
  46. stack:take_item(1)
  47. return stack
  48. end
  49. })
  50. nodecore.register_limited_abm({
  51. label = "concrete wander",
  52. interval = 4,
  53. chance = 2,
  54. limited_max = 100,
  55. nodenames = {"group:concrete_source"},
  56. neighbors = {"group:concrete_flow"},
  57. action = function(pos, node)
  58. local def = concdef(node.name)
  59. local meta = minetest.get_meta(pos)
  60. local gen = meta:get_int("agggen")
  61. if gen >= 8 and math_random(1, 2) == 1 then
  62. nodecore.witness({
  63. x = pos.x,
  64. y = pos.y + 0.5,
  65. z = pos.z
  66. },
  67. def.name .. " to " .. def.to_crude)
  68. return nodecore.set_loud(pos, {name = def.to_crude})
  69. end
  70. local miny = pos.y
  71. local found = {}
  72. nodecore.scan_flood(pos, 2, function(p)
  73. local nn = minetest.get_node(p).name
  74. if nn == node.name then return end
  75. if minetest.get_item_group(nn, "concrete_flow") < 1
  76. then return false end
  77. if p.y > miny then return end
  78. if p.y == miny then
  79. found[#found + 1] = p
  80. return
  81. end
  82. miny = p.y
  83. found = {p}
  84. end)
  85. if #found < 1 then return end
  86. local np = nodecore.pickrand(found)
  87. nodecore.set_loud(np, node)
  88. minetest.get_meta(np):set_int("agggen", gen + 1)
  89. local flow = minetest.registered_items[node.name].liquid_alternative_flowing
  90. minetest.set_node(pos, {name = flow, param2 = 7})
  91. end
  92. })
  93. nodecore.register_limited_abm({
  94. label = "concrete sink/disperse",
  95. interval = 4,
  96. chance = 2,
  97. limited_max = 100,
  98. nodenames = {"group:concrete_source"},
  99. neighbors = {"group:water"},
  100. action = function(pos, node)
  101. local def = concdef(node.name)
  102. local waters = #nodecore.find_nodes_around(pos, "group:water") - 3
  103. local rnd = math_random() * 20
  104. if rnd * rnd < waters then
  105. nodecore.set_loud(pos, {name = def.to_washed})
  106. return nodecore.fallcheck(pos)
  107. end
  108. local below = {x = pos.x, y = pos.y - 1, z = pos.z}
  109. local bname = minetest.get_node(below).name
  110. if bname == "ignore" then return end
  111. if minetest.get_item_group(bname, "water") > 0 then
  112. nodecore.set_loud(below, node)
  113. nodecore.remove_node(pos)
  114. return
  115. end
  116. end
  117. })
  118. nodecore.register_soaking_abm({
  119. label = "wet concrete cure",
  120. interval = 5,
  121. chance = 2,
  122. limited_max = 100,
  123. nodenames = {"group:concrete_source"},
  124. fieldname = "curing",
  125. soakrate = function(pos)
  126. if minetest.find_node_near(pos,
  127. 1, {"group:concrete_flow", "group:water"}) then
  128. return false
  129. end
  130. local found = nodecore.find_nodes_around(pos, "group:igniter", 1)
  131. return #found + 1
  132. end,
  133. soakcheck = function(data, pos, node)
  134. if data.total < 40 then
  135. nodecore.smokefx(pos, 5, data.rate)
  136. return
  137. end
  138. local def = concdef(node.name)
  139. nodecore.set_loud(pos, {name = def.to_molded})
  140. return false
  141. end
  142. })