Skip to main content

WorldEntityManager

Struct WorldEntityManager 

Source
pub struct WorldEntityManager {
    state: SyncRwLock<ManagerState>,
}
Expand description

Central world entity manager.

Fields§

§state: SyncRwLock<ManagerState>

Implementations§

Source§

impl WorldEntityManager

Source

pub fn new() -> Self

Creates an empty manager.

Source

pub(crate) fn is_chunk_loaded(&self, pos: ChunkPos) -> bool

Returns whether runtime entity ownership for this chunk is loaded.

This is Vanilla’s separate areEntitiesLoaded gate used by block-entity ticking; it is intentionally not the stricter entity-ticking visibility.

Source

pub fn on_chunk_loaded(&self, pos: ChunkPos) -> ChunkEntityLoadResult

Marks a chunk as loaded and reactivates retained unloading entities.

Source

pub fn update_chunk_visibility( &self, pos: ChunkPos, visibility: EntityVisibility, ) -> EntityLifecycleChanges

Updates the entity visibility for a chunk column.

Source

fn push_unique_entity( entity: &SharedEntity, seen: &mut FxHashSet<i32>, entities: &mut Vec<SharedEntity>, )

Source

pub fn begin_chunk_unload(&self, pos: ChunkPos) -> ChunkEntityUnloadStart

Moves manager-owned root entities in pos out of live world membership while retaining them for possible chunk recovery.

Source

fn retain_unloading_entity_tree( state: &mut ManagerState, entity_id: i32, visited: &mut FxHashSet<i32>, retained: &mut Vec<EntityEntry>, retained_entities: &mut Vec<SharedEntity>, tracking_stopped_ids: &mut FxHashSet<i32>, tracking_stopped: &mut Vec<SharedEntity>, )

Source

pub fn finalize_chunk_unload(&self, pos: ChunkPos)

Finalizes an unloading chunk. Retained entities are detached and dropped.

Source

pub fn add_live_entity( &self, entity: SharedEntity, ownership: EntityOwnership, ) -> Result<EntityLifecycleChanges, AddEntityError>

Registers a live runtime entity.

§Panics

Panics if an entity with the same session network ID is already present. Duplicate runtime IDs indicate corrupted manager ownership and cannot be recovered without losing identity.

Source

pub fn add_live_entity_tree( &self, entities: &[SharedEntity], ownership: EntityOwnership, ) -> Result<EntityLifecycleChanges, AddEntityError>

Adds a related group of live entities atomically.

Use this for persisted vehicle/passenger trees so registration either publishes the whole tree or leaves world indexes unchanged.

§Panics

Panics if the entity tree contains the same session network ID more than once. Duplicate runtime IDs indicate corrupted ownership.

Source

fn checked_live_entry( entity: SharedEntity, ownership: EntityOwnership, ) -> Result<EntityEntry, AddEntityError>

Source

fn validate_live_entries( state: &ManagerState, entries: &[EntityEntry], ownership: EntityOwnership, require_loaded_chunks: bool, ) -> Result<(), AddEntityError>

Source

pub fn remove_live_entity( &self, entity_id: i32, reason: RemovalReason, ) -> Option<SharedEntity>

Removes a live entity for an explicit entity removal reason.

Source

pub fn on_chunk_saved(&self, chunk: ChunkPos, saved_entity_ids: &[i32])

Acknowledges that selected save-pending entities for chunk were persisted.

Source

pub fn has_save_pending_for_chunk(&self, chunk: ChunkPos) -> bool

Returns whether chunk has removed runtime entities waiting for a save acknowledgement.

Source

pub fn validate_move( &self, entity_id: i32, new_pos: DVec3, ) -> Result<(), EntityMoveError>

Validates that a live entity can move to new_pos.

Source

pub fn commit_move( &self, entity_id: i32, new_pos: DVec3, ) -> Result<EntityMoveUpdate, EntityMoveError>

Commits manager indexes after a live entity position change.

Source

pub fn commit_bounding_box_change(&self, entity_id: i32)

Commits a live entity bounding-box change to the spatial query index.

Reads the current bounds after acquiring the manager lock so concurrent callbacks may complete in either order without restoring stale bounds.

Source

fn can_move_manager_owned_to_chunk( state: &ManagerState, entry: &EntityEntry, new_chunk: ChunkPos, ) -> bool

Source

fn has_live_loaded_root_vehicle( state: &ManagerState, entity: &SharedEntity, ) -> bool

Source

pub fn get_by_id(&self, entity_id: i32) -> Option<SharedEntity>

Gets a live entity by session network ID.

Source

pub fn contains_live_or_unloading_entity(&self, entity: &SharedEntity) -> bool

Returns true if this exact entity is live or retained for chunk-unload recovery.

Source

pub fn get_accessible_by_id(&self, entity_id: i32) -> Option<SharedEntity>

Gets a live entity by session network ID if it is visible to vanilla gameplay lookups.

Source

pub fn get_by_uuid(&self, uuid: &Uuid) -> Option<SharedEntity>

Gets a live entity by persistent UUID.

Source

pub fn get_entities_in_aabb_matching( &self, aabb: &WorldAabb, predicate: impl FnMut(&dyn Entity) -> bool, ) -> Vec<SharedEntity>

Gets live entities whose bounding boxes intersect aabb and match predicate.

Source

pub fn has_entity_in_aabb_matching( &self, aabb: &WorldAabb, predicate: impl FnMut(&dyn Entity) -> bool, ) -> bool

Returns whether any live entity intersects aabb and matches predicate.

Source

pub fn get_entity_bounding_boxes_in_aabb_matching( &self, aabb: &WorldAabb, predicate: impl FnMut(&dyn Entity) -> bool, ) -> Vec<WorldAabb>

Gets matching live entity bounding boxes that intersect aabb.

Source

pub fn nearest_entity_in_aabb_matching( &self, aabb: &WorldAabb, origin: DVec3, predicate: impl FnMut(&dyn Entity) -> bool, ) -> Option<SharedEntity>

Gets the nearest live entity whose bounding box intersects aabb and matches predicate.

Source

pub fn get_entities_in_aabb(&self, aabb: &WorldAabb) -> Vec<SharedEntity>

Gets live entities whose bounding boxes intersect aabb.

Source

pub fn get_accessible_entities(&self) -> Vec<SharedEntity>

Gets all live entities visible to vanilla gameplay lookups.

Source

fn entity_query_entries<'a>( state: &'a ManagerState, aabb: &WorldAabb, ) -> Vec<&'a EntityEntry>

Source

fn entity_ids_in_chunk_order(state: &ManagerState, chunk: ChunkPos) -> Vec<i32>

Source

pub fn saveable_entities_outside_chunks( &self, saved_chunks: &[ChunkPos], ) -> Vec<UnsavedEntityReport>

Reports saveable entities whose chunks were not part of a chunk save pass.

Source

pub fn get_saveable_entities_for_chunk( &self, chunk: ChunkPos, ) -> Vec<SharedEntity>

Gets entities that should be serialized for chunk.

Source

pub fn live_entities_in_chunk(&self, chunk: ChunkPos) -> Vec<SharedEntity>

Gets live entities currently indexed in chunk.

Source

pub fn count(&self) -> usize

Returns the number of live indexed entities.

Source

pub fn tick_entities( &self, _tick_count: i32, runs_normally: bool, ) -> FxHashSet<ChunkPos>

Ticks live entities currently in the ticking visibility set.

Source

fn ticking_entities_snapshot(&self) -> Vec<SharedEntity>

Source

fn live_manager_owned_entity_chunk(&self, entity_id: i32) -> Option<ChunkPos>

Source

fn chunk_visibility(state: &ManagerState, chunk: ChunkPos) -> EntityVisibility

Source

fn effective_visibility( entry: &EntityEntry, chunk_visibility: EntityVisibility, ) -> EntityVisibility

Source

fn lifecycle_visibility_for( entry: &EntityEntry, chunk_visibility: EntityVisibility, ) -> EntityVisibility

Source

fn apply_entity_lifecycle_after_insert( state: &mut ManagerState, entity_id: i32, ) -> EntityLifecycleChanges

Source

fn apply_chunk_visibility_change( state: &mut ManagerState, chunk: ChunkPos, previous: EntityVisibility, new: EntityVisibility, ) -> EntityLifecycleChanges

Source

fn is_entity_frozen_by_tick_rate( entity: &dyn Entity, runs_normally: bool, ) -> bool

Source

fn has_pending_world_change_in_vehicle_chain(entity: &SharedEntity) -> bool

Source

fn is_accessible(state: &ManagerState, entry: &EntityEntry) -> bool

Source

fn is_accessible_at( state: &ManagerState, ownership: EntityOwnership, chunk: ChunkPos, ) -> bool

Source

fn is_valid_passenger_or_stop_riding(entity: &SharedEntity) -> bool

Source

fn assert_acyclic_vehicle_chain(entity: &SharedEntity)

Source

fn tick_non_passenger( &self, entity: &SharedEntity, ticked_entities: &mut FxHashSet<i32>, dirty_chunks: &mut FxHashSet<ChunkPos>, )

Source

fn tick_vehicle_passengers_with_ticked( &self, vehicle: &dyn Entity, ticked_entities: &mut FxHashSet<i32>, dirty_chunks: &mut FxHashSet<ChunkPos>, )

Source

fn mark_dirty_after_tick( &self, entity: &SharedEntity, dirty_chunks: &mut FxHashSet<ChunkPos>, )

Source

fn can_tick_entity_now(&self, entity_id: i32) -> bool

Source

fn insert_live_entry(state: &mut ManagerState, entry: EntityEntry)

Source

fn contains_uuid(state: &ManagerState, uuid: Uuid) -> bool

Source

fn contains_id(state: &ManagerState, entity_id: i32) -> bool

Source

fn push_saveable_entity( result: &mut Vec<SharedEntity>, seen_ids: &mut FxHashSet<i32>, seen_uuids: &mut FxHashSet<Uuid>, entry: &EntityEntry, )

Source

fn push_unsaved_entity_report( saved_chunks: &FxHashSet<ChunkPos>, seen: &mut FxHashSet<i32>, reports: &mut Vec<UnsavedEntityReport>, entry: &EntityEntry, )

Source

fn remove_live_entry( state: &mut ManagerState, entity_id: i32, ) -> Option<EntityEntry>

Source

fn next_section_order(state: &mut ManagerState) -> u64

Source

fn insert_into_spatial_cells( state: &mut ManagerState, cells: &[EntitySpatialCell], entity_id: i32, query_order: EntityQueryOrder, )

Source

fn remove_from_spatial_cells( state: &mut ManagerState, cells: &[EntitySpatialCell], entity_id: i32, )

Source

fn remove_from_section( state: &mut ManagerState, section: SectionPos, entity_id: i32, )

Source

fn remove_from_chunk(state: &mut ManagerState, chunk: ChunkPos, entity_id: i32)

Trait Implementations§

Source§

impl Debug for WorldEntityManager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for WorldEntityManager

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoShared for T

Source§

fn into_shared(self) -> Arc<Mutex<RawMutex, Self>>

Wraps this value in an Arc<SyncMutex<>>
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more