api.lua 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. -- LUALOCALS < ---------------------------------------------------------
  2. local math, minetest, nodecore
  3. = math, minetest, nodecore
  4. local math_floor, math_pow
  5. = math.floor, math.pow
  6. -- LUALOCALS > ---------------------------------------------------------
  7. local modname = minetest.get_current_modname()
  8. nodecore.hard_stone_strata = 7
  9. function nodecore.hard_stone_tile(n)
  10. local o = math_floor(math_pow(n, 0.75) * 59)
  11. if o <= 0 then
  12. return modname .. "_stone.png"
  13. end
  14. if o >= 255 then
  15. return modname .. "_stone.png^"
  16. .. modname .. "_stone_hard.png"
  17. end
  18. return modname .. "_stone.png^("
  19. .. modname .. "_stone_hard.png^[opacity:"
  20. .. o .. ")"
  21. end
  22. function nodecore.register_dirt_leaching(fromnode, tonode, rate)
  23. local function waterat(pos, dx, dy, dz)
  24. pos = {x = pos.x + dx, y = pos.y + dy, z = pos.z + dz}
  25. local node = minetest.get_node(pos)
  26. return minetest.get_item_group(node.name, "water") ~= 0
  27. end
  28. nodecore.register_soaking_abm({
  29. label = fromnode .. " leaching to " .. tonode,
  30. fieldname = "leach",
  31. nodenames = {fromnode},
  32. neighbors = {"group:water"},
  33. interval = 5,
  34. chance = 1,
  35. soakrate = function(pos)
  36. if not waterat(pos, 0, 1, 0) then return false end
  37. local qty = 1
  38. if waterat(pos, 1, 0, 0) then qty = qty * 1.5 end
  39. if waterat(pos, -1, 0, 0) then qty = qty * 1.5 end
  40. if waterat(pos, 0, 0, 1) then qty = qty * 1.5 end
  41. if waterat(pos, 0, 0, -1) then qty = qty * 1.5 end
  42. if waterat(pos, 0, -1, 0) then qty = qty * 1.5 end
  43. return qty * (rate or 1)
  44. end,
  45. soakcheck = function(data, pos)
  46. if data.total < 5000 then return end
  47. nodecore.witness(pos, "leach " .. fromnode)
  48. nodecore.set_loud(pos, {name = tonode})
  49. return nodecore.fallcheck(pos)
  50. end
  51. })
  52. end