ghast-client 0.5.6

Headless Minecraft Java Edition client for the ghast library: connection, login, fixed 50 ms tick loop and a version-agnostic bot API (1.8.9, 1.12.2, 1.16.5, 26.1, 26.2 and 26.3)
Documentation
//! 1.8.9: our own entity's data (the flags byte movement reads).

use super::*;

impl Sim18 {
    /// `entity_metadata`: only our own entity's flags byte (index 0) is read. Vanilla's data
    /// watcher writes it into the local player too (`NetHandlerPlayClient.handleEntityMetadata`):
    /// the sprint bit sets the flag `isSprinting()` reads (`Entity.setFlag(3)`, not
    /// `setSprinting`: the speed modifier stays until the client's own movement update changes
    /// it). Sneaking is the input's on the 1.8 client (`isSneaking()`), the other bits are not
    /// read by movement.
    pub(super) fn own_metadata(&mut self, raw: &RawPacket) -> Result<(), SimError> {
        use ghast_protocol::defs::p47::types::EntityMetadataValue as V;
        use ghast_protocol::v1_8::play::clientbound as cb;
        let Some(own) = self.own_id else {
            return Ok(());
        };
        let id = ghast_protocol::Reader::new(&raw.body).read_varint()?;
        if let Some(r) = self.ride.as_deref_mut()
            && r.id == id
            && let Seat18::Mount(m) = &mut r.seat
        {
            // The mount's entity data index 16: horse flags (int), pig saddle (byte).
            let p: cb::EntityMetadata = raw.decode_as()?;
            for e in &p.metadata {
                match (e.key, &e.value) {
                    (16, V::Int(f)) => m.set_flags(*f),
                    (16, V::Byte(b)) => m.set_flags(i32::from(*b)),
                    _ => {}
                }
            }
            return Ok(());
        }
        if id != own {
            return Ok(());
        }
        let p: cb::EntityMetadata = raw.decode_as()?;
        for e in &p.metadata {
            // PlayerEntity.setAbsorption: index 17.
            if let (17, V::Float(a)) = (e.key, &e.value) {
                self.absorption = *a;
                self.absorption_dirty = true;
            }
            if let (0, V::Byte(b)) = (e.key, &e.value) {
                let flags = *b as u8;
                self.server_flags = Some(flags);
                self.player.sprinting = flags & 0x08 != 0;
                if let Some(r) = &mut self.rec {
                    r.note("own entity flags not representable");
                }
            }
        }
        Ok(())
    }
}