Overview
The Screen system in Minecraft Community Edition provides the foundation for all user interface screens, including menus, dialogs, and in-game overlays. All screens inherit from theScreen base class, which itself extends GuiComponent.
Screen Base Class
TheScreen class (Screen.h/Screen.cpp) provides the core functionality for all UI screens:
Class Hierarchy
Core Properties
Minecraft.Client/Screen.h:8- Screen class definitionMinecraft.Client/Screen.cpp:11- Screen constructor
Screen Lifecycle
Initialization
Screens are initialized through a two-stage process: 1. Base Initialization (Screen::init())
Minecraft.Client/Screen.cpp:83
2. Derived Class Setup (virtual void init())
Each screen type implements its own init() method to:
- Add buttons to the screen
- Initialize screen-specific state
- Set up UI layout
Update Loop
tick() - Called every game tick (20 times per second)- Updating animations
- Processing time-based logic
- Managing screen state
Minecraft.Client/Screen.cpp:146
Rendering
render() - Called every frame to draw the screenxm- Mouse X coordinateym- Mouse Y coordinatea- Alpha/interpolation value for smooth rendering
Minecraft.Client/Screen.cpp:22
Cleanup
removed() - Called when screen is closedMinecraft.Client/Screen.cpp:150
Input Handling
Mouse Input
mouseClicked() - Handles mouse button pressMinecraft.Client/Screen.cpp:52
mouseReleased() - Handles mouse button release
Minecraft.Client/Screen.cpp:70
Keyboard Input
keyPressed() - Handles keyboard inputMinecraft.Client/Screen.cpp:32
tabPressed() - Handles tab key for chat auto-complete
Minecraft.Client/Screen.cpp:200
Button Callbacks
buttonClicked() - Override to handle button pressesMinecraft.Client/Screen.cpp:79
Screen Transitions
Screens are transitioned usingMinecraft::setScreen():
Background Rendering
Screens provide methods to render common backgrounds:Semi-transparent Overlay
Minecraft.Client/Screen.cpp:159
Dirt Background
The classic Minecraft dirt background for main menus:Minecraft.Client/Screen.cpp:171
Common Screen Types
Menu Screens
TitleScreen - Main menu- File:
Minecraft.Client/TitleScreen.h:7 - Features: Logo animation, splash text, main menu buttons
- Key Method:
render()for animated logo
- File:
Minecraft.Client/PauseScreen.h:4 - Features: Resume, options, save, quit
- Property:
isPauseScreen()returns true
- File:
Minecraft.Client/OptionsScreen.h:6 - Features: Controls, video settings, game options
- Uses
Optionsclass for settings management
Dialog Screens
ChatScreen - In-game chat interface- File:
Minecraft.Client/ChatScreen.h:5 - Features: Text input, message history
- Special handling for character filtering
- File:
Minecraft.Client/ConfirmScreen.h - Features: Confirmation dialogs with callbacks
- Method:
confirmResult(bool result, int id)
- File:
Minecraft.Client/DeathScreen.h:4 - Features: Respawn button, score display
- Method:
isPauseScreen()returns true
Container Screens
AbstractContainerScreen - Base for inventory UIs- File:
Minecraft.Client/AbstractContainerScreen.h:8 - Features: Slot rendering, item dragging
- Abstract method:
renderBg(float a)
- InventoryScreen - Player inventory (
InventoryScreen.h:6) - CraftingScreen - Crafting table interface
- FurnaceScreen - Furnace interface
- ContainerScreen - Generic chest/container
Information Screens
AchievementScreen - Achievement viewer- File:
Minecraft.Client/AchievementScreen.h:6 - Features: Scrollable achievement tree, progress tracking
- Properties:
xScrollP,yScrollPfor panning - Special rendering with zoom and scroll
- File:
Minecraft.Client/StatsScreen.h - Features: Block/item statistics display
Connection Screens
ConnectScreen - Connecting to server- File:
Minecraft.Client/ConnectScreen.h - Features: Connection status, cancel button
- File:
Minecraft.Client/ReceivingLevelScreen.h - Features: Progress bar for level download
- File:
Minecraft.Client/DisconnectedScreen.h - Features: Reason display, return to menu
- File:
Minecraft.Client/ErrorScreen.h - Features: Error message, stacktrace display
Pause Behavior
Screens can control whether they pause the game:Minecraft.Client/Screen.cpp:191
Set to false for screens that should allow game to continue (like chat).
Particle Effects
Screens have access to a particle system for visual effects:Best Practices
Creating a New Screen
- Inherit from Screen (or appropriate base class)
- Override init() to set up UI
- Override render() to draw custom elements
- Override buttonClicked() to handle interactions
- Call parent methods when appropriate
Example Implementation
Size Calculation
Screens useScreenSizeCalculator to handle different resolutions and GUI scales:
Minecraft.Client/ScreenSizeCalculator.h
Related Documentation
- GUI Components - Buttons, rendering, and HUD
- Input Handling - Detailed input system documentation