Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Minecraft-Community-Edition/client/llms.txt

Use this file to discover all available pages before exploring further.

Overview

The Level API provides core functionality for world management in Minecraft Community Edition. The Level class serves as the foundation for both single-player and multiplayer worlds, handling block manipulation, entity management, lighting, and game logic.

Class Hierarchy

LevelSource
  └── Level (abstract)
        └── MultiPlayerLevel

Level Class

The abstract base class for all game worlds. Header: Minecraft.World/Level.h
Inherits: LevelSource

Constants

static const int MAX_TICK_TILES_PER_TICK = 1000;
static const int MAX_GRASS_TICKS = 100;
static const int MAX_LAVA_TICKS = 100;

static const int MAX_LEVEL_SIZE = 30000000;
static const int maxMovementHeight = 512;

static const int minBuildHeight = 0;
static const int maxBuildHeight = 256;
static const int genDepth = 128;          // 1 << 7
static const int constSeaLevel = 63;      // genDepth / 2 - 1

static const int MAX_BRIGHTNESS = 15;
static const int TICKS_PER_DAY = 24000;   // 20*60*20

Core Members

vector<shared_ptr<Entity>> entities;
vector<shared_ptr<Player>> players;
vector<shared_ptr<Entity>> globalEntities;
vector<shared_ptr<TileEntity>> tileEntityList;

ChunkSource *chunkSource;
Dimension *dimension;
Random *random;
LevelData *levelData;

int difficulty;
int seaLevel;
bool isClientSide;

Constructors

Level(shared_ptr<LevelStorage>, const wstring&, Dimension*, LevelSettings*)
constructor
Creates a new level with the specified storage, name, dimension, and settings.Parameters:
  • levelStorage - Shared pointer to level storage system
  • name - World name
  • dimension - Dimension instance (Overworld, Nether, End)
  • levelSettings - World generation and gameplay settings
Level(Level*, Dimension*)
constructor
Creates a dimension variant of an existing level.Parameters:
  • level - Source level to derive from
  • dimension - Target dimension

Block Access & Modification

getTile(int x, int y, int z)
int
Gets the block ID at the specified coordinates.Returns: Block/tile ID, or 0 if air or unloaded
getData(int x, int y, int z)
int
Gets the block metadata/data value at the specified coordinates.Returns: Block data value (0-15)
setTile(int x, int y, int z, int tile)
bool
Sets a block at the specified position with lighting and updates.Parameters:
  • x, y, z - Block coordinates
  • tile - Block ID to place
Returns: true if block was changed
setTileAndData(int x, int y, int z, int tile, int data)
bool
Sets both block ID and metadata at the specified position.Parameters:
  • x, y, z - Block coordinates
  • tile - Block ID to place
  • data - Metadata value (0-15)
Returns: true if block was changed
setTileNoUpdate(int x, int y, int z, int tile)
bool
Sets a block without triggering neighbor updates or lighting recalculation.Warning: Use sparingly - can cause lighting bugs if not followed by checkLight()
setData(int x, int y, int z, int data, bool forceUpdate)
void
Sets block metadata/data value.Parameters:
  • data - Metadata value (0-15)
  • forceUpdate - Force neighbor updates even if data unchanged

Chunk Management

hasChunk(int x, int z)
bool
Checks if a chunk is loaded (may return true for chunks being generated).Parameters:
  • x, z - Chunk coordinates (not block coordinates)
reallyHasChunk(int x, int z)
bool
Checks if a chunk is actually loaded and ready.Note: More strict than hasChunk() - doesn’t include chunks being generated
getChunk(int x, int z)
LevelChunk*
Gets a chunk, loading it if necessary.Returns: Pointer to chunk (never null - will load/generate if needed)
getChunkAt(int x, int z)
LevelChunk*
Gets the chunk containing the specified block coordinates.Parameters:
  • x, z - Block coordinates (will be converted to chunk coords)

Lighting

getBrightness(LightLayer::variety layer, int x, int y, int z)
int
Gets light level at coordinates for the specified layer.Parameters:
  • layer - LightLayer::Sky or LightLayer::Block
  • x, y, z - Block coordinates
Returns: Light level (0-15)
setBrightness(LightLayer::variety layer, int x, int y, int z, int brightness)
void
Sets light level at coordinates.Parameters:
  • brightness - Light level (0-15)
checkLight(int x, int y, int z, bool force, bool rootOnlyEmissive)
void
Recalculates lighting at the specified position.Parameters:
  • force - Force recalculation even if lighting appears correct
  • rootOnlyEmissive - Only recalculate emissive (block) lighting
getRawBrightness(int x, int y, int z, bool propagate)
int
Gets raw brightness combining sky and block light.Returns: Combined light level (0-15)

Entity Management

addEntity(shared_ptr<Entity> e)
bool
Adds an entity to the world.Returns: true if entity was added successfully
removeEntity(shared_ptr<Entity> e)
void
Marks an entity for removal on next tick.
getEntities(shared_ptr<Entity> except, AABB* bb)
vector<shared_ptr<Entity>>*
Gets all entities within a bounding box.Parameters:
  • except - Entity to exclude from results
  • bb - Axis-aligned bounding box
getEntitiesOfClass(const type_info& baseClass, AABB* bb)
vector<shared_ptr<Entity>>*
Gets entities of a specific type within a bounding box.Example:
auto players = level->getEntitiesOfClass(typeid(Player), boundingBox);

World Queries

getTopTile(int x, int z)
int
Gets the Y coordinate of the highest non-air block.Returns: Y coordinate of topmost solid block
canSeeSky(int x, int y, int z)
bool
Checks if a position has direct line of sight to the sky.
isEmptyTile(int x, int y, int z)
bool
Checks if a position contains air.
getBiome(int x, int z)
Biome*
Gets the biome at the specified coordinates.
getSeaLevel()
int
Gets the sea level for this world.Returns: Y coordinate of sea level (typically 63)

Time & Weather

getTime()
__int64
Gets the current world time in ticks.
setTime(__int64 time)
void
Sets the world time.
isDay()
bool
Checks if it’s currently daytime.
isRaining()
bool
Checks if it’s currently raining.
isThundering()
bool
Checks if there’s currently a thunderstorm.
setRainLevel(float rainLevel)
void
Sets rain intensity (0.0 to 1.0).

Tick & Update

tick()
void
Advances the world by one tick (1/20th of a second).Updates entities, tile entities, scheduled ticks, weather, and mob spawning.
tickEntities()
void
Updates all entities in the world.

MultiPlayerLevel Class

Client-side implementation of Level for multiplayer worlds. Header: Minecraft.Client/MultiPlayerLevel.h
Inherits: Level

Key Features

  • Receives world updates from server via ClientConnection
  • Manages chunk visibility and streaming
  • Handles entity synchronization
  • Supports multiple local players (split-screen)

Constructor

MultiPlayerLevel(ClientConnection*, LevelSettings*, int dimension, int difficulty)
constructor
Creates a multiplayer client-side level.Parameters:
  • connection - Connection to server
  • levelSettings - World settings
  • dimension - Dimension ID (0=Overworld, -1=Nether, 1=End)
  • difficulty - Difficulty level

Methods

setChunkVisible(int x, int z, bool visible)
void
Marks a chunk as visible or invisible to the client.Used for chunk streaming - invisible chunks can be unloaded.
putEntity(int id, shared_ptr<Entity> e)
void
Registers an entity with a network ID for synchronization.
getEntity(int id)
shared_ptr<Entity>
Gets an entity by its network ID.
removeEntity(int id)
shared_ptr<Entity>
Removes and returns an entity by network ID.

Example Usage

Basic Block Manipulation

// Get current block
int blockId = level->getTile(x, y, z);
int blockData = level->getData(x, y, z);

// Place a block
level->setTile(x, y, z, Tile::STONE);

// Place block with metadata
level->setTileAndData(x, y, z, Tile::LOG, 2); // Oak log, east-west orientation

Finding Entities

// Find all players within 10 blocks
AABB searchBox(x - 10, y - 10, z - 10, x + 10, y + 10, z + 10);
auto nearbyPlayers = level->getEntitiesOfClass(typeid(Player), &searchBox);

for (auto& player : *nearbyPlayers) {
    auto p = dynamic_pointer_cast<Player>(player);
    // Do something with player
}

Lighting Updates

// Place a torch and update lighting
level->setTile(x, y, z, Tile::TORCH);
level->checkLight(x, y, z, true, false);

// Get combined light level
int lightLevel = level->getRawBrightness(x, y, z, true);

See Also

Build docs developers (and LLMs) love