Client events
These events mark points in the life of the client: joining and leaving a world, each client tick, and the F3 screen being drawn. Each loader has its own versions of them; Stope’s fire at the same points on every loader, so a mod registers once in its client 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 |
ClientTickCallback |
Fired at the end of every client tick, in a world or not. | Experimental | 2.11.0 | client | render |
DebugScreenLinesCallback |
Adds lines to the F3 debug screen’s right column. | Experimental | 2.0.0 | client | render |
Quick start
Section titled “Quick start”Poll a key mapping each client tick to act on a key pressed in game. With
cycleKey, a MappedKey
registered with KeyContext.ANYWHERE, wasHeld, a boolean field, and cycleRuleSet, the
mod’s own method, in client initialization:
ClientTickCallback.EVENT.register(() -> { boolean pressed = false; // Take every press counted since the last tick, a held key's repeats among them. while (cycleKey.consumeClick()) pressed = true; // A press that comes while the key was already down is a repeat. if (pressed && !wasHeld) cycleRuleSet(); wasHeld = cycleKey.isHeld();});ClientTickCallback
Section titled “ClientTickCallback”Experimental · Since 2.11.0 · Side: client · Thread: render
ClientTickCallback runs a mod’s client code once a tick, such as polling a key, as the
quick start does.
- A key that also works on container screens has a
ContainerKeyCallbacklistener for those.
DebugScreenLinesCallback
Section titled “DebugScreenLinesCallback”Experimental · Since 2.0.0 · Side: client · Thread: render
DebugScreenLinesCallback adds a mod’s own lines to the F3 screen. Lines are plain strings: resolve translations yourself, for example with I18n.get. In
client initialization, with leafColors, the mod’s
Colormap for
its leaves:
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”- Container screens and keys: registering a key and reading it on a container screen.
- Server lifecycle events: the server starting, a player spawning and joining, and each level tick.
- Item events: the client events for a held stack used up or replaced, a tool or armor piece worn, and an item gained.