Minecraft text rendering inside the browser!
Find a file
Perny 91aee51dfe chore: stricten tests
chore: stria
2026-04-22 20:44:18 +03:00
devserver push 2026-04-19 20:55:48 +03:00
headers yes 2026-04-19 21:20:28 +03:00
scripts yes 2026-04-19 21:20:28 +03:00
src feat: align text horizontally 2026-04-22 09:43:24 +03:00
tests chore: stricten tests 2026-04-22 20:44:18 +03:00
.gitignore work from yesturday 2026-04-20 13:57:13 +03:00
AGENTS.md yes 2026-04-19 20:35:10 +03:00
bun.lock yes 2026-04-19 20:35:10 +03:00
LICENSE.md add license 2026-04-19 21:26:34 +03:00
logo.png yes 2026-04-19 20:57:47 +03:00
package.json feat: align text horizontally 2026-04-22 09:43:24 +03:00
README.md feat: align text horizontally 2026-04-22 09:43:24 +03:00
tsconfig.build.json work from yesturday 2026-04-20 13:57:13 +03:00
tsconfig.json yes 2026-04-19 20:35:10 +03:00

Libmojangles

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.

Features
  • 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
Installation
bun add libmojangles
# or
npm install libmojangles
Quick Start
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:

lib.drawText("Centered title", canvas.width / 2, 20, {
  scale: 2,
  anchorX: "center",
});
Text Components

Libmojangles supports Minecraft's JSON text component format:

lib.drawText(
  {
    extra: [{ text: "Hello " }, { text: "World!", color: "gold", bold: true }],
  },
  10,
  10,
);

shadow_color is also supported for JSON components. It uses a decimal ARGB integer value.

lib.drawText(
  {
    text: "Custom Shadow",
    color: "white",
    shadow_color: -2130771713,
  },
  10,
  30,
);

Supported properties: text, extra, color, shadow_color, bold, italic, underlined, strikethrough, obfuscated, font

API Overview

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
Development
# Install dependencies
bun install

# Run dev server with playground
bun run dev

# Run tests
bun test
Resource Packs

You need Minecraft's vanilla assets or a compatible resource pack. The library expects the standard Minecraft resource pack structure: