From 13e83e4e63e13752978d552980b997573013fea4 Mon Sep 17 00:00:00 2001 From: Kacpherek Date: Sun, 25 Oct 2026 15:36:01 +0100 Subject: [PATCH 1/2] Read saved attribute bases for every mob LivingEntity.readAdditionalSaveData applies the attributes list for any living entity, then sets the health (the max health when none is saved). Only horses read max_health and movement_speed, so a summoned cow kept its type defaults. Read max_health, movement_speed and attack_damage for all mobs before the health; horses still read jump_strength. --- crates/horizon-client/src/entity_nbt.rs | 26 +++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/crates/horizon-client/src/entity_nbt.rs b/crates/horizon-client/src/entity_nbt.rs index bf0764a6b..00576ea02 100644 --- a/crates/horizon-client/src/entity_nbt.rs +++ b/crates/horizon-client/src/entity_nbt.rs @@ -617,9 +617,23 @@ pub fn mob_from_nbt(tag: &Tag, types: &HashMap>, id: u32) - m.head_pitch = pitch; m.on_ground = flag(tag, "OnGround"); m.fall_distance = float(tag.get("fall_distance")).unwrap_or(0.0); - if let Some(h) = float(tag.get("Health")) { - m.health = h as f32; + // LivingEntity.readAdditionalSaveData: the saved attribute bases, then + // the health, the max health when there is none. + if let Some(Tag::List(attrs)) = tag.get("attributes") { + for a in attrs { + let (Some(id), Some(Tag::Double(bits))) = (text(a.get("id")), a.get("base")) else { + continue; + }; + let v = f64::from_bits(*bits); + match id.as_str() { + "minecraft:max_health" => m.attrs.max_health = v as f32, + "minecraft:movement_speed" => m.attrs.speed = v, + "minecraft:attack_damage" => m.attrs.attack_damage = v as f32, + _ => {} + } + } } + m.health = float(tag.get("Health")).map_or(m.attrs.max_health, |h| h as f32); m.hurt_time = number(tag.get("HurtTime")).unwrap_or(0) as i32; // What it holds (equipment.mainhand / offhand), when saved. if let Some(eq) = tag.get("equipment") { @@ -735,12 +749,8 @@ pub fn mob_from_nbt(tag: &Tag, types: &HashMap>, id: u32) - let (Some(id), Some(Tag::Double(bits))) = (text(a.get("id")), a.get("base")) else { continue; }; - let v = f64::from_bits(*bits); - match id.as_str() { - "minecraft:max_health" => m.attrs.max_health = v as f32, - "minecraft:movement_speed" => m.attrs.speed = v, - "minecraft:jump_strength" => m.extra.vector[0] = v, - _ => {} + if id == "minecraft:jump_strength" { + m.extra.vector[0] = f64::from_bits(*bits); } } } From 0dfc6d8700554d0d0b8bfb93cc00cd14062daa49 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sun, 25 Oct 2026 17:38:28 +0100 Subject: [PATCH 2/2] command_exec harness: summoned mobs' saved attribute bases and health (#1483) A cow summoned with max_health and movement_speed bases, and a zombie with an attack_damage base and a saved Health, against vanilla. Co-Authored-By: Claude Opus 5.5 --- tools/command_exec_corpus.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tools/command_exec_corpus.py b/tools/command_exec_corpus.py index 0e376e260..be4e16a8a 100644 --- a/tools/command_exec_corpus.py +++ b/tools/command_exec_corpus.py @@ -291,6 +291,19 @@ def entities(): cmd('/data get entity @e[tag=root,limit=1] Passengers[0].Health'), cmd('/data get entity @e[tag=root,limit=1] Passengers[0].id'), cmd('/kill @e[tag=root]'), + # Saved attribute bases are read for every mob, then Health or the max + # health when there is none (LivingEntity.readAdditionalSaveData, #1483). + cmd('/summon minecraft:cow 4.5 210 8.5 {Tags:["attr"],NoAI:1b,NoGravity:1b,' + 'attributes:[{id:"minecraft:max_health",base:40.0d},{id:"minecraft:movement_speed",base:0.5d}]}'), + cmd('/data get entity @e[tag=attr,limit=1] Health'), + cmd('/attribute @e[tag=attr,limit=1] minecraft:max_health base get'), + cmd('/attribute @e[tag=attr,limit=1] minecraft:movement_speed base get'), + cmd('/kill @e[tag=attr]'), + cmd('/summon minecraft:zombie 4.5 210 8.5 {Tags:["attr"],NoAI:1b,NoGravity:1b,Health:7.0f,' + 'attributes:[{id:"minecraft:attack_damage",base:9.0d}]}'), + cmd('/data get entity @e[tag=attr,limit=1] Health'), + cmd('/attribute @e[tag=attr,limit=1] minecraft:attack_damage base get'), + cmd('/kill @e[tag=attr]'), *setup('/kill @e[type=minecraft:armor_stand]'), {'op': 'tick', 'n': 25}, cmd('/execute if entity @e[tag=h]'),