use super::*;
mod data_index {
pub(super) const HOOKED: u8 = 8;
pub(super) const BITING: u8 = 9;
}
impl ModernSim {
pub(super) fn fishing_packet_ids(&self) -> &'static [i32] {
use super::proto::play::clientbound as cb;
if self.fishing.active() {
&[cb::id::ENTITY_METADATA]
} else {
&[]
}
}
#[cold]
#[inline(never)]
pub(super) fn fishing_packet(&mut self, raw: &RawPacket) -> Result<(), SimError> {
use super::proto::play::clientbound as cb;
use super::proto::types::EntityMetadataEntryValue as V;
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 {
r.skip(16)?; let ty = r.read_varint()?;
let bobber = u16::try_from(ty)
.ok()
.and_then(super::data::entity_type)
.is_some_and(|t| t.name == "fishing_bobber");
let changed = match t.get(id) {
Some(e) if bobber => self
.fishing
.spawned(id, e.data(), self.own.id, e.position()),
_ => self.fishing.id() == Some(id) && self.fishing.gone(),
};
if changed {
self.filter_dirty = 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::Int(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| {
modern::projectile::bobber_liquid_height::<Rules, _>(world, p) > 0.0
});
if gone {
self.filter_dirty = true;
}
}
}