api.lua 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. -- LUALOCALS < ---------------------------------------------------------
  2. local math, minetest, nodecore, pairs, vector
  3. = math, minetest, nodecore, pairs, vector
  4. local math_ceil, math_pow
  5. = math.ceil, math.pow
  6. -- LUALOCALS > ---------------------------------------------------------
  7. local modname = minetest.get_current_modname()
  8. local function isfluid(pos)
  9. local def = minetest.registered_nodes[minetest.get_node(pos).name]
  10. return def and def.groups and def.groups.lux_fluid
  11. end
  12. local indirs = {}
  13. for _, v in pairs(nodecore.dirs()) do
  14. if v.y == 0 then
  15. indirs[#indirs + 1] = v
  16. end
  17. end
  18. function nodecore.lux_soak_rate(pos)
  19. local above = vector.add(pos, {x = 0, y = 1, z = 0})
  20. if not isfluid(above) then return false end
  21. local qty = 1
  22. for _, v in pairs(indirs) do
  23. if isfluid(vector.add(pos, v)) then qty = qty + 1 end
  24. end
  25. local dist = nodecore.scan_flood(above, 14, function(p, d)
  26. if p.dir and p.dir.y < 0 then return false end
  27. local nn = minetest.get_node(p).name
  28. if nn == modname .. ":flux_source" then return d end
  29. if nn ~= modname .. ":flux_flowing" then return false end
  30. end)
  31. if not dist then return false end
  32. return qty * 20 / math_pow(2, dist / 2)
  33. end
  34. local function is_lux_cobble(stack)
  35. return (not stack:is_empty()) and minetest.get_item_group(stack:get_name(), "lux_cobble") > 0
  36. end
  37. function nodecore.lux_react_qty(pos, adjust)
  38. local minp = vector.subtract(pos, {x = 1, y = 1, z = 1})
  39. local maxp = vector.add(pos, {x = 1, y = 1, z = 1})
  40. local qty = #minetest.find_nodes_in_area(minp, maxp, {"group:lux_cobble"})
  41. if adjust then qty = qty + adjust end
  42. for _, p in pairs(minetest.find_nodes_with_meta(minp, maxp)) do
  43. if is_lux_cobble(nodecore.stack_get(p)) then
  44. qty = qty + 1
  45. end
  46. end
  47. for _, p in pairs(minetest.get_connected_players()) do
  48. if vector.distance(pos, vector.add(p:get_pos(), {x = 0, y = 1, z = 0})) < 2 then
  49. local inv = p:get_inventory()
  50. for i = 1, inv:get_size("main") do
  51. if is_lux_cobble(inv:get_stack("main", i)) then
  52. qty = qty + 1
  53. end
  54. end
  55. end
  56. end
  57. qty = math_ceil(qty / 2)
  58. if qty > 8 then qty = 8 end
  59. if qty < 1 then qty = 1 end
  60. return qty
  61. end