Trait AttributesRegistrar
pub trait AttributesRegistrar {
// Required method
fn declare_attribute(
&mut self,
path: &str,
default: f64,
min: f64,
max: f64,
syncable: bool,
sentiment: Sentiment,
) -> Result<(), AttributeRegistrationError>;
}Expand description
Registration of new attribute types (Registrar::declare_attribute).
Required Methods§
fn declare_attribute(
&mut self,
path: &str,
default: f64,
min: f64,
max: f64,
syncable: bool,
sentiment: Sentiment,
) -> Result<(), AttributeRegistrationError>
fn declare_attribute( &mut self, path: &str, default: f64, min: f64, max: f64, syncable: bool, sentiment: Sentiment, ) -> Result<(), AttributeRegistrationError>
Declare an attribute type of the mod’s own (vanilla’s
RangedAttribute in BuiltInRegistries.ATTRIBUTE, NeoForge’s
RegisterEvent): path in the mod’s namespace (mana of mymod is
mymod:mana), its default and [min, max] bounds, whether it
joins the attribute sync (Attribute.setSyncable), and the sentiment
that colors its tooltip lines (Attribute.setSentiment, POSITIVE by
default; the translation key is attribute.name.<ns>.<path>).
Only both-side packages may declare attributes; other sides refuse because
declarations assign network registry IDs.
The declarations join the attribute catalog once, at load, appended
after every vanilla attribute sorted by declaring mod id, then by
attribute id — the order is the network id’s, so every side running
the same mods builds the same numbers and vanilla ids never shift —
before entity attribute rows resolve, so a mod entity’s declared set
may name the mod’s own new attribute. Sanitizing a value (NaN → min,
else clamp) is the definition’s own sanitize.
An id outside the mod’s manifest-owned namespaces (a vanilla attribute’s included),
a malformed id, a duplicate — of this mod’s or another’s, caught
where the declarations join the catalog — a non-finite default or
bound, or bounds the default is not inside (min > max included)
refuses, naming the mod.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".