Skip to main content

Overview

The Chunk API manages 16×256×16 sections of the world in Minecraft Community Edition. Chunks handle block storage, lighting, entity organization, and tile entities.

Class Hierarchy

LevelChunk Class

Represents a 16×256×16 section of blocks in the world. Header: Minecraft.World/LevelChunk.h

Constants

Core Members

Internal Storage

Chunks use optimized compressed storage:

Constructor

constructor
Creates a new empty chunk.Parameters:
  • level - Parent world
  • x, z - Chunk coordinates (not block coordinates)
constructor
Creates a chunk with pre-existing block data.Parameters:
  • blocks - Block data array (65536 bytes)

Block Access

int
Gets block ID at local chunk coordinates.Parameters:
  • x, z - Local coordinates (0-15)
  • y - Height coordinate (0-255)
Returns: Block/tile ID
bool
Sets block at local chunk coordinates.Returns: true if block was changed
int
Gets block metadata at local coordinates.Returns: Metadata value (0-15)
bool
Sets both block and metadata.Parameters:
  • tile - Block ID
  • data - Metadata (0-15)
bool
Sets block metadata with optional masking.Parameters:
  • val - New metadata value
  • mask - Bit mask for partial updates
  • maskedBitsChanged - Output: were masked bits actually changed?

Bulk Data Operations

void
Sets all block data from a 32768-byte array.Format: Raw block IDs for entire 16×256×16 chunk
void
Copies all block data into a 32768-byte array.
void
Sets all metadata from a 16384-byte array.
void
Copies all metadata into a 16384-byte array.

Lighting

int
Gets light level at local coordinates.Parameters:
  • layer - LightLayer::Sky or LightLayer::Block
Returns: Light level (0-15)
void
Sets light level at local coordinates.
void
Exports sky light data to 16384-byte array.
void
Imports sky light data from 16384-byte array.
void
Exports block light data to 16384-byte array.
void
Imports block light data from 16384-byte array.
void
Sets all sky light to maximum (15).Use case: Initial chunk generation in overworld
void
Recalculates the heightmap array.Scans from top down to find highest non-air block in each column.
void
Recalculates all block (emissive) lighting in the chunk.
void
Rechecks and fixes lighting gaps.Parameters:
  • force - Force recheck even if gaps were already checked

Height & Terrain

int
Gets the Y coordinate of the highest non-air block.Parameters:
  • x, z - Local coordinates (0-15)
Returns: Y coordinate (0-255)
int
Gets Y coordinate where rain/snow would land.Returns: Y coordinate of topmost solid block
bool
Checks if chunk is completely empty (all air).
bool
Checks if a vertical range is completely empty.Parameters:
  • y1, y2 - Y range to check
bool
Checks if a 16-block vertical section is empty.Parameters:
  • y - Section Y coordinate (0-15)
Use case: Render optimization - skip empty sections

Entity Management

void
Adds an entity to this chunk’s entity list.Entities are organized into a grid for efficient spatial queries.
void
Removes an entity from this chunk.
void
Removes an entity from a specific Y section.Parameters:
  • yc - Y section index (0-15)
void
Adds entities within bounding box to output vector.Parameters:
  • except - Entity to exclude
  • bb - Bounding box in world coordinates
  • es - Output vector (entities appended)
void
Adds entities of specific type within bounding box.
int
Gets total entity count in this chunk.

Tile Entities

shared_ptr<TileEntity>
Gets the tile entity at local coordinates.Returns: Tile entity or null if none exists
void
Places a tile entity at local coordinates.
void
Adds a tile entity to the chunk.
void
Removes the tile entity at local coordinates.

Biomes

Biome*
Gets biome at local coordinates.Parameters:
  • x, z - Local coordinates (0-15)
  • biomeSource - Biome generator
byteArray
Gets the 16×16 biome array.
void
Sets the biome array.

Loading & Saving

void
Marks chunk as loaded and initializes data structures.
void
Unloads chunk and optionally removes tile entities.
bool
Checks if chunk needs saving.Parameters:
  • force - Force save even if not modified
void
Marks chunk as modified and needing save.
void
Sets the unsaved flag.

Compression & Memory

void
Attempts to compress block, data, and light storage.Use case: Memory optimization - called periodically on unused chunks
void
Compresses block storage.
void
Compresses metadata storage.
void
Compresses lighting data.

ChunkSource Class

Abstract interface for chunk loading and generation. Header: Minecraft.World/ChunkSource.h

Constants

Methods

bool
Checks if a chunk exists or can be generated.
LevelChunk*
Gets a chunk, loading or generating if needed.
LevelChunk*
Generates a new chunk at the specified coordinates.
void
Runs terrain decoration/population on a chunk.Examples: Tree placement, ore generation, structure spawning
bool
Saves all modified chunks.

Example Usage

Accessing Chunk Data

Bulk Block Placement

Checking Chunk Population

See Also

  • Level API - World management
  • Entity API - Entity storage in chunks
  • Block API - Block types and properties