A zero-dependencies TypeScript library that recreates Minecraft's font rendering stack for the web, pixel-perfect.
> **Note:** This project has been mostly developed by LLMs, but tested heavily against the game.
- **Resource Pack Support** — Load Minecraft resource packs to use custom fonts, textures, and font definitions
- **Shader Pipeline** — Uses Minecraft's core shaders (vertex + fragment); supports custom shaders via resource packs
- **Text Component Parsing** — Full support for Minecraft JSON text components with colors, formatting, and nested extras
- **Component Bounding Boxes** — Get precise bounding boxes for each text component, useful for hit detection and tooltips
- **WebGL2 Rendering** — Hardware-accelerated text rendering with proper Unicode and bitmap font support
```bash
bun add libmojangles
# or
npm install libmojangles
```
```typescript
import { createLibmojangles, ResourcePackZIP } from "libmojangles";
const canvas = document.getElementById("canvas") as HTMLCanvasElement;
const lib = createLibmojangles({ canvas });
// Load a resource pack from a zip file (e.g., Minecraft's assets or a custom pack)
const zipData = await fetch("/path/to/resourcepack.zip").then((r) =>
r.arrayBuffer(),
);
const pack = await ResourcePackZIP.fromZip(zipData, "vanilla");
lib.addResourcePack(pack);
await lib.loadFont({ namespace: "minecraft", path: "default" });
lib.renderer.beginFrame();
lib.drawText("Hello World!", 10, 10, { scale: 2 });
lib.renderer.endFrame();
```
You can anchor text horizontally at draw time:
```typescript
lib.drawText("Centered title", canvas.width / 2, 20, {
scale: 2,
anchorX: "center",
});
```
Libmojangles supports Minecraft's JSON text component format:
```typescript
lib.drawText(
{
extra: [{ text: "Hello " }, { text: "World!", color: "gold", bold: true }],
},
10,
10,
);
```
### Per-Component Custom Uniforms
For convenience, you can pass custom shader uniforms to specific components by ID.
```typescript
lib.drawText(
{
extra: [
{ id: "warning", text: "WARNING: " },
{ id: "message", text: "System overheating!" },
],
},
10,
10,
{
uniforms: {
warning: { TintColor: [1, 0, 0] },
message: { TintColor: [1, 1, 0] },
},
},
);
```
### `createLibmojangles(options)`
Creates a new Libmojangles instance.
| Option | Type | Description |
| ------------- | ------------------- | --------------------------------- |
| `canvas` | `HTMLCanvasElement` | Required. The canvas to render to |
| `defaultFont` | `ResourceLocation` | Optional. Default font to use |
### Instance Methods
| Method | Description |
| -------------------------------- | --------------------------------------------------------------------------------- |
| `addResourcePack(pack)` | Add a resource pack for fonts/textures/shaders |
| `removeResourcePack(pack)` | Remove a resource pack |
| `loadFont(id)` | Load a font by resource location |
| `drawText(text, x, y, options?)` | Draw text; returns `{ components }` with bounding boxes when `cachePicking: true` |
| `createTextMesh(text, options?)` | Create vertex data without rendering |
| `pick(x, y)` | Get glyph info at screen position |
| `resize(width, height)` | Resize the renderer |
| `dispose()` | Clean up resources |
```bash
# Install dependencies
bun install
# Run dev server with playground
bun run dev
# Run tests
bun test
```
You need Minecraft's vanilla assets or a compatible resource pack. The library expects the standard Minecraft resource pack structure:
Libmojangles was built by the Hudkit team to power Minecraft text rendering in [Hudkit Studio](https://studio.hudkit.net), where it runs in production today.
Libmojangles is licensed under the **GNU Lesser General Public License v3.0 or later** (LGPL-3.0-or-later).
This means you can:
- Use this library in proprietary applications without open-sourcing your entire project
- Link to or import libmojangles as a dependency in any project (commercial or otherwise)
- Modify the library for your own use
If you distribute a modified version of libmojangles itself, you must:
- Release your modifications under LGPL-3.0 or later
- Provide access to the modified source code
See [LICENSE.md](LICENSE.md) for the full license text.
Copyright (C) 2026 Perny / Hudkit