Skip to content

Custom Fonts

SpiDrone edited this page Jul 22, 2026 · 1 revision

Adding Fonts

Adding a custom font for use with drawCustomFont() is uber simple.

1. Register the font

Drop your .ttf into assets/<modid>/font/, and put a .json definition right next to it in the same folder:

assets/spis_ui_api/font/boldpixels.ttf
assets/spis_ui_api/font/boldpixels.json
{
  "providers": [
    {
      "type": "ttf",
      "file": "spis_ui_api:boldpixels.ttf",
      "shift": [0.0, 0.0],
      "size": 16.0,
      "oversample": 2.0
    }
  ]
}

A few notes on the fields:

  • file is relative to the font folder itself, not your namespace root — so it's just modid:filename.ttf, not modid:font/filename.ttf.
  • size controls the internal glyph resolution Minecraft renders at, not the final size on screen.
  • oversample sharpens the glyphs at small sizes. 2.0 is a safe default; bump it higher if the font looks blurry in-game.

That's the entire registration step.
Minecraft scans every font/*.json on resource reload, no extra setup needed.

2. Reference it in code

The font's ID is just its namespace plus filename:

public static final ResourceLocation BOLD_PIXELS_FONT =
    ResourceLocation.fromNamespaceAndPath("spis_ui_api", "boldpixels");

Pass that into any drawCustomFont call and you're done:

UIGraphicsHelper.drawCustomFont(graphics, BOLD_PIXELS_FONT, "Hello!", x, y, 0xFFFFFFFF, false);

Troubleshooting

If your text renders as empty boxes (tofu), check the following.

  1. Is the .json actually inside a folder named font? Not fonts, not anything else. Minecraft only scans that exact folder name.
  2. Does the file path in the json match the real filename, casing included? BoldPixels.ttf and boldpixels.ttf are not the same file on a case-sensitive lookup.

Clone this wiki locally