Skip to main content
Version: Minecraft 26.2

Client basics

You use the client API through mod.client() in the client entrypoint (ClientModInitializer). Calling it on a dedicated server gives POLY-CLIENT-001.

ClientRegistrar client = mod.client();
KeyBinding open = client.keyBinding("open", KeyCodes.K);
client.hudLayer("status", canvas -> canvas.drawText("Hi", 4, 4, 0xFFFFFFFF));
mod.events().register(ClientEvents.TICK, view -> {
if (open.consumeClick()) {
view.showActionBar("Open!");
}
});

Key bindings​

Declare one with keyBinding(path, KeyCodes.K).

  • It appears in the controls settings, and the player can rebind it.
  • The name is key.<mod>.<path> in the lang file, and the category name is key.category.<mod>.keybinds.
  • consumeClick() consumes the number of presses one at a time. isDown() tells whether the key is held down now.
  • KeyCodes has letter keys, F6–F10, UNBOUND, and others.
  • If adding fails, you get POLY-CLIENT-004.

HUD layers​

hudLayer(path, canvas -> …) is called on the render thread every frame.

HudCanvasMeaning
width(), height()Screen size (GUI coordinates)
textWidth(text)Text width
drawText(text, x, y, argb)Text
fill(x1, y1, x2, y2, argb)Rectangle
drawTexture(texture, x, y, width, height)Texture (for example, a dynamic texture)
client.hudLayer("status", canvas -> {
String text = "Native Showcase";
canvas.fill(2, 2, 6 + canvas.textWidth(text), 14, 0x80000000);
canvas.drawText(text, 4, 4, 0xFFFFD54F);
});

If an exception occurs, Poly Mod Loader turns off only that layer and logs POLY-CLIENT-003. It is called every frame, so keep it light.

ClientView​

Client events (TICK, JOINED_WORLD, LEFT_WORLD) give you a ClientView.

MethodMeaning
player(), world()The current player and world (Optional, empty outside a world)
showActionBar(text)Action bar message
openScreen(screen), closeScreen(), isScreenOpen()Mod screens
cameraPerspective(), setCameraPerspective(p)Camera perspective
setPostEffect(id), clearPostEffect(), postEffect()Post-processing shader
leaveWorld()Same as "Save and Quit to Title"
mod.events().register(ClientEvents.JOINED_WORLD, view -> LOGGER.info("joined")); // LEFT_WORLD exists too

The list of client events is in Events.

Error codes​

CodeMeaning
POLY-CLIENT-001Client API used on a server
POLY-CLIENT-002Client ID error or registration closed
POLY-CLIENT-003HUD layer or drawing failed (only that layer is turned off)
POLY-CLIENT-004Adding a key binding failed
POLY-CLIENT-005A dynamic texture was uploaded from a thread other than the client thread, or particle or post-processing hookup failed
POLY-CLIENT-006A mod shader pipeline could not be created or compiled (logged once, that rectangle is skipped)
POLY-CLIENT-007A mod shader uniform value threw an exception or has the wrong count, or the upload failed (logged once, the last valid value is used)
Buy me a coffee