Now, we need to define a custom widget renderer object which will be passed to dynamicHUD. This object is an instance of which contains a list of all widgets to render on screens and manage per mod.
public class MyIntegration implements DynamicHudIntegration{
TextWidget exampleWidget;
WidgetRenderer renderer;
@Override
public void init() {
//Previously added and initialised text widget
}
@Override
public void addWidgets() {
//Previously added and initialised text widget
}
//This method is called after the `addWidgets()` method.
public void initAfter() {
//Returns a list of widgets which have the mod id as MyMod.MOD_ID
List<Widget> widgets = WidgetManager.getWidgetsForMod(MyMod.MOD_ID);
//Create a widgetRenderer with the recieved widgets.
renderer = new WidgetRenderer(widgets);
/*
Alternatively you could also use this:
renderer = new WidgetRenderer(new ArrayList<>());
renderer.addWidget(exampleWidget);
Though this method is suggested to only be used when you want
specific widgets to be rendered instead of all.
*/
//Render widgets in the game hud (i.e. when a player is in a world)
renderer.shouldRenderInGameHud(true);
//Add screens to render your widgets in.
//The default is the GameMenuScreen.class (or the pause menu).
//Add screens to also render the widgets in.
//Eg:
renderer.addScreen(TitleScreen.class);
}
@Override
public WidgetRenderer getWidgetRenderer() {
return renderer;
}
@Override
public AbstractMoveableScreen getMovableScreen() {
return null /*Check the next page for this implementation*/;
}
}