Server's mobs: babies, wool, collars, fire, slime sizes and health reach its clients

A client of a server (single player on its server thread, a LAN guest, a
dedicated server's player) only applied a rabbit's baby flag and a creeper's
swell from SetEntityData. It now reads the synched data vanilla's entities
read in onSyncedDataUpdated: Entity's on-fire flag, LivingEntity's health
(the wither's boss bar follows it), the baby flag of every ageable mob,
Sheep.DATA_WOOL_ID, TamableAnimal's sitting and tame flags, the wolf's and
the cat's collar colour, and the cube mobs' size. A remote wolf or cat starts
with vanilla's red collar.

The server sends the wolf's and cat's collar colour. Pairing still carries
only the values that differ from the defaults; a mob's state now lists the
defaults of the entries that can go back to theirs (health, the baby flag,
the wool, the collar), and the tracker sends that default when one does:
a calf growing up or a sheep's white wool growing back reach the clients.

Sheep saves wrote the colour and shearing they were loaded with (0 unless
the save had them) and loads ignored both: they now save and load the wool
as it is (Sheep.add/readAdditionalSaveData).

lan_e2e's new `looks` check summons the mobs and changes them on both sides.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-23 07:31:31 +02:00
parent e325fa6587
commit c35ea9568f
12 changed files with 331 additions and 17 deletions
+44 -3
View File
@@ -445,10 +445,10 @@ pub fn mob_to_nbt(m: &Mob, uuid: [i32; 4], raw: Option<&Tag>) -> Tag {
map.entry(key.into()).or_insert(value);
}
}
// Sheep.addAdditionalSaveData: its wool as it is now.
"minecraft:sheep" => {
for (key, value) in [("Color", Tag::Byte(0)), ("Sheared", Tag::Byte(0))] {
map.entry(key.into()).or_insert(value);
}
map.insert("Color".into(), Tag::Byte((m.extra.color & 15) as i8));
map.insert("Sheared".into(), Tag::Byte(i8::from(m.extra.sheared)));
}
// CopperGolem.addAdditionalSaveData.
"minecraft:copper_golem" => {
@@ -832,6 +832,11 @@ pub fn mob_from_nbt(tag: &Tag, types: &HashMap<String, Arc<MobType>>, id: u32) -
}
m.extra.egg_time = number(tag.get("life_ticks")).map_or(-1, |v| v as i32);
}
// Sheep.readAdditionalSaveData: white and unsheared when absent.
if m.species() == crate::mobs::Species::Sheep {
m.extra.color = number(tag.get("Color")).map_or(0, |c| (c as u8) & 15);
m.extra.sheared = flag(tag, "Sheared");
}
if m.species() == crate::mobs::Species::Shulker {
m.extra.variant3 = number(tag.get("AttachFace")).unwrap_or(0).clamp(0, 5) as u8;
m.extra.counter = number(tag.get("Peek")).unwrap_or(0).clamp(0, 100) as i32;
@@ -2051,3 +2056,39 @@ mod axolotl_nbt_tests {
assert_eq!(mm.temptation_cooldown_ticks.value(), Some(42));
}
}
#[cfg(test)]
mod sheep_nbt_tests {
use super::*;
#[test]
fn a_sheep_keeps_its_dyed_and_sheared_wool() {
let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
.join("../../.local/horizon-client")
.join(horizon_core::VANILLA_VERSION);
if !root.join("items.json").exists() {
return;
}
let data = crate::mobs::MobTypes::load(&root).unwrap();
let mut m = Mob::new(
1,
Arc::new(data.types["minecraft:sheep"].clone()),
Vec3::new(0.0, 4.0, 0.0),
0.0,
);
// Summoned white, then dyed red and sheared: the save has it now.
let raw = Tag::compound([("Color", Tag::Byte(0)), ("Sheared", Tag::Byte(0))]);
(m.extra.color, m.extra.sheared) = (14, true);
let tag = mob_to_nbt(&m, [1, 2, 3, 4], Some(&raw));
assert_eq!(
(number(tag.get("Color")), number(tag.get("Sheared"))),
(Some(14), Some(1))
);
let types: HashMap<String, Arc<MobType>> = data
.types
.iter()
.map(|(k, v)| (k.clone(), Arc::new(v.clone())))
.collect();
let back = mob_from_nbt(&tag, &types, 2).unwrap();
assert_eq!((back.extra.color, back.extra.sheared), (14, true));
}
}
+1
View File
@@ -121,6 +121,7 @@ mod pumpkin;
mod raids;
mod recipe_book;
mod remote;
mod remote_mob_data;
mod remote_objects;
mod remote_projectiles;
mod remote_stations;
@@ -343,8 +343,12 @@ impl Game<'_> {
"on_ground": m.on_ground,
"variant": m.extra.variant,
"color": m.extra.color,
"sheared": m.extra.sheared,
"burning": m.fire_ticks > 0,
"size": m.extra.size,
"leash": m.extra.leash.map(|h| format!("{h:?}")),
"tame": m.extra.tame,
"sitting": m.extra.sitting,
"temper": m.extra.variant3,
"chested": m.extra.chested,
"head": m.extra.head.as_deref(),
+1
View File
@@ -2697,6 +2697,7 @@ impl Game<'_> {
velocity: [d.velocity.x, d.velocity.y, d.velocity.z],
data: 0,
meta,
defaults: Vec::new(),
equipment: Vec::new(),
attributes: Vec::new(),
precise: false,
+24 -7
View File
@@ -91,7 +91,7 @@ pub(super) fn entity_uuid(id: u32) -> u128 {
/// The SynchedEntityData index of the baby flag: AgeableMob.DATA_BABY_ID and
/// Zombie.DATA_BABY_ID are both the first entry after Mob's (16); Piglin's
/// comes after AbstractPiglin's zombification flag (17).
fn baby_index(kind: &str) -> Option<u8> {
pub(super) fn baby_index(kind: &str) -> Option<u8> {
match kind {
"minecraft:piglin" => Some(17),
"minecraft:cow"
@@ -139,7 +139,13 @@ fn baby_index(kind: &str) -> Option<u8> {
/// A mob's synched data as ServerEntity sends it (only the values that differ
/// from the defaults the client constructs), with vanilla's entry indices:
/// Entity 0..=7, LivingEntity 8..=14, Mob 15, then the subclasses.
fn mob_meta(m: &Mob, hub: &Hub, meta: &mut Vec<(u8, i32, Value)>) {
/// `defaults` gets the defaults of the entries that can go back to theirs.
fn mob_meta(
m: &Mob,
hub: &Hub,
meta: &mut Vec<(u8, i32, Value)>,
defaults: &mut Vec<(u8, i32, Value)>,
) {
let kind = m.kind.id.as_str();
if m.fire_ticks > 0 {
meta.push((0, serializer::BYTE, Value::Byte(1)));
@@ -159,15 +165,18 @@ fn mob_meta(m: &Mob, hub: &Hub, meta: &mut Vec<(u8, i32, Value)>) {
if health != 1.0 {
meta.push((9, serializer::FLOAT, Value::Float(health)));
}
defaults.push((9, serializer::FLOAT, Value::Float(1.0)));
// Mob.DATA_MOB_FLAGS_ID: no AI 1, left-handed 2.
let flags = i8::from(m.no_ai) | i8::from(m.extra.left_handed) << 1;
if flags != 0 {
meta.push((15, serializer::BYTE, Value::Byte(flags)));
}
if m.is_baby()
&& let Some(index) = baby_index(kind)
{
meta.push((index, serializer::BOOLEAN, Value::Bool(true)));
// AgeableMob.DATA_BABY_ID (and Zombie's, Piglin's).
if let Some(index) = baby_index(kind) {
if m.is_baby() {
meta.push((index, serializer::BOOLEAN, Value::Bool(true)));
}
defaults.push((index, serializer::BOOLEAN, Value::Bool(false)));
}
let e = &m.extra;
let id = |registry: &str, name: &str| hub.registry_id(registry, &format!("minecraft:{name}"));
@@ -178,6 +187,7 @@ fn mob_meta(m: &Mob, hub: &Hub, meta: &mut Vec<(u8, i32, Value)>) {
if value != 0 {
meta.push((18, serializer::BYTE, Value::Byte(value as i8)));
}
defaults.push((18, serializer::BYTE, Value::Byte(0)));
}
"minecraft:cat" | "minecraft:wolf" => {
// TamableAnimal.DATA_FLAGS_ID: sitting 1, tame 4.
@@ -200,6 +210,13 @@ fn mob_meta(m: &Mob, hub: &Hub, meta: &mut Vec<(u8, i32, Value)>) {
if let Some(v) = id(registry, name) {
meta.push((index, serializer, Value::Id(v)));
}
// Wolf.DATA_COLLAR_COLOR and Cat's, red by default.
let collar = if kind == "minecraft:cat" { 23 } else { 21 };
let red = i32::from(horizon_client::mobs::tame::RED);
if i32::from(e.color & 15) != red {
meta.push((collar, serializer::INT, Value::Int(i32::from(e.color & 15))));
}
defaults.push((collar, serializer::INT, Value::Int(red)));
}
"minecraft:horse"
| "minecraft:donkey"
@@ -766,7 +783,7 @@ impl Game<'_> {
e.on_ground = m.on_ground;
e.velocity = [m.velocity.x, m.velocity.y, m.velocity.z];
e.needs_sync = m.needs_sync;
mob_meta(m, hub, &mut e.meta);
mob_meta(m, hub, &mut e.meta, &mut e.defaults);
mob_equipment(m, hub, &mut e.equipment);
self.mob_attributes(m, &mut e.attributes);
}
@@ -36,6 +36,7 @@ fn state(id: u32, kind: &str, position: [f64; 3], yaw: f32, on_ground: bool) ->
velocity: [0.0; 3],
data: 0,
meta: Vec::new(),
defaults: Vec::new(),
equipment: Vec::new(),
attributes: Vec::new(),
precise: false,
+4 -4
View File
@@ -1334,6 +1334,7 @@ impl Game<'_> {
}
if let Some(t) = mob_type {
let mut mob = Mob::new(id as u32, t, at, head);
super::remote_mob_data::client_defaults(&mut mob);
(mob.yaw, mob.previous_yaw) = (yaw, yaw);
(mob.head_pitch, mob.previous_head_pitch) = (pitch, pitch);
mob.persistent = true;
@@ -1909,13 +1910,12 @@ impl Game<'_> {
&& m.species() == horizon_client::mobs::Species::Rabbit
{
for (index, _, value) in &p.values {
match (index, value) {
(15, Value::Byte(flags)) => m.no_ai = flags & 1 != 0,
(16, Value::Bool(baby)) => m.extra.age = if *baby { -1 } else { 0 },
_ => {}
if let (15, Value::Byte(flags)) = (index, value) {
m.no_ai = flags & 1 != 0;
}
}
}
self.remote_mob_data(p.id, &p.values);
if let Some(m) = self.mobs.iter_mut().find(|m| m.id == p.id as u32)
&& m.species() == horizon_client::mobs::Species::Creeper
{
@@ -0,0 +1,136 @@
//! A server's mobs as their synched data has them
//! (ClientPacketListener.handleSetEntityData, then each entity's
//! `onSyncedDataUpdated`): what a client draws from it rather than from its
//! own simulation, which a client of a server doesn't run.
use super::Game;
use horizon_client::mobs::{Mob, Species, tame};
use horizon_protocol::entity_data::Value;
/// The values `apply` takes from one SetEntityData packet, by vanilla's entry
/// indices (Entity 0..=7, LivingEntity 8..=14, Mob 15, then the subclasses).
fn apply(m: &mut Mob, values: &[(u8, i32, Value)]) {
let species = m.species();
let baby = super::lan::baby_index(&m.kind.id);
for (index, _, value) in values {
match (*index, value) {
// Entity.DATA_SHARED_FLAGS_ID's FLAG_ONFIRE: Entity.isOnFire on a
// client, which draws the flames. A client doesn't count the
// fire down: the flag goes off when the server's fire is out.
(0, Value::Byte(flags)) => m.fire_ticks = i32::from(flags & 1),
// LivingEntity.DATA_HEALTH_ID: the boss bars and the death
// animation follow it.
(9, Value::Float(health)) => m.health = *health,
(i, Value::Bool(b)) if Some(i) == baby => m.extra.age = if *b { -1 } else { 0 },
_ => {}
}
match (species, *index, value) {
// Sheep.DATA_WOOL_ID: the colour in the low nibble, 16 sheared.
(Species::Sheep, 18, Value::Byte(wool)) => {
m.extra.color = (*wool & 15) as u8;
m.extra.sheared = wool & 16 != 0;
}
// TamableAnimal.DATA_FLAGS_ID: sitting 1, tame 4.
(Species::Wolf | Species::Cat | Species::Parrot, 18, Value::Byte(flags)) => {
m.extra.sitting = flags & 1 != 0;
m.extra.tame = flags & 4 != 0;
}
// Wolf.DATA_COLLAR_COLOR and Cat's.
(Species::Wolf, 21, Value::Int(c)) | (Species::Cat, 23, Value::Int(c)) => {
m.extra.color = (*c & 15) as u8;
}
// AbstractCubeMob.ID_SIZE: its size and box (refreshDimensions).
(Species::Slime | Species::MagmaCube, 18, Value::Int(size)) => {
m.extra.size = (*size).clamp(1, 127);
}
_ => {}
}
}
}
impl Game<'_> {
/// SetEntityData for a mob of the server's.
pub(super) fn remote_mob_data(&mut self, id: i32, values: &[(u8, i32, Value)]) {
if let Some(m) = self.mobs.iter_mut().find(|m| m.id == id as u32) {
apply(m, values);
}
}
}
/// A mob as a client constructs it before its data arrives: the synched
/// defaults the server leaves out (`getNonDefaultValues`) that differ from
/// what `Mob::new` gives, such as a wolf's and a cat's red collar.
pub(super) fn client_defaults(m: &mut Mob) {
if matches!(m.species(), Species::Wolf | Species::Cat) {
m.extra.color = tame::RED;
}
}
#[cfg(test)]
mod tests {
use super::*;
use horizon_protocol::entity_data::serializer as s;
/// A mob of the prepared resources' type `kind`, as a client spawns it
/// (None without the resources).
fn mob(kind: &str) -> Option<Mob> {
let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
.join("../../.local/horizon-client")
.join(horizon_core::VANILLA_VERSION);
let types = horizon_client::mobs::MobTypes::load(&root).ok()?;
let t = std::sync::Arc::new(types.types.get(kind)?.clone());
let mut m = Mob::new(1, t, horizon_core::geometry::Vec3::ZERO, 0.0);
client_defaults(&mut m);
Some(m)
}
#[test]
fn a_sheep_takes_its_wool_and_a_calf_its_size() {
let Some(mut m) = mob("minecraft:sheep") else {
return;
};
apply(&mut m, &[(18, s::BYTE, Value::Byte(14 | 16))]);
assert_eq!((m.extra.color, m.extra.sheared), (14, true));
apply(&mut m, &[(18, s::BYTE, Value::Byte(0))]);
assert_eq!((m.extra.color, m.extra.sheared), (0, false));
let mut calf = mob("minecraft:cow").unwrap();
apply(&mut calf, &[(16, s::BOOLEAN, Value::Bool(true))]);
assert!(calf.is_baby());
apply(&mut calf, &[(16, s::BOOLEAN, Value::Bool(false))]);
assert!(!calf.is_baby());
}
#[test]
fn a_wolf_takes_its_owner_flags_and_collar() {
let Some(mut m) = mob("minecraft:wolf") else {
return;
};
assert_eq!(m.extra.color, tame::RED);
apply(
&mut m,
&[
(18, s::BYTE, Value::Byte(4 | 1)),
(21, s::INT, Value::Int(11)),
],
);
assert!(m.extra.tame && m.extra.sitting);
assert_eq!(m.extra.color, 11);
}
#[test]
fn fire_health_and_size_follow_the_server() {
let Some(mut m) = mob("minecraft:slime") else {
return;
};
apply(
&mut m,
&[
(0, s::BYTE, Value::Byte(1)),
(9, s::FLOAT, Value::Float(12.5)),
(18, s::INT, Value::Int(4)),
],
);
assert_eq!((m.fire_ticks, m.health, m.extra.size), (1, 12.5, 4));
apply(&mut m, &[(0, s::BYTE, Value::Byte(0))]);
assert_eq!(m.fire_ticks, 0);
}
}
+33 -1
View File
@@ -50,6 +50,10 @@ pub struct EntityState {
pub data: i32,
/// SynchedEntityData entries that differ from the defaults.
pub meta: Vec<(u8, i32, Value)>,
/// The defaults of entries `meta` leaves out while they are at them,
/// sent when one goes back to its default (a calf grown up, a mob healed
/// back to 1, wool grown back white) beyond Entity's own below.
pub defaults: Vec<(u8, i32, Value)>,
/// EquipmentSlot ordinals (0 main hand, 1 off hand, 2 feet, 3 legs,
/// 4 chest, 5 head, 6 body, 7 saddle) and their stacks.
pub equipment: Vec<(u8, Option<Stack>)>,
@@ -78,6 +82,7 @@ impl EntityState {
self.velocity = [0.0; 3];
self.data = 0;
self.meta.clear();
self.defaults.clear();
self.equipment.clear();
self.attributes.clear();
self.precise = false;
@@ -469,7 +474,10 @@ impl ServerEntity {
(0, serializer::BYTE) => Value::Byte(0),
(6, serializer::POSE) => Value::Id(0),
(14, serializer::OPTIONAL_BLOCK_POS) => Value::OptPos(None),
_ => continue,
_ => match e.defaults.iter().find(|d| (d.0, d.1) == (*index, *kind)) {
Some(d) => d.2.clone(),
None => continue,
},
};
if !e.meta.iter().any(|m| m.0 == *index) {
changed.push((*index, *kind, default));
@@ -855,6 +863,7 @@ mod tests {
velocity: [0.0; 3],
data: 0,
meta: Vec::new(),
defaults: Vec::new(),
equipment: Vec::new(),
attributes: Vec::new(),
precise: false,
@@ -1075,6 +1084,29 @@ mod tests {
assert!(changes(&mut s, &e).is_empty());
}
#[test]
fn a_value_back_at_a_listed_default_is_sent() {
let mut e = state(0.0);
e.defaults = vec![(16, serializer::BOOLEAN, Value::Bool(false))];
// A calf: paired with its baby flag, then grown up.
e.meta = vec![(16, serializer::BOOLEAN, Value::Bool(true))];
let mut s = added(&e);
changes(&mut s, &e);
e.meta.clear();
let data = changes(&mut s, &e)
.into_iter()
.find_map(|p| match p {
play::Clientbound::SetEntityData(d) => Some(d),
_ => None,
})
.expect("growing up is sent");
assert_eq!(
data.values,
vec![(16, serializer::BOOLEAN, Value::Bool(false))]
);
assert!(changes(&mut s, &e).is_empty());
}
#[test]
fn metadata_and_equipment_send_only_the_changes() {
let mut e = state(0.0);
+1
View File
@@ -1559,6 +1559,7 @@ impl Hub {
velocity: [0.0; 3],
data: 0,
meta,
defaults: Vec::new(),
equipment,
attributes,
precise: false,
+1
View File
@@ -430,6 +430,7 @@ fn guests_see_each_other_and_the_world_entities() {
velocity: [0.0; 3],
data: 0,
meta: Vec::new(),
defaults: Vec::new(),
equipment: Vec::new(),
attributes: Vec::new(),
precise: false,
+81 -2
View File
@@ -24,6 +24,11 @@ address. The script then checks, from both sides, what a guest's game used to ge
- arrows: the guest and the host shoot each other with a bow; with the pvp game rule off, nothing (#484);
- looks: mobs look on both sides as the server has them (their synched data): a calf is a
baby, a red sheep is sheared, a size 4 slime, a tamed wolf sits with its blue collar, a
cow on fire burns and goes out; then the wither's health drops when it is hurt, the
sheep is dyed blue with its wool back and the calf grows up (#1367, #1368, #1370,
#1371, #1385, #1390);
- respawn: a player killed is drawn dead by the other side, and alive again once it respawns (the
respawned player is a new entity to the others); the host dies, and on the server thread
the guest too;
@@ -201,7 +206,7 @@ ROOT = Path(__file__).resolve().parents[1]
GUEST_NAME = 'Guest'
# The host plays single player on its server thread (--server-thread).
SERVER_THREAD = False
CHECKS = ['tab', 'self', 'armour', 'nametags', 'walls', 'chest', 'crafting', 'sign', 'damage', 'mobs', 'hazards', 'pvp', 'arrows', 'kills', 'hurt', 'respawn', 'containers', 'feedback', 'titles', 'chat', 'commands', 'recipes', 'machines', 'brewing', 'loom', 'stonecutter', 'grindstone', 'anvil', 'smithing', 'enchanting', 'beacon', 'crafter', 'lectern', 'cartography', 'trials', 'clicks', 'sleep', 'predict', 'push', 'eat', 'eating', 'xp', 'objects', 'projectiles', 'worn', 'blast', 'barter', 'deflect', 'fireball', 'light', 'time', 'swings', 'cracks', 'plates', 'effects', 'portals', 'distance', 'growth', 'flight', 'ladder', 'boats', 'minecarts', 'frames', 'lightning', 'riding', 'mounts', 'worldspawn', 'beds', 'shield', 'deathmining', 'contacts', 'absorption', 'breath', 'lava', 'levels', 'drops', 'underwater']
CHECKS = ['tab', 'self', 'armour', 'nametags', 'walls', 'chest', 'crafting', 'sign', 'damage', 'mobs', 'hazards', 'pvp', 'arrows', 'kills', 'hurt', 'looks', 'respawn', 'containers', 'feedback', 'titles', 'chat', 'commands', 'recipes', 'machines', 'brewing', 'loom', 'stonecutter', 'grindstone', 'anvil', 'smithing', 'enchanting', 'beacon', 'crafter', 'lectern', 'cartography', 'trials', 'clicks', 'sleep', 'predict', 'push', 'eat', 'eating', 'xp', 'objects', 'projectiles', 'worn', 'blast', 'barter', 'deflect', 'fireball', 'light', 'time', 'swings', 'cracks', 'plates', 'effects', 'portals', 'distance', 'growth', 'flight', 'ladder', 'boats', 'minecarts', 'frames', 'lightning', 'riding', 'mounts', 'worldspawn', 'beds', 'shield', 'deathmining', 'contacts', 'absorption', 'breath', 'lava', 'levels', 'drops', 'underwater']
class Game:
@@ -1147,6 +1152,79 @@ def check_hurt(host, guest, out):
return seen
def mob_looks(game, centre):
"""What `check_looks` compares of each mob around `centre`, by kind and column."""
found = {}
for m in game.raw('mobs', 32).get('near', []):
if abs(m['pos'][0] - centre[0]) > 12 or abs(m['pos'][2] - centre[2]) > 14:
continue
key = f"{m['kind'].removeprefix('minecraft:')}@{round(m['pos'][0] - centre[0])}"
found[key] = {'baby': m['baby'], 'color': m['color'], 'sheared': m['sheared'], 'size': m['size'],
'tame': m['tame'], 'sitting': m['sitting'], 'burning': m['burning'],
'health': round(m['health'])}
return found
def check_looks(host, guest, out):
x, y, z = (int(v // 1) for v in pos_of(host))
centre = (x + 0.5, y, z + 0.5)
# Each mob in a column of its own (the key), standing on the stone floor.
looks = {
'cow@-5': ('{NoAI:1b,Fire:80s}', {'burning': True}),
'cow@-3': ('{NoAI:1b,Age:-24000}', {'baby': True}),
'cow@-1': ('{NoAI:1b}', {'baby': False}),
'sheep@1': ('{NoAI:1b,Color:14b,Sheared:1b}', {'color': 14, 'sheared': True}),
'slime@3': ('{NoAI:1b,Size:3}', {'size': 4}),
'wolf@5': ('{NoAI:1b,Owner:[I;1,2,3,4],Sitting:1b,CollarColor:11b}',
{'tame': True, 'sitting': True, 'color': 11}),
}
sides = {'host': host, 'guest': guest}
seen = {}
try:
for key, (tag, _) in looks.items():
kind, dx = key.split('@')
host('command', command=f'summon minecraft:{kind} {centre[0] + int(dx)} {y} {z + 4.5} {tag}')
host('command', command=f'summon minecraft:wither {centre[0]} {y + 3} {z + 10.5} {{NoAI:1b,Invul:0}}')
host.wait(30)
seen['spawned'] = {name: mob_looks(g, centre) for name, g in sides.items()}
# Changes after the spawn: the wither hurt, the sheep dyed and grown back, the calf grown up.
host('command', command='damage @e[type=minecraft:wither,limit=1] 150 minecraft:generic')
for kind, dx, tag in (('sheep', 1, '{Color:11b,Sheared:0b}'), ('cow', -3, '{Age:0}')):
host('command', command=f'data merge entity @e[type=minecraft:{kind},x={centre[0] + dx},y={y},'
f'z={z + 4.5},distance=..0.5,limit=1] {tag}')
guest.raw('look-at', centre[0], y + 1, z + 4.5)
host.raw('look-at', centre[0], y + 1, z + 4.5)
# The fire (80 ticks) goes out in the meantime.
host.wait(80)
for name, g in sides.items():
g.shot(out, 'looks')
seen['later'] = {name: mob_looks(g, centre) for name, g in sides.items()}
finally:
# A killed slime splits: shrink it first so no children are left hopping into the next check.
host('command', command=f'data merge entity @e[type=minecraft:slime,x={centre[0] + 3},y={y},z={z + 4.5},'
f'distance=..2,limit=1] {{Size:0}}')
host('command', command=f'kill @e[type=!minecraft:player,x={x - 12},y={y - 2},z={z - 2},dx=24,dy=12,dz=16]')
wrong = []
for name in sides:
spawned, later = seen['spawned'][name], seen['later'][name]
for key, (_, want) in looks.items():
got = spawned.get(key)
if got is None or any(got[k] != v for k, v in want.items()):
wrong.append(f'{name} {key}: {got}, wants {want}')
if later.get('cow@-5', {}).get('burning') is not False:
wrong.append(f"{name}: the cow's fire never went out: {later.get('cow@-5')}")
if [later.get('sheep@1', {}).get(k) for k in ('color', 'sheared')] != [11, False]:
wrong.append(f"{name}: the sheep dyed blue with its wool back: {later.get('sheep@1')}")
if later.get('cow@-3', {}).get('baby') is not False:
wrong.append(f"{name}: the calf grown up: {later.get('cow@-3')}")
withers = [v['health'] for k, v in spawned.items() if k.startswith('wither')]
hurt = [v['health'] for k, v in later.items() if k.startswith('wither')]
if withers != [300] or hurt != [150]:
wrong.append(f"{name}: the wither's health {withers} then {hurt}, wants [300] then [150]")
assert not wrong, '\n'.join(wrong)
return seen['later']['guest']
def container_items(game):
"""The open container's stacks by slot (Horizon's container slots are 300 and up) and its size."""
slots = [s for s in game('screen').get('slots', []) if s.get('slot', 0) >= 300]
@@ -3826,7 +3904,8 @@ CHECK_FNS = {'tab': check_tab, 'self': check_self, 'armour': check_armour,
'worldspawn': check_world_spawn, 'beds': check_beds, 'shield': check_shield, 'deathmining': check_death_mining,
'contacts': check_contacts, 'absorption': check_absorption, 'breath': check_breath,
'lava': check_lava, 'levels': check_levels, 'drops': check_drops,
'underwater': check_underwater}
'underwater': check_underwater,
'looks': check_looks}
def run(ctl, out, resources, checks):