Overview
The LevelRenderer class is responsible for rendering the Minecraft world, including chunks, entities, sky, clouds, particles, and various visual effects. It implements the LevelListener interface to receive updates about level changes.
Header: Minecraft.Client/LevelRenderer.h
Class Definition
Constants
Chunk Dimensions
Memory Limits
Platform-specific command buffer allocation limits:
Chunk Flags
Constructor
Creates a new LevelRenderer instance.
Parameters:
mc - Pointer to the main Minecraft instance
textures - Pointer to the texture manager
Core Rendering Methods
render
Renders the level from a player’s perspective.
Parameters:
player - The player entity whose view to render
layer - Render layer (0 = solid blocks, 1 = transparent blocks)
alpha - Interpolation alpha for smooth rendering (0.0-1.0)
updateChunks - Whether to update dirty chunks this frame
Returns: Number of chunks rendered
Example Usage:
renderSameAsLast
Re-renders the same chunks as the previous frame (optimization for split-screen).
renderEntities
Renders all entities in the level.
Parameters:
cam - Camera position vector
culler - Frustum culler for visibility testing
a - Interpolation alpha
Sky and Atmosphere
renderSky
Renders the sky box with celestial bodies (sun, moon, stars).
renderClouds
Renders standard cloud layer.
renderAdvancedClouds
Renders volumetric/fancy clouds (when enabled).
isInCloud
Checks if a position is inside a cloud volume.
Chunk Management
updateDirtyChunks
Rebuilds chunks that have been marked dirty.
Returns: true if any chunks were updated
setDirty
Marks a region of chunks as dirty (needing rebuild).
Parameters:
x0, y0, z0 - Minimum coordinates
x1, y1, z1 - Maximum coordinates
level - The level containing the region
tileChanged
Notifies the renderer that a specific tile/block has changed.
setTilesDirty
Marks tiles in a region as dirty for lighting updates.
Culling and Optimization
cull
Performs frustum culling on chunks to determine visibility.
Parameters:
culler - Frustum culler object
a - Interpolation alpha
Chunk Flag Management
Manage per-chunk flags for tracking compilation status, emptiness, etc.
Reference Counting
Track how many players reference each chunk (for split-screen).
Hit and Selection Rendering
renderHit
Renders the block selection overlay.
renderHitOutline
Renders just the outline of the selected block.
renderDestroyAnimation
Renders block breaking/destruction progress animations.
Particle and Sound
addParticle
Adds a particle effect to the level.
Parameters:
eParticleType - Type of particle to spawn
x, y, z - Spawn position
xa, ya, za - Initial velocity
playSound
Plays a positional sound effect.
Statistics
gatherStats1
Returns chunk rendering statistics (rendered/total chunks).
gatherStats2
Returns entity rendering statistics.
Level Events
levelEvent
Handles level events (door opening, note block, etc.).
destroyTileProgress
Updates block destruction progress (0-10).
Initialization and Cleanup
setLevel
Sets the level for a specific player (split-screen support).
allChanged
Marks all chunks as needing rebuild (called on resource pack change, etc.).
clear
Clears all rendering data and resets the renderer.
PS3 SPU Methods
SPU-accelerated culling for PlayStation 3.
Usage Example
Chunk Rebuild Threading: On large world builds, up to 4 concurrent chunk rebuilds can occur using dedicated threads. The MAX_CONCURRENT_CHUNK_REBUILDS constant controls this behavior.
Memory Management: The command buffer allocation limits are strict per-platform. Exceeding these limits can cause rendering failures or crashes.
- GameRenderer - Main rendering coordinator
- ParticleEngine - Particle system
Chunk - Individual render chunks
TileRenderer - Block/tile rendering
Culler - Frustum culling