API Reference
This section provides a structured reference to core Pyrite classes, methods, and constants. Use this for looking up specific functionality.
Core Engine (main.py)
class Pyrite
Root application class managing game lifecycle, state transitions, and subsystems.
Key Attributes:
game_state: Current state ('MAIN_MENU', 'IN_GAME', 'PAUSED', 'OPTIONS', 'LOADING', 'INVENTORY', 'WORLD_SELECT', 'CREATE_WORLD)world: World instance (active when in-game)player: Player instancescene: Scene manager (rendering)ctx: ModernGL context
Key Methods:
__init__(): Initialize Pygame, OpenGL, load configinit_game_session(save_name, force_seed, game_mode): Load/create a worldrun(): Main loop (event → update → render)handle_events(): Dispatch OS eventsupdate(): Tick all systemsrender(): Draw framequit_game(): Shutdown, save world
Player (player.py)
class Player(Camera)
Manages player physics, camera, input, inventory, and survival stats.
Key Attributes:
feet_pos: glm.vec3: Position at feet (for collisions)velocity: glm.vec3: Movement velocityyaw, pitch: float: Camera rotation (radians)on_ground: bool: Contact with solid blockin_water: bool: Head submergedhealth, hunger, oxygen: float: Survival stats (0-20)inventory: List[int]: 41-slot inventory IDsinventory_counts: List[int]: Stack sizeshotbar_index: int: Selected hotbar slot (0-8)
Key Methods:
update(): Physics, movement, animationshandle_event(event): Process inputget_aabb(): Get bounding boxmove_and_collide(): Physics with collisionadd_item(voxel_id): Pickup itemtake_damage(amount): Reduce health
World (world.py)
class World
Manages terrain generation, chunk loading/unloading, and persistence.
Key Attributes:
active_chunks: Dict: Loaded chunksworld_seed: int: World seedvoxels: np.ndarray: Massive 1D array of all active world voxelslightmaps: np.ndarray: Massive 1D array of all active world light data
Key Methods:
load_chunk(x, y, z): Queue a chunk for asynchronous loading/generationunload_chunk(pos): Unload chunk and trigger async DB savesave(): Synchronous shutdown, flush all to disk
Chunk (chunk.py)
class Chunk
Represents a 48x48x48 voxel block.
Key Attributes:
position: (int, int, int): Chunk coordinatesvoxels: np.ndarray: (110592,) uint8 voxel IDslightmap: np.ndarray: (110592,) uint8 packed lightmesh: ChunkMesh: Rendered geometryis_empty: bool: True if chunk contains only airis_visible: bool: Frustum/Occlusion visibility state
Key Methods:
build_mesh(): Triggers chunk mesh builderrender(): Submits VBOs to GPU
Scene (scene.py)
class Scene
Multi-pass rendering orchestrator.
Key Methods:
update(): Update cameras, animations, chunksrender(): Render world + UI
VoxelHandler (voxel_handler.py)
class VoxelHandler
Raycast targeting and block manipulation.
Key Methods:
ray_cast(): Cast ray from camera, return target blockadd_voxel(): Place blockremove_voxel(): Mine block
Constants (settings.py)
Performance Tuning:
MESH_BUILD_LIMIT_INGAME = 4: Chunks meshed per frameMAIN_THREAD_MESH_PROCESS_LIMIT_INGAME = 2: GPU uploads per frameVBO_POOL_CAP = 150: Recycled GPU buffersLIGHTING_QUEUE_SIZE = 200000: BFS light queue nodes
Physics:
GRAVITY = -0.000025: Downward accelerationJUMP_VELOCITY = 0.0095: Jump boostPLAYER_SPEED = 0.005: Movement speedPLAYER_WIDTH = 0.6: Collision box widthPLAYER_HEIGHT = 1.8: Collision box height
Survival:
MAX_HEALTH = 20: Player dies at 0 healthMAX_HUNGER = 20: Hunger depletes over time, causes health loss at 0MAX_OXYGEN = 20: Breath underwaterBLOCK_HARDNESS: Dict of block IDs → break time (ms)
Environment:
CHUNK_SIZE = 48: Voxels per axisCHUNK_VOL = 110592: Total voxels per chunkWATER_LINE = 6: Sea levelSTONE_LVL = 49: Bedrock layer startWORLD_W, WORLD_H, WORLD_D: Max chunk counts
Shader Programs (shader_program.py)
Uniform Bindings (All Shaders):
m_proj: mat4: Projection matrixm_view: mat4: View matrix (camera)m_model: mat4: Model matrixu_sun_direction: vec3: Sun position (normalized)u_time: float: World time (seconds)
Chunk Shader Uniforms:
u_texture_array_0: sampler2DArray: Texture atlasu_texture_map[256]: int[]: Voxel ID → texture layeru_fog_density: float: Fog start distanceu_underwater_tint: bool: Apply blue tintbg_color: vec3: Background (sky) color
UI Shader Uniforms:
u_offset: vec2: Screen position (NDC)u_scale: vec2: Size (NDC)u_color: vec4: Color (UI shaders)
Mesh Building (build_chunk_mesh.py)
Function: build_chunk_mesh(chunk_voxels, chunk_lightmap, chunk_pos, world_voxels, world_lightmaps, chunk_positions)
Numba-compiled greedy meshing. Returns vertex data and light data (packed).
Vertex Packing:
Bits 31-26: X coordinate (0-47)
Bits 25-20: Y coordinate (0-47)
Bits 19-14: Z coordinate (0-47)
Bits 13-6: Voxel ID (0-255)
Bits 5-3: Face ID (0-5)
Bits 2-1: AO ID (0-3)
Bit 0: Flip ID (0-1)
Light Packing:
Bits 7-4: Sunlight (0-15)
Bits 3-0: Blocklight (0-15)
Terrain Generation (terrain_gen.py)
Handled via Numba JIT functions in Chunk.generate_terrain() using vectorized 3D simplex noise.
Lighting (lighting.py)
Uses BFS lighting propagation logic executed completely through standalone Numba compiled functions such as:
init_chunk_lighting()stitch_chunk_lighting()update_light_place_block()update_light_remove_block()place_torch()
Common Enums and Constants
# Block IDs
AIR = 0
SAND = 1
GRASS = 2
DIRT = 3
STONE = 4
SNOW = 5
LEAVES = 6
WOOD = 7
GRAVEL = 8
WOOD_PLANKS = 9
COBBELSTONE = 10
WATER = 11
GLOWSTONE = 12
GLASS = 13
CACTUS = 14
STONE_BRICKS = 15
# 16-32 are reserved for other blocks, 33+ are items
STICK = 33
WOODEN_PICKAXE = 34
# Game States
MAIN_MENU
WORLD_SELECT
CREATE_WORLD
LOADING
IN_GAME
INVENTORY
PAUSED
OPTIONS
# Transparent Blocks:
[AIR, WATER, GLASS, LEAVES]