Skip to main content

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 the Screen base class, which itself extends GuiComponent.

Screen Base Class

The Screen class (Screen.h/Screen.cpp) provides the core functionality for all UI screens:

Class Hierarchy

Core Properties

Key Source Files:
  • Minecraft.Client/Screen.h:8 - Screen class definition
  • Minecraft.Client/Screen.cpp:11 - Screen constructor

Screen Lifecycle

Initialization

Screens are initialized through a two-stage process: 1. Base Initialization (Screen::init())
Source: 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)
Used for:
  • Updating animations
  • Processing time-based logic
  • Managing screen state
Source: Minecraft.Client/Screen.cpp:146

Rendering

render() - Called every frame to draw the screen
Parameters:
  • xm - Mouse X coordinate
  • ym - Mouse Y coordinate
  • a - Alpha/interpolation value for smooth rendering
Source: Minecraft.Client/Screen.cpp:22

Cleanup

removed() - Called when screen is closed
Use for cleanup tasks when transitioning away from the screen. Source: Minecraft.Client/Screen.cpp:150

Input Handling

Mouse Input

mouseClicked() - Handles mouse button press
Source: Minecraft.Client/Screen.cpp:52 mouseReleased() - Handles mouse button release
Source: Minecraft.Client/Screen.cpp:70

Keyboard Input

keyPressed() - Handles keyboard input
Source: Minecraft.Client/Screen.cpp:32 tabPressed() - Handles tab key for chat auto-complete
Source: Minecraft.Client/Screen.cpp:200

Button Callbacks

buttonClicked() - Override to handle button presses
Implementations check the button ID to determine action:
Source: Minecraft.Client/Screen.cpp:79

Screen Transitions

Screens are transitioned using Minecraft::setScreen():

Background Rendering

Screens provide methods to render common backgrounds:

Semi-transparent Overlay

Source: Minecraft.Client/Screen.cpp:159

Dirt Background

The classic Minecraft dirt background for main menus:
Source: Minecraft.Client/Screen.cpp:171

Common Screen Types

TitleScreen - Main menu
  • File: Minecraft.Client/TitleScreen.h:7
  • Features: Logo animation, splash text, main menu buttons
  • Key Method: render() for animated logo
PauseScreen - In-game pause menu
  • File: Minecraft.Client/PauseScreen.h:4
  • Features: Resume, options, save, quit
  • Property: isPauseScreen() returns true
OptionsScreen - Settings and configuration
  • File: Minecraft.Client/OptionsScreen.h:6
  • Features: Controls, video settings, game options
  • Uses Options class 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
ConfirmScreen - Yes/No dialog
  • File: Minecraft.Client/ConfirmScreen.h
  • Features: Confirmation dialogs with callbacks
  • Method: confirmResult(bool result, int id)
DeathScreen - Death/respawn screen
  • 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)
Derived screens:
  • 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, yScrollP for panning
  • Special rendering with zoom and scroll
StatsScreen - Statistics viewer
  • 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
ReceivingLevelScreen - Loading level data
  • File: Minecraft.Client/ReceivingLevelScreen.h
  • Features: Progress bar for level download
DisconnectedScreen - Disconnection message
  • File: Minecraft.Client/DisconnectedScreen.h
  • Features: Reason display, return to menu
ErrorScreen - Critical error display
  • File: Minecraft.Client/ErrorScreen.h
  • Features: Error message, stacktrace display

Pause Behavior

Screens can control whether they pause the game:
Source: 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:
Used by achievement notifications and other animated UI elements. See: GUI Components for details on GuiParticles.

Best Practices

Creating a New Screen

  1. Inherit from Screen (or appropriate base class)
  2. Override init() to set up UI
  3. Override render() to draw custom elements
  4. Override buttonClicked() to handle interactions
  5. Call parent methods when appropriate

Example Implementation

Size Calculation

Screens use ScreenSizeCalculator to handle different resolutions and GUI scales:
Source: Minecraft.Client/ScreenSizeCalculator.h