Skip to main content

WorldHandle

Trait WorldHandle 

Source
pub trait WorldHandle {
    // Required methods
    fn get_block(&self, x: i32, y: i32, z: i32) -> u16;
    fn set_block(&self, x: i32, y: i32, z: i32, state: u16);
    fn get_block_entity(&self, x: i32, y: i32, z: i32) -> Option<BlockEntity>;
    fn set_block_entity(&self, x: i32, y: i32, z: i32, entity: BlockEntity);
    fn mark_chunk_dirty(&self, cx: i32, cz: i32);
    fn persist_chunk(&self, cx: i32, cz: i32);
    fn dirty_chunks(&self) -> Vec<(i32, i32)>;
    fn check_overlap(&self, aabb: &Aabb) -> bool;
    fn ray_cast(
        &self,
        origin: (f64, f64, f64),
        direction: (f64, f64, f64),
        max_distance: f64,
    ) -> Option<RayHit>;
    fn resolve_movement(
        &self,
        aabb: &Aabb,
        dx: f64,
        dy: f64,
        dz: f64,
    ) -> (f64, f64, f64);
}
Expand description

Long-lived handle to the world runtime.

Pure read/write operations only – no response queueing (see WorldContext for that).

Concrete types stored in Arc for cross-thread sharing (e.g. Arc<World>) already implement Send + Sync. The trait itself does not require them so that per-dispatch types like ServerContext (which uses RefCell) can implement it too.

Required Methods§

Source

fn get_block(&self, x: i32, y: i32, z: i32) -> u16

Returns the block state at the given position.

Generates or loads the chunk if it is not cached. Returns 0 (air) for positions outside the valid Y range.

Source

fn set_block(&self, x: i32, y: i32, z: i32, state: u16)

Sets a block state at the given position.

Generates or loads the chunk if it is not cached. Marks the containing chunk as dirty for persistence.

Source

fn get_block_entity(&self, x: i32, y: i32, z: i32) -> Option<BlockEntity>

Returns a cloned block entity at the given position, if any.

Source

fn set_block_entity(&self, x: i32, y: i32, z: i32, entity: BlockEntity)

Sets a block entity at the given position. Marks the chunk dirty.

Source

fn mark_chunk_dirty(&self, cx: i32, cz: i32)

Marks a chunk as dirty so the persistence system flushes it on the next batch.

Source

fn persist_chunk(&self, cx: i32, cz: i32)

Forces immediate persistence of the chunk to disk (synchronous).

Most callers should prefer mark_chunk_dirty to let the batch persistence path handle it.

Source

fn dirty_chunks(&self) -> Vec<(i32, i32)>

Returns the coordinates of all chunks currently marked dirty.

Source

fn check_overlap(&self, aabb: &Aabb) -> bool

Returns true if the AABB overlaps any solid block.

Source

fn ray_cast( &self, origin: (f64, f64, f64), direction: (f64, f64, f64), max_distance: f64, ) -> Option<RayHit>

Casts a ray through solid blocks. Returns the first hit within max_distance, or None.

Source

fn resolve_movement( &self, aabb: &Aabb, dx: f64, dy: f64, dz: f64, ) -> (f64, f64, f64)

Resolves desired AABB movement against solid block collisions. Returns the actual (dx, dy, dz) after clamping.

Implementors§