abm.lua 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. ---@meta
  2. ---ABM (ActiveBlockModifier) definition
  3. ---------------------------------------
  4. ---Used by `minetest.register_abm`.
  5. ---@class mt.ABMDef
  6. -- Descriptive label for profiling purposes (optional).
  7. -- Definitions with identical labels will be listed as one.
  8. ---@field label string|nil
  9. -- Apply `action` function to these nodes.
  10. -- `group:groupname` can also be used here.
  11. ---@field nodenames string|string[]
  12. -- Only apply `action` to nodes that have one of, or any
  13. -- combination of, these neighbors.
  14. -- If left out or empty, any neighbor will do.
  15. -- `group:groupname` can also be used here.
  16. ---@field neighbors string|string[]
  17. ---@field interval number Operation interval in seconds.
  18. -- Chance of triggering `action` per-node per-interval is 1.0 / this value
  19. ---@field chance number
  20. -- Min height level where ABM will be processed can be used to reduce CPU usage.
  21. ---@field min_y number
  22. -- Max height level where ABM will be processed can be used to reduce CPU usage.
  23. ---@field max_y number
  24. -- If true, catch-up behavior is enabled: The `chance` value is
  25. -- temporarily reduced when returning to an area to simulate time lost
  26. -- by the area being unattended. Note that the `chance` value can often
  27. -- be reduced to 1.
  28. ---@field catch_up boolean
  29. local abm = {}
  30. -- Function triggered for each qualifying node.
  31. --
  32. -- If any neighboring mapblocks are unloaded an estmate is calculated for them
  33. -- based on loaded mapblocks.
  34. ---@param pos mt.Vector
  35. ---@param node mt.Node
  36. ---@param active_object_count number Active objects in the node's mapblock.
  37. ---@param active_object_count_wider number Plus all 26 neighboring mapblocks.
  38. function abm.action(pos, node, active_object_count, active_object_count_wider) end