Skip to main content
Minecraft Community Edition implements a custom network protocol for client-server communication, with platform-specific P2P implementations for console multiplayer.

Network Stack Overview

Connection Class

The Connection class (Connection.h:20) provides the core networking functionality:
The Connection class uses separate read and write threads to prevent blocking and ensure smooth gameplay even with network latency.

Read Thread

Write Thread

Packet System

Packets are defined in net.minecraft.network.packet.h with a base class:

Common Packet Types

  • PreLoginPacket: Initial handshake (UGC settings, texture pack info)
  • LoginPacket: Player authentication and spawn data
  • DisconnectPacket: Connection termination with reason
  • KeepAlivePacket: Connection health check (every 15 seconds)
  • MovePlayerPacket: Player position and rotation
  • TeleportEntityPacket: Instant position change
  • MoveEntityPacket: Entity position delta
  • RotateHeadPacket: Entity head rotation
  • ChunkVisibilityPacket: Send/remove chunk data
  • ChunkVisibilityAreaPacket: Set render distance
  • TileUpdatePacket: Single block change
  • BlockRegionUpdatePacket: Multiple block changes
  • AddPlayerPacket: Spawn player entity
  • AddMobPacket: Spawn mob entity
  • AddEntityPacket: Spawn generic entity
  • RemoveEntitiesPacket: Despawn entities
  • SetEntityDataPacket: Entity metadata update
  • PlayerActionPacket: Mining, interact, use item
  • UseItemPacket: Right-click/place block
  • AnimatePacket: Swing arm, take damage, etc.
  • InteractPacket: Entity interaction

Packet Example: MovePlayerPacket

Platform-Specific Networking

Socket Abstraction

P2P Connection Manager

Each platform has its own P2P implementation:
P2P connections require NAT traversal and may fail on restrictive networks. Always implement fallback to relay servers for production use.

Multiplayer Synchronization

Entity Synchronization

The server is authoritative for all entity state:

Client-Side Prediction

For responsive gameplay, clients predict their own movement:
When the server sends back the authoritative position, the client smoothly interpolates if there’s a mismatch, avoiding jarring teleportation.

Chunk Loading

Chunks are streamed based on player position:

Block Updates

Block changes are broadcast to nearby players:

Network Optimization

Slow Queue System

Low-priority packets use a rate-limited queue to prevent bandwidth saturation:
Slow queue is used for:
  • Non-critical entity updates
  • Distant chunk data
  • Particle effects
  • Sound events

Packet Batching

Multiple small updates can be batched:

Compression

Large data (chunks, textures) uses compression:

Texture Synchronization

Custom skins and texture packs are synchronized:
Texture packets use the slow queue to avoid overwhelming the network during multiplayer sessions.

Error Handling

Disconnect Reasons

Connection Timeout

Best Practices

Minimize Packet Size

Use compact data types (shorts instead of ints where possible) and avoid sending redundant data.

Batch Updates

Group multiple changes into region update packets instead of individual updates.

Use Slow Queue

Put non-critical updates in the slow queue to prioritize gameplay packets.

Validate Server-Side

Never trust client data. Always validate positions, inventory changes, etc.

Client-Server

Learn about the client-server architecture

Overview

High-level architecture overview