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
Creates a new empty chunk.Parameters:
level- Parent worldx, z- Chunk coordinates (not block coordinates)
Creates a chunk with pre-existing block data.Parameters:
blocks- Block data array (65536 bytes)
Block Access
Gets block ID at local chunk coordinates.Parameters:
x, z- Local coordinates (0-15)y- Height coordinate (0-255)
Sets block at local chunk coordinates.Returns:
true if block was changedGets block metadata at local coordinates.Returns: Metadata value (0-15)
Sets both block and metadata.Parameters:
tile- Block IDdata- Metadata (0-15)
Sets block metadata with optional masking.Parameters:
val- New metadata valuemask- Bit mask for partial updatesmaskedBitsChanged- Output: were masked bits actually changed?
Bulk Data Operations
Sets all block data from a 32768-byte array.Format: Raw block IDs for entire 16×256×16 chunk
Copies all block data into a 32768-byte array.
Sets all metadata from a 16384-byte array.
Copies all metadata into a 16384-byte array.
Lighting
Gets light level at local coordinates.Parameters:
layer-LightLayer::SkyorLightLayer::Block
Sets light level at local coordinates.
Exports sky light data to 16384-byte array.
Imports sky light data from 16384-byte array.
Exports block light data to 16384-byte array.
Imports block light data from 16384-byte array.
Sets all sky light to maximum (15).Use case: Initial chunk generation in overworld
Recalculates the heightmap array.Scans from top down to find highest non-air block in each column.
Recalculates all block (emissive) lighting in the chunk.
Rechecks and fixes lighting gaps.Parameters:
force- Force recheck even if gaps were already checked
Height & Terrain
Gets the Y coordinate of the highest non-air block.Parameters:
x, z- Local coordinates (0-15)
Gets Y coordinate where rain/snow would land.Returns: Y coordinate of topmost solid block
Checks if chunk is completely empty (all air).
Checks if a vertical range is completely empty.Parameters:
y1, y2- Y range to check
Checks if a 16-block vertical section is empty.Parameters:
y- Section Y coordinate (0-15)
Entity Management
Adds an entity to this chunk’s entity list.Entities are organized into a grid for efficient spatial queries.
Removes an entity from this chunk.
Removes an entity from a specific Y section.Parameters:
yc- Y section index (0-15)
Adds entities within bounding box to output vector.Parameters:
except- Entity to excludebb- Bounding box in world coordinateses- Output vector (entities appended)
Adds entities of specific type within bounding box.
Gets total entity count in this chunk.
Tile Entities
Gets the tile entity at local coordinates.Returns: Tile entity or null if none exists
Places a tile entity at local coordinates.
Adds a tile entity to the chunk.
Removes the tile entity at local coordinates.
Biomes
Gets biome at local coordinates.Parameters:
x, z- Local coordinates (0-15)biomeSource- Biome generator
Gets the 16×16 biome array.
Sets the biome array.
Loading & Saving
Marks chunk as loaded and initializes data structures.
Unloads chunk and optionally removes tile entities.
Checks if chunk needs saving.Parameters:
force- Force save even if not modified
Marks chunk as modified and needing save.
Sets the unsaved flag.
Compression & Memory
Attempts to compress block, data, and light storage.Use case: Memory optimization - called periodically on unused chunks
Compresses block storage.
Compresses metadata storage.
Compresses lighting data.
ChunkSource Class
Abstract interface for chunk loading and generation. Header:Minecraft.World/ChunkSource.h
Constants
Methods
Checks if a chunk exists or can be generated.
Gets a chunk, loading or generating if needed.
Generates a new chunk at the specified coordinates.
Runs terrain decoration/population on a chunk.Examples: Tree placement, ore generation, structure spawning
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