What is a Hud?
A Hud is aHudObject that:
- Displays continuously once added to a player
- Updates based on placeholders and listeners
- Can be toggled on/off per player
- Supports animations and conditional visibility
Unlike Popups, Huds don’t automatically disappear. They remain visible until explicitly removed or the player disconnects.
Basic Structure
Huds are defined in YAML files in thehuds/ directory:
The layout names (e.g.,
health_layout) must match layout definitions in the layouts/ directory.Real Example: Default Health & Hunger HUD
Here’s the actual default HUD from BetterHud’s source:Health Layout
Shows health bar and armor bar on the left side
Hunger Layout
Shows hunger bar and air bar on the right side
Layout Configuration
The referenced layouts are defined inlayouts/default-layout.yml:
Positioning System
Huds use a two-part positioning system:GUI Coordinates
Percentage-based positioning relative to screen size:| Value | Position |
|---|---|
x: 0 | Left edge |
x: 50 | Center horizontally |
x: 100 | Right edge |
y: 0 | Top edge |
y: 100 | Bottom edge |
Pixel Coordinates
Fixed pixel offset from GUI position:Combine both for responsive positioning that adapts to screen size while maintaining precise alignment.
Dynamic Content with Listeners
Hud images can respond to game state using listeners:Available Listeners
| Listener | Monitors | Example Use |
|---|---|---|
health | Player health | Health bars |
food | Hunger level | Hunger bars |
armor | Armor points | Armor indicators |
air | Oxygen level | Air bubbles |
exp | Experience | XP bars |
Create custom listeners with the Listener API to track any numeric value.
Animations
Add life to your HUDs with mathematical animations:Animation Variables
t- Current tick in animation cycle (0 to duration)- Mathematical functions -
sin,cos,tan,sqrt,abs, etc. - Constants -
pi,e
Conditional Visibility
Show/hide HUDs based on conditions:Working with Huds via API
Add and remove HUDs programmatically:Get a
HudPlayer instance from the PlayerManager:Default HUDs
Mark a HUD as default to show it automatically to all players:Default HUDs are added to players when they join and after reloads.
Update Frequency
Control how often a HUD updates:Complete Example
Here’s a complete HUD configuration with all features:layouts/status_layout.yml:
Best Practices
Performance
Performance
- Use reasonable update frequencies (don’t update every tick unless necessary)
- Minimize the number of active HUDs per player
- Optimize image sizes (smaller = better performance)
Design
Design
- Keep HUD elements small and unobtrusive
- Use consistent positioning across HUDs
- Test on different screen sizes and resolutions
Organization
Organization
- Group related layouts together
- Use descriptive names for HUDs and layouts
- Document complex equations with comments (using #)
Next Steps
Popups
Learn about temporary notification displays
Layouts
Deep dive into layout configuration
Images
Configure dynamic and animated images
Listeners
Create custom data listeners
