Compare commits

...
Author SHA1 Message Date
Ludovic MarieandClaude Opus 5.5 c9f3bb2d89 Attributes: static registry ids, not format! per mob and tick
The type's default of an attribute (base_value, read by mob movement and
every tick's entity tracking) and the LAN attribute sync built the id
"minecraft:<name>" with format! on each call: for a server's 2000 mobs that
is several allocations per mob per tick. Attr::id returns the id as a
static string.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-31 15:57:33 +01:00
2 changed files with 18 additions and 9 deletions

No files matched your search

@@ -121,15 +121,12 @@ impl Game<'_> {
}
if let Some(s) = m.extra.attributes.as_deref() {
for (attr, v) in &s.bases {
if let Some(a) = self.synced_attribute(kind, &format!("minecraft:{}", attr.name()))
{
if let Some(a) = self.synced_attribute(kind, attr.id()) {
instance(out, a, *v).base = *v;
}
}
for x in &s.modifiers {
if let Some(a) =
self.synced_attribute(kind, &format!("minecraft:{}", x.attr.name()))
{
if let Some(a) = self.synced_attribute(kind, x.attr.id()) {
add_modifier(
out,
a,
+16 -4
View File
@@ -435,6 +435,21 @@ impl Attr {
Self::BurningTime => "burning_time",
}
}
/// The attribute's registry id (`minecraft:` and its name), without
/// building it: mob ticks and entity tracking ask for every mob.
pub fn id(self) -> &'static str {
match self {
Self::MaxHealth => "minecraft:max_health",
Self::MovementSpeed => "minecraft:movement_speed",
Self::FollowRange => "minecraft:follow_range",
Self::AttackDamage => "minecraft:attack_damage",
Self::KnockbackResistance => "minecraft:knockback_resistance",
Self::SpawnReinforcements => "minecraft:spawn_reinforcements",
Self::JumpStrength => "minecraft:jump_strength",
Self::Armor => "minecraft:armor",
Self::BurningTime => "minecraft:burning_time",
}
}
/// `RangedAttribute` bounds.
fn range(self) -> (f64, f64) {
match self {
@@ -473,10 +488,7 @@ pub struct Attributes {
}
/// The type's default value of an attribute, if the mob has it.
pub fn default_value(m: &Mob, a: Attr) -> Option<f64> {
m.kind
.attributes
.get(&format!("minecraft:{}", a.name()))
.copied()
m.kind.attributes.get(a.id()).copied()
}
pub fn base_value(m: &Mob, a: Attr) -> f64 {
m.extra