client — Client API
Phase: Client (client_scripts/)
The client global is available only in client-side scripts. It provides HUD rendering, keybindings, chat messages, player info, and client↔server networking.
Client scripts reload on F3+T (resource pack reload).
client.sendMessage(text)
Displays a message in the local chat window (not sent to other players).
client.sendMessage("Script loaded!")
client.getPlayer() → table | nil
Returns a table with basic information about the local player, or nil if not in a world.
local p = client.getPlayer()
if p then
client.sendMessage("You are at " .. p.x .. ", " .. p.y .. ", " .. p.z)
end
Returned table fields
| Field | Type | Description |
|---|---|---|
name | string | Player name |
x, y, z | number | Position (also available as pos.x, pos.y, pos.z) |
pos | {x, y, z} | Position table |
mainHandItem | string | Held item identifier |
client.onHudRender(fn)
Registers a function that is called every frame while the HUD is rendered. The callback receives a draw context table e.
client.onHudRender(function(e)
e.drawText("Hello, HUD!", 10, 10, 0xFFFFFF)
end)
HUD context (e) fields and methods
| Member | Type | Description |
|---|---|---|
e.screenWidth | int | Scaled screen width in pixels |
e.screenHeight | int | Scaled screen height in pixels |
e.tickDelta | float | Partial tick progress (0.0–1.0) |
e.drawRect(x, y, w, h, argbColor) | function | Draw a filled rectangle |
e.drawText(text, x, y, rgbColor) | function | Draw text with shadow |
e.drawTextCentered(text, cx, y, rgbColor) | function | Draw centred text |
e.drawOverlay(argbColor) | function | Fill the entire screen with a colour overlay |
Colour format
argbColor—0xAARRGGBB(e.g.0x80FF0000= 50% transparent red)rgbColor—0xRRGGBB(e.g.0xFFFFFF= white)
client.onHudRender(function(e)
-- Semi-transparent dark bar at the top
e.drawRect(0, 0, e.screenWidth, 14, 0x88000000)
-- Centred white text
e.drawTextCentered("Custom HUD", e.screenWidth / 2, 3, 0xFFFFFF)
-- Red health warning overlay
local p = client.getPlayer()
if p then
e.drawText("Pos: " .. math.floor(p.x) .. " " .. math.floor(p.y) .. " " .. math.floor(p.z), 4, 4, 0xFFFF55)
end
end)
client.registerKeybind(id, key, fn)
Registers a keybinding that appears in Minecraft's Controls settings. Calls fn each time the key is pressed.
| Parameter | Type | Description |
|---|---|---|
id | string | Unique bind ID shown in Controls (prefixed with key.) |
key | string | Key name: bare letter ("R"), KEY_R, or GLFW_KEY_R all work |
fn | function | Callback fired on press |
client.registerKeybind("mymod.reload", "R", function()
client.sendMessage("R key pressed!")
client.network.sendToServer("mymod:action", { type = "reload" })
end)
client.registerKeybind("mymod.menu", "KEY_M", function()
client.sendMessage("Opening menu...")
end)
Key bindings can only be registered once with Fabric. On F3+T reload the callback is updated, but the key assignment is preserved.
client.network
Client-side packet API for communicating with the server.
client.network.sendToServer(channel, data)
Sends a packet to the server.
client.network.sendToServer("myplugin:action", { type = "purchase", item = "sword" })
client.network.onReceiveFromServer(channel, fn)
Registers a handler for packets sent from the server on the given channel.
client.network.onReceiveFromServer("myplugin:update", function(data)
client.sendMessage("Server score: " .. data.score)
end)
See the Network API page for the server-side counterpart.