Skip to content

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.

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

In your mod’s common code:

Rebuild a list of tagged blocks whenever data packs load
// 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());

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:

Warn at server start when the flower tag lists no blocks
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"));
}
});

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.

Tell players that the mod's rules reloaded
DataPacksReloadedCallback.EVENT.register(server -> server.getPlayerList()
.broadcastSystemMessage(Component.translatable("chat.mymod.rules_reloaded"), false));

Experimental · Since 2.0.0 · Side: server · Thread: server

Speed up players on paths, checked once a second
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));
}
}
});

Experimental · Since 2.0.0 · Side: server · Thread: server

With Settings.FILE, the mod’s ConfigFile:

Add a command that reloads the settings file
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;
}))));

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:

Send the server's settings to each player who joins
PlayerJoinedCallback.EVENT.register(
player -> NET.sendToPlayer(player, SETTINGS, ServerSettings.of(Settings.FILE.get())));

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:

Show the leaf color at the targeted block in F3
// 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)));
});