Interface HudElementRegistry


public interface HudElementRegistry
A registry of identified hud layers with methods to add layers in specific positions.

Operations relative to a vanilla element will inherit that element's render condition. The render condition for all vanilla layers except VanillaHudElements.SLEEP is GameOptions.hudHidden. Only addFirst(Identifier, HudElement) and addLast(Identifier, HudElement) will not inherit any render condition. There is currently no mechanism to change the render condition of a vanilla element. For vanilla layers, see VanillaHudElements.

Common places to add layers (as of 1.21.6):

Injection Point Use Case
Before MISC_OVERLAYS Render before everything
After MISC_OVERLAYS Render after misc overlays (vignette, spyglass, and powder snow) and before the crosshair
After BOSS_BAR Render after most main hud layers like hotbar, spectator hud, status bars, experience bar, status effects overlays, and boss bar and before the sleep overlay
Before DEMO_TIMER Render after sleep overlay and before the demo timer, debug HUD, scoreboard, overlay message (action bar), and title and subtitle
Before CHAT Render after the debug HUD, scoreboard, overlay message (action bar), and title and subtitle and before ChatHud, player list, and sound subtitles
After SUBTITLES Render after everything
  • Method Details

    • addFirst

      static void addFirst(Identifier id, HudElement element)
      Adds an element to the front.
      Parameters:
      element - the element to add
    • addLast

      static void addLast(Identifier id, HudElement element)
      Adds an element to the end.
      Parameters:
      element - the element to add
    • attachElementBefore

      static void attachElementBefore(Identifier beforeThis, Identifier identifier, HudElement element)
      Attaches an element before the element with the specified identifier.

      The render condition of the vanilla element being attached to, if any, also applies to the new element.

      Parameters:
      beforeThis - the identifier of the element to add the new element before
      identifier - the identifier of the new element
      element - the element to add
    • attachElementAfter

      static void attachElementAfter(Identifier afterThis, Identifier identifier, HudElement element)
      Attaches an element after the element with the specified identifier.

      The render condition of the vanilla element being attached to, if any, also applies to the new element.

      Parameters:
      afterThis - the identifier of the element to add the new element after
      identifier - the identifier of the new element
      element - the element to add
    • removeElement

      static void removeElement(Identifier identifier)
      Removes an element with the specified identifier.
      Parameters:
      identifier - the identifier of the element to remove
    • replaceElement

      static void replaceElement(Identifier identifier, Function<HudElement,HudElement> replacer)
      Replaces an element with the specified identifier, the element retains its original identifier.

      The render condition of the vanilla element being replaced, if any, also applies to the new element.

      Parameters:
      identifier - the identifier of the element to replace
      replacer - a function that takes the old element and returns the new element