pub struct EntityRegistry {
entries: Vec<EntityEntry>,
}Expand description
Registry for entity factories and spawn rules.
Maps EntityType to factory functions that can create entity instances.
This is used when loading entities from disk or when entities are spawned.
Fields§
§entries: Vec<EntityEntry>Implementations§
Source§impl EntityRegistry
impl EntityRegistry
fn finish_registered_load_view( entity: &SharedEntity, nbt: &BorrowedNbtCompoundView<'_, '_>, )
Sourcepub fn register(
&mut self,
entity_type: EntityTypeRef,
factory: fn(EntityTypeRef, i32, DVec3, Weak<World>) -> SharedEntity,
)
pub fn register( &mut self, entity_type: EntityTypeRef, factory: fn(EntityTypeRef, i32, DVec3, Weak<World>) -> SharedEntity, )
Registers a factory function for an entity type.
§Panics
Panics if a factory is already registered for the entity type.
Sourcepub fn register_load(
&mut self,
entity_type: EntityTypeRef,
factory: fn(EntityTypeRef, EntityBaseLoad) -> SharedEntity,
)
pub fn register_load( &mut self, entity_type: EntityTypeRef, factory: fn(EntityTypeRef, EntityBaseLoad) -> SharedEntity, )
Registers a load factory function for an entity type.
The load factory is used when loading entities from disk.
§Panics
Panics if a load factory is already registered for the entity type.
Sourcepub(crate) fn register_spawn_rule(
&mut self,
entity_type: EntityTypeRef,
rule: fn(EntityTypeRef, &dyn LevelReader, EntitySpawnReason, BlockPos, &mut dyn Rng) -> bool,
)
pub(crate) fn register_spawn_rule( &mut self, entity_type: EntityTypeRef, rule: fn(EntityTypeRef, &dyn LevelReader, EntitySpawnReason, BlockPos, &mut dyn Rng) -> bool, )
Registers the spawn placement predicate of an entity type.
§Panics
Panics if a spawn rule is already registered for the entity type.
Sourcepub(super) fn spawn_rule(
&self,
entity_type: EntityTypeRef,
) -> Option<fn(EntityTypeRef, &dyn LevelReader, EntitySpawnReason, BlockPos, &mut dyn Rng) -> bool>
pub(super) fn spawn_rule( &self, entity_type: EntityTypeRef, ) -> Option<fn(EntityTypeRef, &dyn LevelReader, EntitySpawnReason, BlockPos, &mut dyn Rng) -> bool>
Returns the spawn placement predicate of an entity type, if it has one.
Read it through SpawnPlacements: registered predicates are only checked
against vanilla for spawner reasons.
Sourcepub fn create(
&self,
entity_type: EntityTypeRef,
entity_id: i32,
pos: DVec3,
world: Weak<World>,
) -> Option<SharedEntity>
pub fn create( &self, entity_type: EntityTypeRef, entity_id: i32, pos: DVec3, world: Weak<World>, ) -> Option<SharedEntity>
Creates a new entity instance.
Returns None if no factory is registered for the given type.
Sourcepub fn create_and_load(
&self,
request: EntityLoadRequest,
nbt: &BorrowedNbtCompound<'_>,
) -> Option<SharedEntity>
pub fn create_and_load( &self, request: EntityLoadRequest, nbt: &BorrowedNbtCompound<'_>, ) -> Option<SharedEntity>
Creates an entity from persisted data.
Returns None and logs a warning when Steel has no load factory for the type.
Skipped entities and their passenger trees are not retained when the chunk is saved.
Sourcepub(crate) fn create_and_load_for_spawn_view(
&self,
request: EntityLoadRequest,
nbt: &BorrowedNbtCompoundView<'_, '_>,
) -> Option<SharedEntity>
pub(crate) fn create_and_load_for_spawn_view( &self, request: EntityLoadRequest, nbt: &BorrowedNbtCompoundView<'_, '_>, ) -> Option<SharedEntity>
Creates an entity for the normal spawner path from an already borrowed NBT view.
Sourcepub fn has_factory(&self, entity_type: EntityTypeRef) -> bool
pub fn has_factory(&self, entity_type: EntityTypeRef) -> bool
Returns whether a factory is registered for the given type.
Sourcepub fn get_implemented(&self) -> impl Iterator<Item = EntityTypeRef> + '_
pub fn get_implemented(&self) -> impl Iterator<Item = EntityTypeRef> + '_
Get all entity types with a registered factory.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for EntityRegistry
impl RefUnwindSafe for EntityRegistry
impl Send for EntityRegistry
impl Sync for EntityRegistry
impl Unpin for EntityRegistry
impl UnsafeUnpin for EntityRegistry
impl UnwindSafe for EntityRegistry
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<>>