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.
- 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.
- In it, draw the text.
- Keep it fast: it runs every frame.
What you can change
Section titled “What you can change”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). |
For each loader and version
Section titled “For each loader and version”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.EVENTGuiGraphics.drawStringMinecraft.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.registerAboveAllLayeredDraw.LayerGuiGraphics.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);}NeoForge 1.20.5 to 1.20.6
Section titled “NeoForge 1.20.5 to 1.20.6”Uses:
RegisterGuiLayersEvent.registerAboveAllLayeredDraw.LayerGuiGraphics.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);}NeoForge 1.20.2 to 1.20.4
Section titled “NeoForge 1.20.2 to 1.20.4”Uses:
RegisterGuiOverlaysEvent.registerAboveAllIGuiOverlayGuiGraphics.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);}NeoForge 1.21.9 to 1.21.10
Section titled “NeoForge 1.21.9 to 1.21.10”Uses:
RegisterGuiLayersEvent.registerAboveAllLayeredDraw.LayerGuiGraphics.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);}NeoForge 1.21.11
Section titled “NeoForge 1.21.11”Uses:
RegisterGuiLayersEvent.registerAboveAllLayeredDraw.LayerGuiGraphics.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);}NeoForge 26.1 to 26.3
Section titled “NeoForge 26.1 to 26.3”Uses:
RegisterGuiLayersEvent.registerAboveAllLayeredDraw.LayerGuiGraphics.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);}Fabric 26.1 to 26.3
Section titled “Fabric 26.1 to 26.3”Uses:
HudElementRegistry.addLastGuiGraphics.drawStringMinecraft.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();Forge 1.19 to 1.19.4
Section titled “Forge 1.19 to 1.19.4”Uses:
RegisterGuiOverlaysEventFont.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);}Forge 1.20 to 1.20.1
Section titled “Forge 1.20 to 1.20.1”Uses:
RegisterGuiOverlaysEvent.registerAboveAllIGuiOverlayGuiGraphics.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);}NeoForge 1.20.1
Section titled “NeoForge 1.20.1”Uses:
RegisterGuiOverlaysEvent.registerAboveAllIGuiOverlayGuiGraphics.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);}Fabric 1.16.5 to 1.19.4
Section titled “Fabric 1.16.5 to 1.19.4”Uses:
HudRenderCallback.EVENTGuiGraphics.drawStringMinecraft.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();Forge 1.16.5 to 1.18.2
Section titled “Forge 1.16.5 to 1.18.2”Uses:
RenderGameOverlayEvent.PostRenderGameOverlayEvent.ElementTypeFontRenderer.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);}Forge 1.12.2
Section titled “Forge 1.12.2”Uses:
RenderGameOverlayEvent.PostRenderGameOverlayEvent.ElementTypeFontRenderer.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); } }}Sources
Section titled “Sources”- https://docs.fabricmc.net/1.21.1/develop/rendering/hud
- https://maven.fabricmc.net/docs/fabric-api-0.116.17+1.21.1/net/fabricmc/fabric/api/client/rendering/v1/HudRenderCallback.html
- https://docs.neoforged.net/docs/1.21.1/concepts/events
Related how-tos
Section titled “Related how-tos”- A key the player can press
- Open a screen from an item
- A command that runs on the client
- A mob with attributes and a spawn egg
- Run code every tick
In Linen
Section titled “In Linen”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.