Widget Renderer

The WidgetRenderer class is a key component in rendering widgets on the screen for your Minecraft mod. This class manages the list of widgets and controls their rendering based on the current screen and user interactions.

The Widget Renderer class is designed to segregate widget rendering by groups.

The AbstractMoveableScreen utilizes the WidgetRenderer to display and drag widgets from a single group, unlike earlier versions which allowed dragging widgets from all mods within a single screen. This makes it easier for mod developers as well as players to manage widgets.

Class Variables

  • List<Class<? extends Screen>> allowedScreens: A thread-safe list that holds the classes of screens where widgets are allowed to be rendered.

  • boolean isInEditor: A flag indicating whether the widget is in editor mode.

  • Widget selectedWidget: The currently selected widget.

  • List<Widget> widgets: The list of widgets that this renderer should render.

  • boolean renderInGameHud: A flag indicating whether widgets should be rendered in the in-game HUD.

Constructor

The constructor takes a list of widgets that the renderer should render.

public WidgetRenderer(List<Widget> widgets) {
    this.widgets = widgets;
    addScreen(GameMenuScreen.class);
}

Methods

  • void addWidget(Widget widget): Adds a widget to the list of widgets to be rendered.

  • void addScreen(Class<? extends Screen> screen): Adds a screen class to the list of allowed screens where widgets can be rendered.

  • void shouldRenderInGameHud(boolean renderInGameHud): Sets whether widgets should be rendered in the in-game HUD.

  • void renderWidgets(DrawContext context, int mouseX, int mouseY): Renders the widgets based on the current screen and whether the widget is in editor mode.

Last updated

Was this helpful?