Overview
Minecraft Community Edition’s GUI system consists of reusable components for building user interfaces. The system is built around theGuiComponent base class, with specialized components for buttons, HUD elements, and visual effects.
GuiComponent Base Class
TheGuiComponent class (GuiComponent.h) provides fundamental rendering utilities used by all GUI elements:
Minecraft.Client/GuiComponent.h:5
Drawing Methods
Line DrawingButton Component
TheButton class provides interactive button elements for screens.
Button Properties
Minecraft.Client/Button.h:5
Creating Buttons
Constructor with default size (200x20):Minecraft.Client/Button.cpp:5
Button States
Buttons have three visual states:Minecraft.Client/Button.cpp:30
- State 0 (Disabled): Gray, non-interactive
- State 1 (Normal): Default appearance
- State 2 (Hovered): Highlighted when mouse over
Button Rendering
Buttons render using thegui.png texture:
Minecraft.Client/Button.cpp:38
Button Interaction
Click Detection:Minecraft.Client/Button.cpp:82
Release Handling:
Minecraft.Client/Button.cpp:78
Button Customization
renderBg() - Override for custom button appearance:Minecraft.Client/Button.cpp:74
Gui (HUD) Class
TheGui class manages the in-game heads-up display (HUD), including health, hunger, hotbar, and messages.
Gui Overview
Minecraft.Client/Gui.h:8
HUD Rendering
The main render method handles all HUD elements:a- Alpha/interpolation valuemouseFree- Whether cursor is visiblexMouse,yMouse- Cursor position
Minecraft.Client/Gui.cpp:57
GUI Scaling
The HUD adapts to different screen configurations:Minecraft.Client/Gui.cpp:68
Supports:
- Fullscreen GUI scaling (scale 2-4)
- Split-screen adjustments
- Safe zones for different viewports
- Dynamic scaling for up to 4 players
Chat Messages
Adding Messages:Minecraft.Client/Gui.h:52
GuiMessage Structure
Minecraft.Client/GuiMessage.h:4
Messages automatically fade out over time based on their tick count.
Overlay Messages
Setting Overlay Text:Minecraft.Client/Gui.h:54
HUD Elements
The Gui class renders various HUD components: Hotbar - Item quick-select bar- 9 slots for quick access
- Selected slot highlighting
- Item icons and counts
- Heart icons
- Damage flash animation
- Regeneration effect
- Food icons (drumsticks)
- Saturation overlay
- Armor icons
- Durability indication
- Progress bar
- Level number
- Damage indication
- Low health warning
- Portal overlay
- FPS counter
- Position/rotation
- Chunk information
- Memory usage
Specialized Rendering
renderSlot() - Renders a single inventory slot:Minecraft.Client/Gui.h:44
Debug Graphs
For performance monitoring:Minecraft.Client/Gui.h:66
Update Loop
- Update message timers
- Fade out old messages
- Animate HUD elements
- Update overlay message timer
GuiParticles System
TheGuiParticles class manages particle effects for UI elements, primarily used in achievement notifications.
GuiParticles Class
Minecraft.Client/GuiParticles.h:8
GuiParticle
Individual particle in the UI:Minecraft.Client/GuiParticle.h:5
Using Particles
- Apply velocity and friction
- Fade out over lifetime
- Remove themselves when expired
- Interpolate position and color for smooth rendering
Achievement Popup System
While not in a dedicated class, achievement notifications use the GUI system: Components:- Toast-style popup in corner
- Achievement icon and title
- Slide-in animation
- GuiParticles for celebratory effect
- Auto-dismiss timer
Item Rendering
TheItemRenderer class handles rendering items in GUI contexts:
- Hotbar item icons
- Inventory slot items
- Achievement icons
- Item tooltips
Color Format
Colors in the GUI system use 32-bit ARGB format:Best Practices
Creating Custom GUI Components
- Extend GuiComponent for rendering utilities
- Use blit() for texture-based rendering
- Use fill() for solid color rectangles
- Cache Font references for text rendering
- Handle visibility with visible flags
- Support scaling using currentGuiScaleFactor
Button Usage
- Use unique IDs for each button
- Set active=false to disable buttons
- Set visible=false to hide buttons
- Position relative to screen width/height
- Standard spacing: 24 pixels between buttons vertically
HUD Rendering
- Respect safe zones for console rendering
- Scale appropriately for split-screen
- Use blitOffset for layered rendering
- Interpolate animations using alpha parameter
- Optimize rendering - avoid overdraw
Related Documentation
- Screen System - Screen lifecycle and management
- Input Handling - Processing user input