Manis Lib Generated Chunk Index
A lightweight library mod that maintains an index of generated Factorio chunks per surface, designed for other mods to query via a remote interface.
This mod has no gameplay content and no UI.
What this mod does
✅ Maintains a generated-chunk index
For each surface, the mod tracks generated chunks using:
- chunk key format:
"cx:cy" - set representation:
chunk_key -> true - array representation:
array<string>for sampling and iteration
A “generated chunk” means:
surface.is_chunk_generated({cx, cy}) == true
✅ Works for both new and existing saves
- Tracks new generation via:
on_chunk_generated-
on_chunk_deleted -
Handles existing saves by enumerating:
surface.get_chunks()- validating with
surface.is_chunk_generated(pos)
✅ Exposes a read-only remote interface
Interface name:
manis_generated_chunk_index
Remote Interface API
All functions take surface_index as the first argument.
1) is_ready(surface_index) -> boolean
Returns whether the index is ready for the given surface.
2) get_surface_status(surface_index) -> table|nil
Returns status information for the surface.
Possible fields:
ready(boolean)scanning(boolean)count(integer)bounds(table|nil)bounds_dirty(boolean)surface_name(string|nil)
May return nil if the surface is unknown.
3) get_generated_chunk_keys(surface_index) -> array<string>
Primary API for callers.
Returns an array of chunk keys in "cx:cy" format.
Intended for:
- uniform sampling
- iteration
- derived structure building
4) has_chunk(surface_index, cx, cy) -> boolean
Returns whether the specific chunk exists in the index.
Intended for:
- point membership queries
- validation loops
- adjacency checks
5) get_generated_chunk_set(surface_index) -> table|nil
Returns the internal set representation:
chunk_key -> true
Intended for:
- debugging
- special or advanced use cases
Caller must treat the returned table as read-only.
6) get_bounds(surface_index) -> table|nil
Returns best-effort bounds:
{ min_cx, max_cx, min_cy, max_cy }
Provided as a convenience.
Caller must not treat bounds as authoritative truth.
Recommended Call Patterns
Pattern A — Gate heavy logic with is_ready
Use when your mod depends on a complete index.
```lua
local iface = "manis_generated_chunk_index"
if not (remote.interfaces and remote.interfaces[iface]) then return end
local surface_index = game.surfaces["nauvis"].index
if not remote.call(iface, "is_ready", surface_index) then
return
end
-- safe to use index
Pattern B — Prefer has_chunk for point checks
If you only need a few coordinates, avoid pulling full data.
if remote.call(iface, "has_chunk", surface_index, cx, cy) then
-- generated
end
Pattern C — Use get_generated_chunk_keys for sampling
If you need random generated chunks:
local keys = remote.call(iface, "get_generated_chunk_keys", surface_index)
if keys and #keys > 0 then
local key = keys[math.random(#keys)]
end
Pattern D — Avoid frequent full-set pulls
get_generated_chunk_set(surface_index) may return a large table.
Best practice:
- Call it rarely
- Do not call every tick
- Convert to your own compact structure if needed
Data Guarantees
- The mod maintains an index of generated chunks per surface.
- The remote interface is read-only.
- Chunk keys are stable in "cx:cy" string format.
Non-Guarantees
- Ordering of chunks is not guaranteed.
- Bounds are best-effort derived data.
- No per-tick change stream is provided.
Compatibility
- Library mod (no entities, no UI).
- Designed for Factorio 2.0 runtime.
- Caller mods must treat returned data as read-only.