Client GUI Events
dev.architectury.event.events.client.ClientGuiEvent
Hooks for rendering the in-game HUD and for initializing, rendering, replacing, and closing screens.
Events
| Event | Listener method | Returns |
|---|---|---|
RENDER_HUD | renderHud(GuiGraphicsExtractor graphics, DeltaTracker) | void - draw on top of the in-game HUD. |
INIT_PRE | init(Screen, ScreenAccess) | EventResult - interrupt to cancel vanilla init. |
INIT_POST | init(Screen, ScreenAccess) | void - after a screen initialized. |
RENDER_PRE | render(Screen, GuiGraphicsExtractor, int mouseX, int mouseY, float delta) | EventResult - interrupt to cancel vanilla render. |
RENDER_POST | render(Screen, GuiGraphicsExtractor, int mouseX, int mouseY, float delta) | void - after a screen rendered. |
RENDER_CONTAINER_BACKGROUND | render(AbstractContainerScreen, GuiGraphicsExtractor, int, int, float) | void |
RENDER_CONTAINER_FOREGROUND | render(AbstractContainerScreen, GuiGraphicsExtractor, int, int, float) | void |
RENDER_BACKGROUND | render(Screen, GuiGraphicsExtractor, int mouseX, int mouseY, float delta) | void - after a screen's background was drawn. |
SET_SCREEN | modifyScreen(Screen) | CompoundEventResult<Screen> - replace the screen about to open. |
SCREEN_CLOSING | closing(Screen) | void - a screen is being closed and removed. |
RENDER_BACKGROUND and SCREEN_CLOSING were added in Architectury API 21.1.
The render events give you a GuiGraphicsExtractor - the drawing context, with methods like
pose(), fill(...), and text(font, component, x, y, color). The ScreenAccess passed to the
INIT events lets you add or remove widgets on the screen - see
Screen Hooks.
RENDER_BACKGROUND fires after a screen's background has been drawn and before its contents.
Unlike RENDER_CONTAINER_BACKGROUND, it fires for every screen, not just container screens.
It mirrors NeoForge's ScreenEvent.Render.Background and Fabric's ScreenEvents.afterBackground.
SCREEN_CLOSING fires when a screen is being closed and removed, which is the counterpart to
INIT_POST and the right place to tear down anything you set up when the screen opened. It
mirrors NeoForge's ScreenEvent.Closing and Fabric's ScreenEvents.remove.
Examples
Draw something over the HUD:
ClientGuiEvent.RENDER_HUD.register((graphics, deltaTracker) -> {
Font font = Minecraft.getInstance().font;
graphics.text(font, Component.literal("Hello HUD"), 4, 4, 0xFFFFFFFF);
});
Draw behind a screen's contents:
ClientGuiEvent.RENDER_BACKGROUND.register((screen, graphics, mouseX, mouseY, delta) -> {
if (screen instanceof MyCustomScreen) {
graphics.fill(0, 0, screen.width, screen.height, 0x40000000);
}
});
Release resources when a screen closes:
ClientGuiEvent.SCREEN_CLOSING.register(screen -> {
if (screen instanceof MyCustomScreen) {
// clean up whatever the screen was holding on to
}
});
Swap one screen for your own when it would open:
ClientGuiEvent.SET_SCREEN.register(screen -> {
if (screen instanceof PauseScreen) {
return CompoundEventResult.interruptTrue(new MyCustomScreen());
}
return CompoundEventResult.pass();
});