Skip to main content

EntityPart

Trait EntityPart 

pub trait EntityPart:
    Send
    + Sync
    + 'static {
    // Provided methods
    fn register_goals(&self, goals: &mut GoalRegistrar<'_>) { ... }
    fn register_behaviors(&self, behaviors: &mut BehaviorRegistrar<'_>) { ... }
    fn spawn_cluster_size(
        &self,
        host: &dyn Host,
        mob: UnspawnedMobRef,
        reason: SpawnReason,
        spawner: Option<SpawnSource>,
        vanilla: u32,
    ) -> Option<u32> { ... }
}
Expand description

An entity type’s part (arismoko/horizon#1077): code attached through RegistrationContext::entity_part to one entity type, a mod’s own or vanilla’s (minecraft:zombie). Its register_goals runs at every Mob construction of that type, spawned or loaded, right after the species’ own goals — vanilla’s registerGoals moment — and the goals it adds join the mob’s two selectors beside vanilla’s, same priorities and interruption. Its register_behaviors runs wherever a brain-driven species’ brain is built (#824). Its spawn_cluster_size answers how large a spawn group of the type may grow. Annotate each part trait implementation with horizon_part to derive its subscriptions; entity parts carry no scoped hook yet, so their subscriptions stay empty whatever they override.

Provided Methods§

fn register_goals(&self, goals: &mut GoalRegistrar<'_>)

The mob’s mod goals, added to its two selectors as GoalSelector.addGoal does in vanilla’s registerGoals: fresh at every construction, so a goal’s state is never saved. Branch on the mob with goals.mob().

fn register_behaviors(&self, behaviors: &mut BehaviorRegistrar<'_>)

Native mods only: entity parts do not cross to wasm yet. The mob’s mod brain behaviors, joined into the species’ brain beside vanilla’s (#824): built wherever the brain is built — its first tick and every rebuild — started and stopped in Brain.tick’s order, fresh state each build, nothing saved. Branch on the mob with behaviors.mob().

fn spawn_cluster_size( &self, host: &dyn Host, mob: UnspawnedMobRef, reason: SpawnReason, spawner: Option<SpawnSource>, vanilla: u32, ) -> Option<u32>

How many mobs one spawn group of this mob’s type may grow to (Mob.getMaxSpawnClusterSize), asked where the spawner has just added a mob to a group and compares the group’s size with the limit: natural spawning’s packs. mob is the mob just spawned, finalized and in no level yet, to read through host; reason and spawner say why and from what it spawned (spawner is none but for a spawner block’s mobs); vanilla is the limit the species has. Answer Some(limit) to replace it and None to leave it to the next part and then to vanilla’s. The first part to answer wins, in dispatch order, and the group stops growing once its size reaches the limit, so a limit of 0 or 1 ends it with the mob just spawned. The host is the read-only one: a listener runs on replayed ticks and must be a pure function of its inputs.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§