Lifecycle Events
Register Nows loader lifecycle listeners and understand how they fit with GEB integration.
Lifecycle Events
integrations/geb registers a GEB instance in NowsServices. Mods that want it can use the small Nows facade:
NowsEvents events = GebIntegration.events(context);
events.post(new MyCustomEvent());
Mods can declare no-argument listener classes in nows.mod.kdl with listener "com.example.Listener". Nows registers those listeners before entrypoints run.
Listeners are discovered from metadata declarations, instantiated by the loader, and registered with the integration event bus before mod entrypoints execute. That makes lifecycle listeners useful for infrastructure that should observe more than one mod, while entrypoints remain the right place for normal mod setup.
For Nows-owned loader lifecycle events, implement NowsLifecycleListener:
public final class MyLifecycleListener implements NowsLifecycleListener {
@Override
public void onNowsEntrypointsCompleted(NowsEntrypointsCompletedEvent event) {
int loadedEntrypoints = event.count();
}
}
Lifecycle events include NowsBootstrapReadyEvent, NowsEntrypointsStartingEvent, NowsModEntrypointStartingEvent, NowsModEntrypointCompletedEvent, NowsEntrypointsCompletedEvent and NowsMinecraftStartingEvent.
Typical Ordering
The public event names describe the intended flow:
| Event | What it means |
|---|---|
NowsBootstrapReadyEvent |
loader services and integrations are ready enough for bootstrap observers |
NowsEntrypointsStartingEvent |
entrypoint execution for the resolved mod set is about to begin |
NowsModEntrypointStartingEvent |
one mod entrypoint is about to run |
NowsModEntrypointCompletedEvent |
one mod entrypoint has completed |
NowsEntrypointsCompletedEvent |
all discovered entrypoints have completed |
NowsMinecraftStartingEvent |
the launcher is handing control toward Minecraft startup |
Keep listener constructors lightweight. Expensive work should happen inside an event method or entrypoint so failures are easier to attribute to the mod phase that caused them.
Entrypoint Or Listener
Use an entrypoint when your mod is setting up its own content, registering channels, creating managers or touching Minecraft APIs through MinecraftApi.
Use a listener when you want a reusable observer around loader phases, such as logging, diagnostics, event forwarding, or a shared integration that must know when other entrypoints start and finish.
A mod that does not care about GEB can still compile against nows-core without pulling GEB into its API.