Architecture Diagram
Client Architecture
Minecraft Class
The main client class manages the game state and rendering (Minecraft.h:47):Even in single-player mode, the client maintains a
ClientConnection to a local MinecraftServer instance running in the same process.MultiplayerLocalPlayer
Represents a local player on the client:Server Architecture
MinecraftServer Class
The server manages world simulation and player connections (MinecraftServer.h:60):Server Tick System
The server runs at a fixed 20 ticks per second:Connection Management
ClientConnection
Manages the client-side network connection (ClientConnection.h:9):Connection Handshake
The connection process follows this sequence:ServerConnection
Manages all incoming connections on the server (ServerConnection.h:10):PlayerConnection
Manages a single player’s connection on the server (PlayerConnection.h:12):Player Management
PlayerList
The server maintains a centralized player list:Player Lifecycle
- Connection:
PlayerConnectioncreated when socket connects - Login: Player entity created after successful authentication
- Spawn: Player spawned in world, visible to other players
- Gameplay: Continuous packet exchange (movement, actions, chat)
- Disconnect: Player removed, resources cleaned up
Split-Screen Local Play
Minecraft CE supports up to 4 local players simultaneously, each with their own connection to the local server.
Adding Local Players
- Has their own
ClientConnectionto the server - Maintains separate inventory and game state
- Renders to their own viewport
- Can have different privileges and permissions
Server Lifecycle
Server Initialization
Server Main Loop
Server Shutdown
Best Practices
Thread Safety
Thread Safety
Always use critical sections when accessing shared state:
Connection Management
Connection Management
Check connection state before sending packets:
Server Performance
Server Performance
Avoid expensive operations in the main tick loop. Use background threads for:
- Chunk generation
- Chunk compression
- File I/O operations
Related Topics
Networking
Deep dive into the network protocol and packet system
Overview
High-level architecture and component overview