Skip to main content

Overview

The ParticleEngine class manages all particle effects in the game, including rendering, updating, and managing different types of particles. It supports multiple texture layers and handles particle lifecycle management. Header: Minecraft.Client/ParticleEngine.h

Class Definition

Constants

Particle Limits

Maximum number of particles allowed per texture layer. Dragon breath particles have a higher limit.

Texture Types

Particles are organized by texture type for efficient batch rendering.

Constructor and Destructor

Parameters:
  • level - The level/world the particles exist in
  • textures - Texture manager for particle textures
Example:

Core Methods

add

Adds a particle to the engine. Automatically manages particle limits per layer. Parameters:
  • p - Shared pointer to the particle to add
Example:
Behavior:
  • If layer is full, removes oldest particle first (FIFO)
  • Supports higher limit for dragon breath particles
  • Automatically determines texture layer from particle type

tick

Updates all active particles. Called once per game tick (20 times per second). Operations:
  • Calls tick() on each particle
  • Removes particles marked as removed
  • Handles all three dimension layers (Overworld, Nether, End)
Example:

render

Renders all particles from the player’s perspective. Parameters:
  • player - Player entity (for camera positioning)
  • a - Interpolation alpha for smooth rendering (0.0-1.0)
Example:
Rendering Details:
  • Binds appropriate texture for each particle layer
  • Uses Tesselator for efficient batch rendering
  • Calculates camera-relative positions for billboarding
  • Handles different textures: particles, terrain, items

renderLit

Renders particles that are affected by world lighting. Parameters:
  • player - Player entity
  • a - Interpolation alpha

Level Management

setLevel

Changes the level/world for the particle engine. Parameters:
  • level - New level to associate with
Example:

Block-Specific Particles

destroy

Creates block destruction particles when a block is broken. Parameters:
  • x, y, z - Block position
  • tid - Tile/block ID
  • data - Block data/metadata value
Example:

crack

Creates crack particles when hitting a block. Parameters:
  • x, y, z - Block position
  • face - Face of block that was hit (0-5)
Example:

Statistics

countParticles

Returns a string with particle count statistics for debugging. Returns: Wide string with format like “P: 45/600” (current/max) Example:

Implementation Details

Internal Storage

Particles are stored in a 2D array:
  • First dimension: Level/dimension (0=Overworld, 1=Nether, 2=End)
  • Second dimension: Texture type (MISC, TERRAIN, ITEM, etc.)
This organization allows efficient rendering by texture batching.

Rendering Implementation

Common Particle Types

While ParticleEngine manages all particles, individual particle types include:
  • ExplodeParticle - Explosion effects
  • FlameParticle - Fire and flame
  • SmokeParticle - Smoke effects
  • WaterDropParticle - Water dripping
  • TerrainParticle - Block break/hit particles
  • ItemParticle - Item pickup/use particles
  • HeartParticle - Animal breeding hearts
  • CritParticle - Critical hit stars

Usage Example

Performance Considerations

Particle Limits: The particle system automatically manages limits per layer (200 standard, 1000 for dragon breath). Oldest particles are removed when limits are exceeded, ensuring consistent performance.
Batch Rendering: Particles are batched by texture type for optimal performance. Avoid creating custom particles that frequently switch textures.

Optimization Tips

  1. Texture Batching: The engine groups particles by texture for efficient rendering
  2. Dimension Separation: Each dimension has separate particle storage
  3. FIFO Removal: Oldest particles are removed first when limits are hit
  4. Deque Storage: Uses std::deque for efficient add/remove operations

Multi-Dimension Support

This separation ensures particles in one dimension don’t affect another.
  • LevelRenderer - Main level rendering system
  • GameRenderer - Rendering coordinator
  • Particle - Base particle class
  • Tesselator - Vertex batching for rendering
  • Camera - Camera orientation for billboarding