chunk
Block
¶
Represents a block state in the Minecraft world.
A Block encapsulates the fundamental properties of a single block position, including its type, metadata, world position, and any associated block entity.
| ATTRIBUTE | DESCRIPTION |
|---|---|
id |
Block type identifier
TYPE:
|
metadata |
Block metadata value
TYPE:
|
entity |
Associated block entity (e.g., chest, furnace)
TYPE:
|
position |
World position coordinates |
is_valid
¶
is_valid() -> bool
Check if block state has valid ID and metadata values.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if block ID is in [0, 255] and metadata is in [0, 15] |
is_solid
¶
is_solid() -> bool
Check if block is solid for collision and pathfinding purposes.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if block is not air (ID != 0), False for air blocks |
Notes
This method considers any non-air block as solid. For more complex collision detection, additional logic may be needed based on block type.
Chunk
¶
Complete chunk in the world, optimized for pathfinding and storage.
A chunk represents a 16x16x256 column of blocks divided into 16x16x16 sections. Provides efficient access to block data and manages chunk loading/unloading.
| ATTRIBUTE | DESCRIPTION |
|---|---|
position |
Chunk position in world coordinates |
sections |
Array of chunk sections, None for empty sections
TYPE:
|
biomes |
Biome data for the chunk surface (16x16 array) |
Notes
Chunks are loaded from network data and automatically parsed into sections. Empty sections are represented as None to save memory.
get_section
¶
get_section(section_y: int) -> Optional[ChunkSection]
Get chunk section at the specified Y level.
| PARAMETER | DESCRIPTION |
|---|---|
section_y
|
Section Y coordinate [0, 15]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[ChunkSection]
|
Chunk section at the Y level, or None if invalid Y or empty section |
set_block_state
¶
set_block_entity
¶
set_block_entity(
position: Vector3D[int],
section_y: int,
block_entity: BaseEntity,
) -> None
Set block entity at the specified position.
| PARAMETER | DESCRIPTION |
|---|---|
position
|
Local position within section [0, 15] |
section_y
|
Section Y coordinate [0, 15]
TYPE:
|
block_entity
|
Block entity to place
TYPE:
|
Notes
Automatically creates a new section if one doesn't exist at the Y level.
set_section
¶
set_section(section_y: int, section: ChunkSection) -> None
Set chunk section at the specified Y level.
| PARAMETER | DESCRIPTION |
|---|---|
section_y
|
Section Y coordinate [0, 15]
TYPE:
|
section
|
Chunk section to set
TYPE:
|
Notes
Ignores requests to set sections at invalid Y coordinates.
ChunkSection
¶
16x16x16 chunk section optimized for pathfinding and world storage.
Represents a cubic section of the world containing blocks and block entities. Provides efficient storage and access patterns for block data.
| ATTRIBUTE | DESCRIPTION |
|---|---|
chunk_pos |
Parent chunk position |
section_y |
Vertical section index
TYPE:
|
block_data |
Packed block data array (block_id << 4 | metadata) |
palette |
Palette used for block state mapping
TYPE:
|
block_entities |
Maps block indices to their associated entities
TYPE:
|
Notes
Block data is stored as packed integers where each value contains both block ID and metadata: (block_id << 4) | metadata
get_block_id
¶
get_block
¶
get_block_entity
¶
get_block_entity(
pos: Vector3D[int],
) -> Optional[BaseEntity]
Get block entity at the specified position.
| PARAMETER | DESCRIPTION |
|---|---|
pos
|
Local coordinates within section [0, 15] |
| RETURNS | DESCRIPTION |
|---|---|
Optional[BaseEntity]
|
Block entity at position, or None if no entity exists |
set_block
¶
set_entity
¶
set_entity(
pos: Vector3D[int], block_entity: BaseEntity
) -> None
Set block entity at the specified position.
| PARAMETER | DESCRIPTION |
|---|---|
pos
|
Local coordinates within section [0, 15] |
block_entity
|
Block entity to place at the position
TYPE:
|
is_empty
¶
is_empty() -> bool
Check if section contains only air blocks.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if all blocks are air (ID = 0), False otherwise |
Notes
Useful for optimization - empty sections can be skipped during rendering and collision detection.
choose_palette
staticmethod
¶
choose_palette(
bits_per_block: int,
) -> Union[IndirectPalette, DirectPalette]
Choose appropriate palette type based on bits per block.
| PARAMETER | DESCRIPTION |
|---|---|
bits_per_block
|
Number of bits required per block
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Union[IndirectPalette, DirectPalette]
|
IndirectPalette for <= 8 bits, DirectPalette otherwise |
Notes
Indirect palettes are more efficient for sections with few unique block types, while direct palettes are better for diverse sections.
IndirectPalette
¶
IndirectPalette(bits_per_block: int)
Indirect palette mapping local indices to global palette IDs.
Used for chunk sections with limited unique block types to compress storage by mapping small local IDs to full block state IDs.
| ATTRIBUTE | DESCRIPTION |
|---|---|
bits_per_block |
Actual bits per block used (>= 4)
TYPE:
|
id_to_state |
Maps palette ID to packed block state |
state_to_id |
Maps packed block state to palette ID |
Notes
Block states are packed as: (block_id << 4) | metadata This allows efficient storage of both block type and metadata in a single integer.
add_state
¶
Add block state to palette and return its local ID.
| PARAMETER | DESCRIPTION |
|---|---|
state
|
State to add to the palette
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
Local palette ID for the state (0-based index) |
Notes
If the state already exists in the palette, returns the existing ID. Otherwise, assigns a new sequential ID starting from 0.
state_for_id
¶
read
¶
Read palette data from network buffer.
| PARAMETER | DESCRIPTION |
|---|---|
buffer
|
Buffer containing serialized palette data
TYPE:
|
Notes
Clears existing palette data before reading new data. Expected format: varint length followed by varint state IDs.
DirectPalette
¶
Direct palette using global palette IDs without local mapping.
Used for chunk sections with many unique block types where the overhead of maintaining a local palette exceeds the storage benefits.
| ATTRIBUTE | DESCRIPTION |
|---|---|
bits_per_block |
Fixed at 13 bits for direct palette usage
TYPE:
|
Notes
Direct palettes store global block state IDs directly in the block data array, eliminating the need for a local ID mapping.
state_for_id
staticmethod
¶
Get block state for global palette ID.
| PARAMETER | DESCRIPTION |
|---|---|
palette_id
|
Global palette identifier
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Block
|
state corresponding to the ID, or air block for invalid IDs |
Notes
Validates that the unpacked block ID and metadata are within valid ranges. Returns Block(0, 0) for invalid palette IDs.
read
staticmethod
¶
Read dummy palette data from buffer.
| PARAMETER | DESCRIPTION |
|---|---|
buffer
|
Buffer containing palette data
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
AssertionError
|
If dummy palette length is not 0 |
Notes
Direct palettes don't store local mapping data, so this method only verifies the expected dummy length of 0.