ghast-client 0.5.4

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.16.5: the bot's own fishing bobber ([`crate::fishing`]): the spawn whose object data is
//! our entity id (`ClientPlayNetworkHandler.onEntitySpawn` makes it the owner's `fishHook`),
//! the synced hooked-entity id and `CAUGHT_FISH` (the bite), and the bobber's removal.

use super::*;

/// `FishingBobberEntity` entity data (1.16.5: `Entity` defines 0 – 6).
mod data_index {
    /// `HOOK_ENTITY_ID` (entity id + 1).
    pub(super) const HOOKED: u8 = 7;
    /// `CAUGHT_FISH`.
    pub(super) const BITING: u8 = 8;
}

impl Sim16 {
    /// A spawn or (our bobber's) entity data packet, after the tracker applied it.
    #[cold]
    #[inline(never)]
    pub(super) fn fishing_packet(&mut self, raw: &RawPacket) -> Result<(), SimError> {
        use ghast_protocol::defs::p754::types::EntityMetadataValue as V;
        use ghast_protocol::v1_16_5::play::clientbound as cb;
        let Some(t) = &self.entities else {
            return Ok(());
        };
        let mut r = ghast_protocol::Reader::new(&raw.body);
        let id = r.read_varint()?;
        if raw.id == cb::id::SPAWN_ENTITY {
            let Some(e) = t.get(id) else {
                return Ok(());
            };
            let bobber = ghast_entity::v1_16_5::info(e.entity_type())
                .is_some_and(|i| i.name == "fishing_bobber");
            let changed = if bobber {
                self.fishing
                    .spawned(id, e.data(), self.rt.own_id, e.position())
            } else {
                // another entity under our bobber's id: ours is gone
                self.fishing.id() == Some(id) && self.fishing.gone()
            };
            if changed {
                self.rt.held.filter_dirty.set(true);
            }
            return Ok(());
        }
        if self.fishing.id() != Some(id) {
            return Ok(());
        }
        let p: cb::EntityMetadata = raw.decode_as()?;
        for m in &p.metadata {
            match (m.key, &m.value) {
                (data_index::HOOKED, V::VarInt(h)) => self.fishing.hooked(*h),
                (data_index::BITING, V::Boolean(b)) => self.fishing.biting(*b),
                _ => {}
            }
        }
        Ok(())
    }

    /// One client tick with our bobber: its tracked position and state.
    #[cold]
    #[inline(never)]
    pub(super) fn tick_fishing(&mut self) {
        let pos = self
            .fishing
            .id()
            .and_then(|id| self.entities.as_ref()?.get(id))
            .map(ghast_entity::Entity::position);
        let world = &self.world;
        let gone = self.fishing.tick(pos, |p| {
            ghast_physics::v1_16_5::projectile::bobber_liquid_height(world, p) > 0.0
        });
        if gone {
            self.rt.held.filter_dirty.set(true);
        }
    }
}