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(Identifier id, StatusBarHeightProvider heightProvider) Adds a height provider for a status bar on the left side above the hotbar.static voidaddRight(Identifier id, StatusBarHeightProvider heightProvider) Adds a height provider for a status bar on the right side above the hotbar.static intgetHeight(Identifier id) Gets the total calculated height offset for a given HUD element ID.
-
Method Details
-
addLeft
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 aPlayerEntityfromInGameHud.getCameraPlayer()and returns the height.
-
addRight
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 aPlayerEntityfromInGameHud.getCameraPlayer()and returns the height.
-
getHeight
Gets the total calculated height offset for a given HUD element ID. Usage:- net.minecraft.client.gui.DrawContext.getScaledWindowHeight() - (39 + renderHeight) + net.minecraft.client.gui.DrawContext.getScaledWindowHeight() - 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
39plus the sum of all registered provider heights that are considered "below" the position of the element associated with the givenid.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 height offset.
-