Skip to content

How to draw text on the screen in a Minecraft mod

The HUD is drawn every frame. Fabric API’s HudRenderCallback.EVENT runs after the vanilla HUD (HudElementRegistry from 26.1). NeoForge 1.20.5 and newer registers a named GUI layer in RegisterGuiLayersEvent, above or below the vanilla layers; Forge and older NeoForge register a GUI overlay (RegisterGuiOverlaysEvent), and on 1.16.5 and 1.12.2 you listen to RenderGameOverlayEvent.Post. On 1.20 and newer you draw text at screen coordinates with guiGraphics.drawString(font, text, x, y, colour); older versions draw with the font renderer.

Works on Minecraft 1.20.1 to 26.3 on NeoForge; Minecraft 1.16.5 to 26.3 on Fabric; Minecraft 1.16.5 to 1.20.1 on Forge; Minecraft 1.12.2 on Forge. Each example was compiled against its loader and version before it shipped in Linen.

  1. Register a HUD callback (Fabric), a GUI layer or overlay (NeoForge and Forge) or an overlay event (1.16.5 and 1.12.2) in the client.
  2. In it, draw the text.
  3. Keep it fast: it runs every frame.

The example uses these values. Change them in the code.

Setting In the example What it does
text Hello from my mod The text it draws.
colour 16777215 Its colour as an RGB number (16777215 is white).

The example mod is examplemod in the package com.example.examplemod. Use your own mod id and package.

Fabric 1.20 to 1.21.1, Fabric 1.21.2 to 1.21.11

Section titled “Fabric 1.20 to 1.21.1, Fabric 1.21.2 to 1.21.11”

Uses:

  • HudRenderCallback.EVENT
  • GuiGraphics.drawString
  • Minecraft.font

src/main/java/com/example/examplemod/client/StatusHud.java

package com.example.examplemod.client;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.Minecraft;
// Text drawn on the HUD every frame, after the vanilla HUD (Fabric API: HudRenderCallback).
public final class StatusHud {
private StatusHud() {
}
// Called from the mod's client entrypoint.
public static void register() {
HudRenderCallback.EVENT.register((guiGraphics, deltaTracker) -> guiGraphics.drawString(Minecraft.getInstance().font, "Hello from my mod", 10, 10, 16777215));
}
}

In your client setup class, inside onInitializeClient:

StatusHud.register();

NeoForge 1.21 to 1.21.1, NeoForge 1.21.2 to 1.21.8

Section titled “NeoForge 1.21 to 1.21.1, NeoForge 1.21.2 to 1.21.8”

Uses:

  • RegisterGuiLayersEvent.registerAboveAll
  • LayeredDraw.Layer
  • GuiGraphics.drawString

src/main/java/com/example/examplemod/client/StatusHud.java

package com.example.examplemod.client;
import com.example.examplemod.ExampleMod;
import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.client.event.RegisterGuiLayersEvent;
// Text drawn on the HUD every frame, in a GUI layer above the vanilla ones (NeoForge: RegisterGuiLayersEvent).
public final class StatusHud {
private StatusHud() {
}
// Called from the mod's constructor, in the client only.
public static void register(IEventBus modBus) {
modBus.addListener(StatusHud::registerLayers);
}
private static void registerLayers(RegisterGuiLayersEvent event) {
event.registerAboveAll(ResourceLocation.fromNamespaceAndPath(ExampleMod.MOD_ID, "status"),
(guiGraphics, deltaTracker) -> guiGraphics.drawString(Minecraft.getInstance().font, "Hello from my mod", 10, 10, 16777215));
}
}

In your main mod class, inside <init>:

if (FMLEnvironment.dist == Dist.CLIENT) {
StatusHud.register(modEventBus);
}

Uses:

  • RegisterGuiLayersEvent.registerAboveAll
  • LayeredDraw.Layer
  • GuiGraphics.drawString

src/main/java/com/example/examplemod/client/StatusHud.java

package com.example.examplemod.client;
import com.example.examplemod.ExampleMod;
import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.client.event.RegisterGuiLayersEvent;
// Text drawn on the HUD every frame, in a GUI layer above the vanilla ones (NeoForge: RegisterGuiLayersEvent).
public final class StatusHud {
private StatusHud() {
}
// Called from the mod's constructor, in the client only.
public static void register(IEventBus modBus) {
modBus.addListener(StatusHud::registerLayers);
}
private static void registerLayers(RegisterGuiLayersEvent event) {
event.registerAboveAll(new ResourceLocation(ExampleMod.MOD_ID, "status"),
(guiGraphics, deltaTracker) -> guiGraphics.drawString(Minecraft.getInstance().font, "Hello from my mod", 10, 10, 16777215));
}
}

In your main mod class, inside <init>:

if (FMLEnvironment.dist == Dist.CLIENT) {
StatusHud.register(modEventBus);
}

Uses:

  • RegisterGuiOverlaysEvent.registerAboveAll
  • IGuiOverlay
  • GuiGraphics.drawString

src/main/java/com/example/examplemod/client/StatusHud.java

package com.example.examplemod.client;
import net.minecraft.client.Minecraft;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.client.event.RegisterGuiOverlaysEvent;
// Text drawn on the HUD every frame, in a GUI overlay above the vanilla ones (NeoForge: RegisterGuiOverlaysEvent).
public final class StatusHud {
private StatusHud() {
}
// Called from the mod's constructor, in the client only.
public static void register(IEventBus modBus) {
modBus.addListener(StatusHud::registerOverlays);
}
private static void registerOverlays(RegisterGuiOverlaysEvent event) {
event.registerAboveAll("status",
(gui, guiGraphics, partialTick, width, height) -> guiGraphics.drawString(Minecraft.getInstance().font, "Hello from my mod", 10, 10, 16777215));
}
}

In your main mod class, inside <init>:

if (FMLEnvironment.dist == Dist.CLIENT) {
StatusHud.register(modEventBus);
}

Uses:

  • RegisterGuiLayersEvent.registerAboveAll
  • LayeredDraw.Layer
  • GuiGraphics.drawString

src/main/java/com/example/examplemod/client/StatusHud.java

package com.example.examplemod.client;
import com.example.examplemod.ExampleMod;
import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.client.event.RegisterGuiLayersEvent;
// Text drawn on the HUD every frame, in a GUI layer above the vanilla ones (NeoForge: RegisterGuiLayersEvent).
public final class StatusHud {
private StatusHud() {
}
// Called from the mod's constructor, in the client only.
public static void register(IEventBus modBus) {
modBus.addListener(StatusHud::registerLayers);
}
private static void registerLayers(RegisterGuiLayersEvent event) {
event.registerAboveAll(ResourceLocation.fromNamespaceAndPath(ExampleMod.MOD_ID, "status"),
(guiGraphics, deltaTracker) -> guiGraphics.drawString(Minecraft.getInstance().font, "Hello from my mod", 10, 10, 16777215));
}
}

In your main mod class, inside <init>:

if (FMLEnvironment.getDist() == Dist.CLIENT) {
StatusHud.register(modEventBus);
}

Uses:

  • RegisterGuiLayersEvent.registerAboveAll
  • LayeredDraw.Layer
  • GuiGraphics.drawString

src/main/java/com/example/examplemod/client/StatusHud.java

package com.example.examplemod.client;
import com.example.examplemod.ExampleMod;
import net.minecraft.client.Minecraft;
import net.minecraft.resources.Identifier;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.client.event.RegisterGuiLayersEvent;
// Text drawn on the HUD every frame, in a GUI layer above the vanilla ones (NeoForge: RegisterGuiLayersEvent).
public final class StatusHud {
private StatusHud() {
}
// Called from the mod's constructor, in the client only.
public static void register(IEventBus modBus) {
modBus.addListener(StatusHud::registerLayers);
}
private static void registerLayers(RegisterGuiLayersEvent event) {
event.registerAboveAll(Identifier.fromNamespaceAndPath(ExampleMod.MOD_ID, "status"),
(guiGraphics, deltaTracker) -> guiGraphics.drawString(Minecraft.getInstance().font, "Hello from my mod", 10, 10, 16777215));
}
}

In your main mod class, inside <init>:

if (FMLEnvironment.getDist() == Dist.CLIENT) {
StatusHud.register(modEventBus);
}

Uses:

  • RegisterGuiLayersEvent.registerAboveAll
  • LayeredDraw.Layer
  • GuiGraphics.drawString

src/main/java/com/example/examplemod/client/StatusHud.java

package com.example.examplemod.client;
import com.example.examplemod.ExampleMod;
import net.minecraft.client.Minecraft;
import net.minecraft.resources.Identifier;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.client.event.RegisterGuiLayersEvent;
// Text drawn on the HUD every frame, in a GUI layer above the vanilla ones (NeoForge: RegisterGuiLayersEvent).
public final class StatusHud {
private StatusHud() {
}
// Called from the mod's constructor, in the client only.
public static void register(IEventBus modBus) {
modBus.addListener(StatusHud::registerLayers);
}
private static void registerLayers(RegisterGuiLayersEvent event) {
event.registerAboveAll(Identifier.fromNamespaceAndPath(ExampleMod.MOD_ID, "status"),
(guiGraphics, deltaTracker) -> guiGraphics.text(Minecraft.getInstance().font, "Hello from my mod", 10, 10, 16777215));
}
}

In your main mod class, inside <init>:

if (FMLEnvironment.getDist() == Dist.CLIENT) {
StatusHud.register(modEventBus);
}

Uses:

  • HudElementRegistry.addLast
  • GuiGraphics.drawString
  • Minecraft.font

Since 26.1 Fabric API’s HudRenderCallback is replaced by HudElementRegistry: a HUD element is a named layer (here added last) that draws with GuiGraphicsExtractor#text.

src/main/java/com/example/examplemod/client/StatusHud.java

package com.example.examplemod.client;
import com.example.examplemod.ExampleMod;
import net.fabricmc.fabric.api.client.rendering.v1.hud.HudElementRegistry;
import net.minecraft.client.Minecraft;
// Text drawn on the HUD every frame, after the vanilla HUD (Fabric API: HudElementRegistry).
public final class StatusHud {
private StatusHud() {
}
// Called from the mod's client entrypoint.
public static void register() {
// Since 26.1 the HUD is a list of named elements; this one goes last, so it draws over the rest.
HudElementRegistry.addLast(ExampleMod.id("status_hud"), (graphics, deltaTracker) -> graphics.text(Minecraft.getInstance().font, "Hello from my mod", 10, 10, 16777215));
}
}

In your client setup class, inside onInitializeClient:

StatusHud.register();

Uses:

  • RegisterGuiOverlaysEvent
  • Font.draw

src/main/java/com/example/examplemod/client/StatusHud.java

package com.example.examplemod.client;
import net.minecraft.client.Minecraft;
import net.minecraftforge.client.event.RegisterGuiOverlaysEvent;
import net.minecraftforge.eventbus.api.IEventBus;
// Text drawn on the HUD every frame, in a GUI overlay above the vanilla ones (Forge: RegisterGuiOverlaysEvent).
public final class StatusHud {
private StatusHud() {
}
// Called from the mod's constructor, in the client only.
public static void register(IEventBus modBus) {
modBus.addListener(StatusHud::registerOverlays);
}
private static void registerOverlays(RegisterGuiOverlaysEvent event) {
event.registerAboveAll("status",
(gui, poseStack, partialTick, width, height) -> Minecraft.getInstance().font.draw(poseStack, "Hello from my mod", 10, 10, 16777215));
}
}

In your main mod class, inside <init>:

if (FMLEnvironment.dist == Dist.CLIENT) {
StatusHud.register(modEventBus);
}

Uses:

  • RegisterGuiOverlaysEvent.registerAboveAll
  • IGuiOverlay
  • GuiGraphics.drawString

src/main/java/com/example/examplemod/client/StatusHud.java

package com.example.examplemod.client;
import net.minecraft.client.Minecraft;
import net.minecraftforge.client.event.RegisterGuiOverlaysEvent;
import net.minecraftforge.eventbus.api.IEventBus;
// Text drawn on the HUD every frame, in a GUI overlay above the vanilla ones (Forge: RegisterGuiOverlaysEvent).
public final class StatusHud {
private StatusHud() {
}
// Called from the mod's constructor, in the client only.
public static void register(IEventBus modBus) {
modBus.addListener(StatusHud::registerOverlays);
}
private static void registerOverlays(RegisterGuiOverlaysEvent event) {
event.registerAboveAll("status",
(gui, guiGraphics, partialTick, width, height) -> guiGraphics.drawString(Minecraft.getInstance().font, "Hello from my mod", 10, 10, 16777215));
}
}

In your main mod class, inside <init>:

if (FMLEnvironment.dist == Dist.CLIENT) {
StatusHud.register(modEventBus);
}

Uses:

  • RegisterGuiOverlaysEvent.registerAboveAll
  • IGuiOverlay
  • GuiGraphics.drawString

src/main/java/com/example/examplemod/client/StatusHud.java

package com.example.examplemod.client;
import net.minecraft.client.Minecraft;
import net.minecraftforge.client.event.RegisterGuiOverlaysEvent;
import net.minecraftforge.eventbus.api.IEventBus;
// Text drawn on the HUD every frame, in a GUI overlay above the vanilla ones (NeoForge: RegisterGuiOverlaysEvent).
public final class StatusHud {
private StatusHud() {
}
// Called from the mod's constructor, in the client only.
public static void register(IEventBus modBus) {
modBus.addListener(StatusHud::registerOverlays);
}
private static void registerOverlays(RegisterGuiOverlaysEvent event) {
event.registerAboveAll("status",
(gui, guiGraphics, partialTick, width, height) -> guiGraphics.drawString(Minecraft.getInstance().font, "Hello from my mod", 10, 10, 16777215));
}
}

In your main mod class, inside <init>:

if (FMLEnvironment.dist == Dist.CLIENT) {
StatusHud.register(modEventBus);
}

Uses:

  • HudRenderCallback.EVENT
  • GuiGraphics.drawString
  • Minecraft.font

src/main/java/com/example/examplemod/client/StatusHud.java

package com.example.examplemod.client;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.Minecraft;
// Text drawn on the HUD every frame, after the vanilla HUD (Fabric API: HudRenderCallback).
public final class StatusHud {
private StatusHud() {
}
// Called from the mod's client entrypoint.
public static void register() {
HudRenderCallback.EVENT.register((poseStack, tickDelta) -> Minecraft.getInstance().font.drawShadow(poseStack, "Hello from my mod", 10, 10, 16777215));
}
}

In your client setup class, inside onInitializeClient:

StatusHud.register();

Uses:

  • RenderGameOverlayEvent.Post
  • RenderGameOverlayEvent.ElementType
  • FontRenderer.draw

src/main/java/com/example/examplemod/client/StatusHud.java

package com.example.examplemod.client;
import net.minecraft.client.Minecraft;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;
// Text drawn on the HUD every frame, after the vanilla HUD (Forge 1.16.5: RenderGameOverlayEvent.Post on the game event bus).
public final class StatusHud {
private StatusHud() {
}
// Called from the mod's constructor, in the client only.
public static void register(IEventBus modBus) {
MinecraftForge.EVENT_BUS.addListener(StatusHud::onRender);
}
private static void onRender(RenderGameOverlayEvent.Post event) {
if (event.getType() == RenderGameOverlayEvent.ElementType.ALL) {
Minecraft.getInstance().font.draw(event.getMatrixStack(), "Hello from my mod", 10, 10, 16777215);
}
}
}

In your main mod class, inside <init>:

if (FMLEnvironment.dist == Dist.CLIENT) {
StatusHud.register(modEventBus);
}

Uses:

  • RenderGameOverlayEvent.Post
  • RenderGameOverlayEvent.ElementType
  • FontRenderer.drawString

src/main/java/com/example/examplemod/client/StatusHud.java

package com.example.examplemod.client;
import com.example.examplemod.ExampleMod;
import net.minecraft.client.Minecraft;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
// Text drawn on the HUD every frame, after the vanilla HUD (Forge 1.12.2: RenderGameOverlayEvent.Post). The class registers itself, in the client only.
@Mod.EventBusSubscriber(modid = ExampleMod.MOD_ID, value = Side.CLIENT)
public final class StatusHud {
private StatusHud() {
}
@SubscribeEvent
public static void onRender(RenderGameOverlayEvent.Post event) {
if (event.getType() == RenderGameOverlayEvent.ElementType.ALL) {
Minecraft.getMinecraft().fontRenderer.drawString("Hello from my mod", 10, 10, 16777215);
}
}
}

Linen’s How-tos library has this page too, with the example for your own mod’s loader and Minecraft version. Hover a name in your code and Linen points to the how-tos that explain it. Both are free. Download Linen.