Class HudStatusBarHeightRegistry
StatusBarHeightProvider instances, known as height providers. These providers define the
vertical space occupied by HUD elements, known as status bars, which are positioned on the left and right sides above
the player's hotbar.
Registering a height provider allows the game to automatically adjust the layout of existing HUD elements, including vanilla ones, to accommodate new bars without overlap. The system calculates the cumulative height from registered providers on each side and shifts status bars like health, armor, food, and air bars accordingly.
Height providers are associated with an Identifier. The function itself should return the height of the
custom bar. The identifier must also be registered with a corresponding HudElement in
HudElementRegistry. The relative positioning to other HUD elements is determined from that registration. For
instance, registering a height provider for a HUD element attached before
ARMOR_BAR via addLeft(Identifier, StatusBarHeightProvider) implies the
custom bar is on the left side and affects the vertical positioning of elements starting from the armor bar upwards.
The final vertical offset for a HUD element is determined by summing the heights of all custom providers
registered for elements that would appear "below" it on the same side. This includes all HUD elements that have been
attached before it in HudElementRegistry.
Mods that would otherwise have a mixin for altering a vanilla status bar are encouraged to instead register a
full replacement via HudElementRegistry and this class.
For vanilla HUD element identifiers, see VanillaHudElements.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddLeft(net.minecraft.resources.Identifier id, StatusBarHeightProvider heightProvider) Adds a height provider for a status bar on the left side above the hotbar.static voidaddRight(net.minecraft.resources.Identifier id, StatusBarHeightProvider heightProvider) Adds a height provider for a status bar on the right side above the hotbar.static intgetElementHeight(net.minecraft.resources.Identifier id) Gets the height of the given HUD element ID.static intgetHeight(net.minecraft.resources.Identifier id) Gets the total calculated Y offset for a given HUD element ID from the bottom of the screen to the top of the element.
-
Method Details
-
addLeft
public static void addLeft(net.minecraft.resources.Identifier id, StatusBarHeightProvider heightProvider) Adds a height provider for a status bar on the left side above the hotbar.The provided function should return the vertical space (height) that the custom element associated with the given
idoccupies. This height contributes to the total offset applied to elements positioned above it on the right side. Conditions implemented for the rendering of the actual element must also be taken into account here; so when an element currently does not actually render0must be returned.Vanilla height providers for this side are:
HudStatusBarHeightRegistryImpl.HEALTH_BAR,HudStatusBarHeightRegistryImpl.ARMOR_BARExisting height providers (like vanilla) can be replaced to coincide with
HudElementRegistry.replaceElement(Identifier, Function).Registration is frozen once the client has fully started.
- Parameters:
id- theIdentifier; must be registered with a correspondingHudElementinHudElementRegistry.heightProvider- aStatusBarHeightProviderthat takes aPlayerfromMinecraft.getCameraEntity()and returns the height.
-
addRight
public static void addRight(net.minecraft.resources.Identifier id, StatusBarHeightProvider heightProvider) Adds a height provider for a status bar on the right side above the hotbar.The provided function should return the vertical space (height) that the custom element associated with the given
idoccupies. This height contributes to the total offset applied to elements positioned above it on the right side. Conditions implemented for the rendering of the actual element must also be taken into account here; so when an element currently does not actually render0must be returned.Vanilla height providers for this side are:
HudStatusBarHeightRegistryImpl.MOUNT_HEALTH,HudStatusBarHeightRegistryImpl.FOOD_BAR,HudStatusBarHeightRegistryImpl.AIR_BARExisting height providers (like vanilla) can be replaced to coincide with
HudElementRegistry.replaceElement(Identifier, Function).Registration is frozen once the client has fully started.
- Parameters:
id- theIdentifier; must be registered with a correspondingHudElementinHudElementRegistry.heightProvider- aStatusBarHeightProviderthat takes aPlayerfromMinecraft.getCameraEntity()and returns the height.
-
getHeight
public static int getHeight(net.minecraft.resources.Identifier id) Gets the total calculated Y offset for a given HUD element ID from the bottom of the screen to the top of the element.
Usage:
- net.minecraft.client.gui.GuiGraphics.guiHeight() - (39 + renderHeight) + net.minecraft.client.gui.GuiGraphics.guiHeight() - HudStatusBarHeightRegistry.getHeight(id)This method is typically used by the rendering system to determine how much to shift a HUD element. It returns the default HUD height which is
24plus the sum of all registered provider heights including and below the position of the element associated with the givenid. Earlier hud elements are considered to be below later ones.Note: The registry must be initialized (frozen) before this method returns values without throwing an exception. This initialization happens during the Minecraft client setup.
- Parameters:
id- theIdentifierof the HUD element.- Returns:
- the total Y offset from the bottom of the screen to the top of the element.
-
getElementHeight
public static int getElementHeight(net.minecraft.resources.Identifier id) Gets the height of the given HUD element ID.- Parameters:
id- theIdentifierof the HUD element.- Returns:
- the height of the element.
-