Skip to main content

EntityAttributesRegistrar

Trait EntityAttributesRegistrar 

pub trait EntityAttributesRegistrar {
    // Required methods
    fn declare_entity_attributes(
        &mut self,
        path: &str,
        template: &str,
        attributes: Vec<(String, f64)>,
    ) -> Result<(), EntityAttributeError>;
    fn modify_entity_attributes(
        &mut self,
        entity: &str,
        attributes: Vec<(String, Option<f64>)>,
    ) -> Result<(), EntityAttributeError>;
}
Expand description

Registrar operations for entity attributes.

Required Methods§

fn declare_entity_attributes( &mut self, path: &str, template: &str, attributes: Vec<(String, f64)>, ) -> Result<(), EntityAttributeError>

Declare the initial attribute set of the mod’s entity type path (NeoForge’s EntityAttributeCreationEvent), starting from template’s (minecraft:zombie, the one the type’s content file copies, as Zombie.createAttributes builds on the template’s): each attribute’s id (minecraft:max_health) and the base value that differs from the template’s. The values reach the type’s own fields, its live attribute map and the attribute sync, so the reads of #1469 and #1493 answer the same defaults with no second copy.

Resolved once, at load: an id outside the mod’s manifest-owned namespaces, a duplicate attribute, a non-finite base or a second declaration of the same type refuses the mods, naming the mod; an attribute the game does not know, or a template without attribute defaults, refuses the resource load, naming the type.

fn modify_entity_attributes( &mut self, entity: &str, attributes: Vec<(String, Option<f64>)>, ) -> Result<(), EntityAttributeError>

Add attributes to an existing entity type’s default set (NeoForge’s EntityAttributeModificationEvent): entity is any type with an attribute row (minecraft:zombie; a bare name is in minecraft): a vanilla type, or a mod’s type with a declared set. A living type that only a content file defines has no row of its own yet; declare its set with declare_entity_attributes first, and the additions apply on top of it. Each attribute’s id (minecraft:luck) takes its base, or with none the attribute’s own default, as the event’s one-argument add. An attribute the type already has takes the new base. The change is the type’s default: entities created after load have it, through their spawn fields, their live attribute map and the attribute sync; nothing edits a live entity.

Applied once, at load, after every declared set (declare_entity_attributes), in registration order, so a later addition of the same attribute wins. An invalid type id, the same attribute twice in one call or a non-finite base refuses the mods, naming the mod; an attribute the game does not know, or a type without an attribute row, refuses the resource load, naming the type.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§