Lifecycle events
These events mark points in the life of the server and the client: the server starting, data packs reloading, each level tick, the command tree being built, a player joining, the client joining and leaving a world, and the F3 screen being drawn. Each loader has its own versions of these events; Stope’s fire at the same points on every loader, so a mod registers once in common code.
At a glance
Section titled “At a glance”| Type | Summary | Status | Since | Side | Thread |
|---|---|---|---|---|---|
ClientDisconnectCallback |
Fired after the client leaves a server or a single-player world, for any reason. | Experimental | 2.0.0 | client | render |
ClientJoinCallback |
Fired when the client has joined a server or a single-player world and can send packets. | Experimental | 2.6.0 | client | render |
CommandRegistrationCallback |
Adds commands to the server’s command tree. | Experimental | 2.0.0 | server | server |
DataPacksReloadedCallback |
Fired after a data-pack reload succeeded and tags are bound again. | Experimental | 2.0.0 | server | server |
DebugScreenLinesCallback |
Adds lines to the F3 debug screen’s right column. | Experimental | 2.0.0 | client | render |
Event |
The listener list behind each callback’s EVENT field, the same on every loader. |
Experimental | 2.0.0 | both | setup |
LevelTickCallback |
Fired at the end of every tick of every server level (each dimension ticks separately). | Experimental | 2.0.0 | server | server |
PlayerJoinedCallback |
Fired once a player has joined the server and can be sent packets. | Experimental | 2.6.0 | server | server |
ServerStartedCallback |
Fired once the server has started: worlds are loaded, data packs applied, and tags bound. | Experimental | 2.0.0 | server | server |
Quick start
Section titled “Quick start”In your mod’s common code:
// A list, so the mod can pick one of the flowers at random.static List<Block> pathsideFlowers = List.of();
static void rebuildFlowers() { pathsideFlowers = RegistryLookups.blockTag(id("pathside_flowers")).orElse(List.of());}
// In your mod's common initializer:ServerStartedCallback.EVENT.register(server -> rebuildFlowers());DataPacksReloadedCallback.EVENT.register(server -> rebuildFlowers());ServerStartedCallback
Section titled “ServerStartedCallback”Experimental · Since 2.0.0 · Side: server · Thread: server
Build or check state that needs loaded worlds or bound tags here, before any player joins.
With LOGGER, the mod’s SLF4J logger, and the flower tag from the quick start:
ServerStartedCallback.EVENT.register(server -> { // Tags are bound by now, so a missing or empty tag means no loaded data pack fills it. if (RegistryLookups.blockTag(id("pathside_flowers")).map(List::isEmpty).orElse(true)) { LOGGER.warn("Block tag {} lists no blocks, so no flowers grow beside paths", id("pathside_flowers")); }});DataPacksReloadedCallback
Section titled “DataPacksReloadedCallback”Experimental · Since 2.0.0 · Side: server · Thread: server
Use it, with ServerStartedCallback, to rebuild what a mod derives from tags or data-pack
files, as the quick start does. It fires the same way on Fabric and Forge: Fabric’s own reload
event also reports failed reloads, and Stope passes on only the successful ones, as Forge does.
DataPacksReloadedCallback.EVENT.register(server -> server.getPlayerList() .broadcastSystemMessage(Component.translatable("chat.mymod.rules_reloaded"), false));LevelTickCallback
Section titled “LevelTickCallback”Experimental · Since 2.0.0 · Side: server · Thread: server
LevelTickCallback.EVENT.register(level -> { // 19 ticks in 20 end here, at no cost. if (level.getGameTime() % 20 != 0) return; for (ServerPlayer player : level.players()) { if (level.getBlockState(player.getOnPos()).is(Blocks.DIRT_PATH)) { // 40 ticks (2 seconds), so the boost lasts until the next check. player.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SPEED, 40, 0, true, false)); } }});CommandRegistrationCallback
Section titled “CommandRegistrationCallback”Experimental · Since 2.0.0 · Side: server · Thread: server
With Settings.FILE, the mod’s
ConfigFile:
CommandRegistrationCallback.EVENT.register((dispatcher, buildContext) -> dispatcher.register( Commands.literal("mymod") .requires(source -> source.hasPermission(2)) .then(Commands.literal("reload").executes(context -> { Settings.FILE.load(); Component done = Component.translatable("commands.mymod.reload"); context.getSource().sendSuccess(() -> done, true); return Command.SINGLE_SUCCESS; }))));PlayerJoinedCallback
Section titled “PlayerJoinedCallback”Experimental · Since 2.6.0 · Side: server · Thread: server
Send a joining player the state it needs before it plays. With NET, SETTINGS, and
ServerSettings from the
NetworkChannel example,
and Settings.FILE, the mod’s
ConfigFile:
PlayerJoinedCallback.EVENT.register( player -> NET.sendToPlayer(player, SETTINGS, ServerSettings.of(Settings.FILE.get())));DebugScreenLinesCallback
Section titled “DebugScreenLinesCallback”Experimental · Since 2.0.0 · Side: client · Thread: render
Lines are plain strings: resolve translations yourself, for example with I18n.get. With
leafColors, the mod’s
Colormap for its leaves:
// Client initialization:DebugScreenLinesCallback.EVENT.register((lines, targetedBlock) -> { if (targetedBlock == null) return; int color = leafColors.color(targetedBlock.getX(), targetedBlock.getZ()); lines.add(""); lines.add(I18n.get("debug.mymod.leaf_color", String.format(Locale.ROOT, "#%06X", color)));});See also
Section titled “See also”- Saved data and reloaders: reload handlers that receive a data pack’s files.
- Movement and block events and mob events.
- Add a config file and settings screen: a guide that adds a reload command step by step.
- Send data from server to client: a guide that sends settings step by step.