Configuring the Widget Renderer
From version 3.0.0 onwards, you configure the renderer using `DynamicHudConfigurator.configureRenderer` or `DynamicHudConfigurator.overrideRenderer`.
Now, we need to define a custom widget renderer object which will be passed to dynamicHUD. This object is an instance of WidgetRenderer which contains a list of all widgets to render on screens and manage per mod.
public class MyIntegration implements DynamicHudIntegration{
TextWidget exampleWidget;
@Override
public void init() {
//Previously added and initialised text widget
}
@Override
public DynamicHudConfigurator configure(DynamicHudConfigurator configurator) {
return configurator
.addWidget(exampleWidget)
.configureRenderer(renderer -> {
// Render widgets in-game (e.g., in a world)
renderer.shouldRenderInGameHud(true);
// Add TitleScreen to allowed screens (default includes GameMenuScreen)
renderer.addScreen(TitleScreen.class);
// Set custom Z-index for rendering
// for example if you want a widget to appear above the inventory screen
// renderer.withZIndex(150);
})
.withMoveableScreen(config -> new AbstractMoveableScreen(Text.literal("My HUD Editor"), config.getRenderer()) {});
}
}
Using a Custom Predicate
For complex screen logic, update the allowed screens with a predicate:
renderer.updateAllowedScreens(screen -> screen instanceof TitleScreen || screen instanceof GameMenuScreen);
Use Case: Use predicates for variable conditions, like rendering only on specific custom screens.
Overriding the Renderer
For full control, create a custom WidgetRenderer and pass it via overrideRenderer:
List<Widget> customWidgets = WidgetManager.getWidgetsForMod("mymod");
WidgetRenderer customRenderer = new WidgetRenderer(customWidgets);
customRenderer.shouldRenderInGameHud(true);
customRenderer.addScreen(TitleScreen.class);
configurator.overrideRenderer(customRenderer);
Use Case: Use when you need a completely custom rendering logic or widget management.
Last updated
Was this helpful?