lighting

Volumetric BFS Lighting Engine for Pyrite.

Implements a highly optimized Breadth-First Search (BFS) flood-fill algorithm for propagating sunlight and block light (glowstone) across the chunk grid. Utilizes Numba and 64-bit integer bit-packing to achieve near-native C++ speeds lock-free across background CPU threads.

lighting.get_voxel_fast(world_x, world_y, world_z, world_voxels, chunk_positions)[source]

Numba-optimized helper to quickly retrieve a voxel ID from the global world arrays using absolute world coordinates. Returns a solid block (1) if the queried chunk is unloaded or out of bounds.

Parameters:
  • world_x (int)

  • world_y (int)

  • world_z (int)

  • world_voxels (Any)

  • chunk_positions (Any)

Return type:

int

lighting.get_light_fast(world_x, world_y, world_z, world_lightmaps, chunk_positions)[source]

Numba-optimized helper to rapidly read the packed light level (Sunlight and Blocklight) for a specific absolute world coordinate. Returns completely dark (0) if out of bounds.

Parameters:
  • world_x (int)

  • world_y (int)

  • world_z (int)

  • world_lightmaps (Any)

  • chunk_positions (Any)

Return type:

int

lighting.set_light_fast(world_x, world_y, world_z, val, world_lightmaps, chunk_positions)[source]

Numba-optimized helper to directly write a packed light value into the global lightmap arrays at the specified absolute world coordinate.

Parameters:
  • world_x (int)

  • world_y (int)

  • world_z (int)

  • val (int)

  • world_lightmaps (Any)

  • chunk_positions (Any)

Return type:

None

lighting.propagate_light_queue(queue, tail, is_sun, world_voxels, world_lightmaps, chunk_positions)[source]

Numba-optimized Breadth-First Search (BFS) light propagation algorithm. Consumes a queue of light nodes and spreads their brightness outward into adjacent transparent blocks (air, water, glass) while respecting bounds and diminishing intensity.

Parameters:
  • queue (Any)

  • tail (int)

  • is_sun (bool)

  • world_voxels (Any)

  • world_lightmaps (Any)

  • chunk_positions (Any)

Return type:

None

lighting.init_chunk_lighting(chunk_x, chunk_y, chunk_z, world_voxels, world_lightmaps, chunk_positions)[source]

Scans a newly loaded/generated chunk for sunlight blocks (level 15) and light-emitting blocks (glowstone). Adds these blocks to a queue and triggers their initial internal BFS propagation to light up the chunk.

Parameters:
  • chunk_x (int)

  • chunk_y (int)

  • chunk_z (int)

  • world_voxels (Any)

  • world_lightmaps (Any)

  • chunk_positions (Any)

Return type:

None

lighting.stitch_chunk_lighting(chunk_x, chunk_y, chunk_z, world_voxels, world_lightmaps, chunk_positions)[source]

Cross-chunk boundary light bleeding. Evaluates the outer borders of a given chunk against its neighboring chunks to allow light to properly spill in or out seamlessly.

Parameters:
  • chunk_x (int)

  • chunk_y (int)

  • chunk_z (int)

  • world_voxels (Any)

  • world_lightmaps (Any)

  • chunk_positions (Any)

Return type:

None

lighting.remove_light_node(world_x, world_y, world_z, light_level, is_sun, world_lightmaps, chunk_positions, refill_queue, tail_refill, queue)[source]

Strips out lighting dynamically when a light source (or opening) is blocked/destroyed. Removes any light dependent on the broken node, but captures any overlapping brighter light nodes into a refill_queue so the space can be re-illuminated by surviving light sources.

Parameters:
  • world_x (int)

  • world_y (int)

  • world_z (int)

  • light_level (int)

  • is_sun (bool)

  • world_lightmaps (Any)

  • chunk_positions (Any)

  • refill_queue (Any)

  • tail_refill (int)

  • queue (Any)

Return type:

int

lighting.update_light_place_block(world_x, world_y, world_z, world_voxels, world_lightmaps, chunk_positions)[source]

Executed when a player places a solid block. Strips existing light from the space and propogates a refill sequence for neighbouring light source to compensate.

Parameters:
  • world_x (int)

  • world_y (int)

  • world_z (int)

  • world_voxels (Any)

  • world_lightmaps (Any)

  • chunk_positions (Any)

Return type:

None

lighting.update_light_remove_block(world_x, world_y, world_z, world_voxels, world_lightmaps, chunk_positions)[source]

Executed when a player destroys a block. Allows surrounding light to flood into the newly opened space. Implements an O(1) verticle linear raycast optimization if the block broken was covering directly top-down sunlight.

Parameters:
  • world_x (int)

  • world_y (int)

  • world_z (int)

  • world_voxels (Any)

  • world_lightmaps (Any)

  • chunk_positions (Any)

Return type:

None

lighting.place_torch(world_x, world_y, world_z, world_voxels, world_lightmaps, chunk_positions)[source]

Hardcodes a block light value of 14 into the grid and triggers a blocklight BFS propogation. Used exclusively for placing items like Glowstone.

Parameters:
  • world_x (int)

  • world_y (int)

  • world_z (int)

  • world_voxels (Any)

  • world_lightmaps (Any)

  • chunk_positions (Any)

Return type:

None