pub(crate) struct BlockEntityStorage {
entries: SyncRwLock<BlockEntityEntries>,
}Expand description
Storage for block entities in a chunk.
Ticker iteration is world-owned. This storage only owns chunk-persistent entities and lazy-promotion markers.
Fields§
§entries: SyncRwLock<BlockEntityEntries>Related entity and marker state shares one lock. This makes replacement, promotion, removal, and persistence snapshots linearizable.
Implementations§
Source§impl BlockEntityStorage
impl BlockEntityStorage
Sourcepub(crate) fn get(&self, pos: BlockPos) -> Option<SharedBlockEntity>
pub(crate) fn get(&self, pos: BlockPos) -> Option<SharedBlockEntity>
Gets a block entity at the given position.
Sourcepub(crate) fn contains_same(
&self,
pos: BlockPos,
expected: &SharedBlockEntity,
) -> bool
pub(crate) fn contains_same( &self, pos: BlockPos, expected: &SharedBlockEntity, ) -> bool
Returns whether expected is the exact current concrete owner.
Sourcepub(crate) fn lookup(&self, pos: BlockPos) -> BlockEntityLookup
pub(crate) fn lookup(&self, pos: BlockPos) -> BlockEntityLookup
Classifies a position with one lock acquisition and one entity-map probe.
Sourcepub(crate) fn get_all(&self) -> Vec<SharedBlockEntity> ⓘ
pub(crate) fn get_all(&self) -> Vec<SharedBlockEntity> ⓘ
Returns all block entities in this storage.
Sourcepub(crate) fn get_all_without_lifecycle_filter(&self) -> Vec<SharedBlockEntity> ⓘ
pub(crate) fn get_all_without_lifecycle_filter(&self) -> Vec<SharedBlockEntity> ⓘ
Returns every concrete entry without applying LevelChunk lifecycle filtering.
Sourcepub(crate) fn save_snapshot(&self) -> (Vec<SharedBlockEntity>, Vec<BlockPos>)
pub(crate) fn save_snapshot(&self) -> (Vec<SharedBlockEntity>, Vec<BlockPos>)
Atomically snapshots concrete entities and packed markers for persistence.
Sourcepub(crate) fn save_snapshot_without_lifecycle_filter(
&self,
) -> (Vec<SharedBlockEntity>, Vec<BlockPos>)
pub(crate) fn save_snapshot_without_lifecycle_filter( &self, ) -> (Vec<SharedBlockEntity>, Vec<BlockPos>)
Atomically snapshots Chunk entries without applying Full lifecycle filtering.
Vanilla ProtoChunk storage is a raw map: removed flags are neither changed nor consulted
until transfer into a LevelChunk.
Sourcepub(crate) fn pending_positions(&self) -> Vec<BlockPos>
pub(crate) fn pending_positions(&self) -> Vec<BlockPos>
Returns packed block-entity positions without changing them.
Sourcepub(crate) fn remove_pending(&self, pos: BlockPos)
pub(crate) fn remove_pending(&self, pos: BlockPos)
Removes one invalid packed marker without constructing an entity.
Sourcepub(crate) fn set_pending(&self, pos: BlockPos) -> bool
pub(crate) fn set_pending(&self, pos: BlockPos) -> bool
Adds a packed marker only when no concrete entity owns the position.
Sourcepub(crate) fn set_without_lifecycle(
&self,
block_entity: &SharedBlockEntity,
) -> bool
pub(crate) fn set_without_lifecycle( &self, block_entity: &SharedBlockEntity, ) -> bool
Sets a Chunk block entity without invoking LevelChunk lifecycle callbacks.
Vanilla ProtoChunk map replacement neither clears nor sets the removed flag.
Sourcepub(crate) fn adopt_if_same_staged(
&self,
pos: BlockPos,
expected: &SharedBlockEntity,
block_state: BlockStateId,
) -> Option<SmallVec<[SharedBlockEntity; 2]>>
pub(crate) fn adopt_if_same_staged( &self, pos: BlockPos, expected: &SharedBlockEntity, block_state: BlockStateId, ) -> Option<SmallVec<[SharedBlockEntity; 2]>>
Adopts an existing pre-Full entity in place and stages its Full lifecycle updates.
Returns None if expected no longer owns the position.
Sourcepub(crate) fn discard_if_same_without_lifecycle(
&self,
pos: BlockPos,
expected: &SharedBlockEntity,
) -> bool
pub(crate) fn discard_if_same_without_lifecycle( &self, pos: BlockPos, expected: &SharedBlockEntity, ) -> bool
Discards an invalid pre-Full entity only while it still owns the position.
Promotion is an ownership transfer, not an unload, so this deliberately queues no removal lifecycle event.
Sourcepub(crate) fn remove_staged(
&self,
pos: BlockPos,
) -> (bool, SmallVec<[SharedBlockEntity; 2]>)
pub(crate) fn remove_staged( &self, pos: BlockPos, ) -> (bool, SmallVec<[SharedBlockEntity; 2]>)
Removes an entity or marker while staging lifecycle callbacks for an outer lock boundary.
Sourcepub(crate) fn detach_and_queue_removal(
&self,
pos: BlockPos,
) -> DetachedBlockEntity
pub(crate) fn detach_and_queue_removal( &self, pos: BlockPos, ) -> DetachedBlockEntity
Detaches the old owner without invoking callbacks.
The removal flag/event is queued while storage still owns the entity. This lets a reentrant same-Arc insertion order its clear transition after removal even though the caller delays callback dispatch until pre-removal side effects have run.
Sourcepub(crate) fn remove_without_lifecycle(&self, pos: BlockPos) -> bool
pub(crate) fn remove_without_lifecycle(&self, pos: BlockPos) -> bool
Removes Chunk entity data without invoking LevelChunk lifecycle callbacks.
Sourcepub(crate) fn remove_if_same_and_removed(
&self,
pos: BlockPos,
expected: &SharedBlockEntity,
) -> bool
pub(crate) fn remove_if_same_and_removed( &self, pos: BlockPos, expected: &SharedBlockEntity, ) -> bool
Removes the entity only if expected still owns pos.
This prevents a stale reader from deleting a concurrent replacement.
Sourcepub(crate) fn add_staged(
&self,
block_entity: &SharedBlockEntity,
block_state: BlockStateId,
) -> (bool, SmallVec<[SharedBlockEntity; 2]>)
pub(crate) fn add_staged( &self, block_entity: &SharedBlockEntity, block_state: BlockStateId, ) -> (bool, SmallVec<[SharedBlockEntity; 2]>)
Adds an entity while staging callbacks for dispatch after outer chunk locks are dropped.
fn set_inner( &self, block_entity: &SharedBlockEntity, block_state: BlockStateId, ) -> (bool, SmallVec<[SharedBlockEntity; 2]>)
Sourcepub(crate) fn insert_if_absent_staged(
&self,
block_entity: &SharedBlockEntity,
block_state: BlockStateId,
) -> BlockEntityInsert
pub(crate) fn insert_if_absent_staged( &self, block_entity: &SharedBlockEntity, block_state: BlockStateId, ) -> BlockEntityInsert
Inserts without replacing a concurrent concrete owner.
fn promote_entry( &self, expected_pos: BlockPos, block_entity: SharedBlockEntity, block_state: Option<BlockStateId>, update_lifecycle: bool, ) -> (Option<SharedBlockEntity>, SmallVec<[SharedBlockEntity; 2]>)
Sourcepub(crate) fn promote_without_lifecycle(
&self,
expected_pos: BlockPos,
block_entity: SharedBlockEntity,
) -> Option<SharedBlockEntity>
pub(crate) fn promote_without_lifecycle( &self, expected_pos: BlockPos, block_entity: SharedBlockEntity, ) -> Option<SharedBlockEntity>
Atomically replaces a packed marker with a concrete proto entity without lifecycle work.
Sourcepub(crate) fn promote_staged(
&self,
expected_pos: BlockPos,
block_state: BlockStateId,
block_entity: SharedBlockEntity,
) -> (Option<SharedBlockEntity>, SmallVec<[SharedBlockEntity; 2]>)
pub(crate) fn promote_staged( &self, expected_pos: BlockPos, block_state: BlockStateId, block_entity: SharedBlockEntity, ) -> (Option<SharedBlockEntity>, SmallVec<[SharedBlockEntity; 2]>)
Promotes a marker while staging callbacks for dispatch after outer locks are dropped.
Sourcepub(crate) fn update_if_same_staged(
&self,
pos: BlockPos,
block_entity: &SharedBlockEntity,
block_state: BlockStateId,
) -> (bool, SmallVec<[SharedBlockEntity; 2]>)
pub(crate) fn update_if_same_staged( &self, pos: BlockPos, block_entity: &SharedBlockEntity, block_state: BlockStateId, ) -> (bool, SmallVec<[SharedBlockEntity; 2]>)
Updates cached state only while block_entity still owns pos.
Sourcepub(crate) fn remove_if_same_staged(
&self,
pos: BlockPos,
expected: &dyn BlockEntity,
) -> (bool, SmallVec<[SharedBlockEntity; 2]>)
pub(crate) fn remove_if_same_staged( &self, pos: BlockPos, expected: &dyn BlockEntity, ) -> (bool, SmallVec<[SharedBlockEntity; 2]>)
Removes expected only while it still owns pos, staging its callback.
Sourcepub(crate) fn clear_and_stage_lifecycle_callbacks(&self) -> ClearedBlockEntities
pub(crate) fn clear_and_stage_lifecycle_callbacks(&self) -> ClearedBlockEntities
Clears storage and returns entities whose lifecycle callback dispatcher this call owns.
Callers that hold outer chunk-map or holder guards can drop them before dispatching.
Sourcepub(crate) fn clear_without_lifecycle(&self)
pub(crate) fn clear_without_lifecycle(&self)
Clears Chunk entity data without invoking LevelChunk lifecycle callbacks.
Trait Implementations§
Source§impl Debug for BlockEntityStorage
impl Debug for BlockEntityStorage
Auto Trait Implementations§
impl !Freeze for BlockEntityStorage
impl !RefUnwindSafe for BlockEntityStorage
impl !UnwindSafe for BlockEntityStorage
impl Send for BlockEntityStorage
impl Sync for BlockEntityStorage
impl Unpin for BlockEntityStorage
impl UnsafeUnpin for BlockEntityStorage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreArc<SyncMutex<>>