use super::*;
mod data_index {
pub(super) const HOOKED: u8 = 7;
pub(super) const BITING: u8 = 8;
}
impl Sim16 {
#[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 {
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(())
}
#[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);
}
}
}