use super::*;
use ghast_entity::EntityType;
const HOOKED: u8 = 6;
const SPLASH: i32 = 153;
const WINDOW: u8 = 20;
const BOBBER: EntityType = EntityType::LegacyObject(90);
impl Sim12 {
#[cold]
#[inline(never)]
pub(super) fn fishing_packet(&mut self, raw: &RawPacket) -> Result<(), SimError> {
use ghast_protocol::defs::p340::types::EntityMetadataValue as V;
use ghast_protocol::v1_12_2::play::clientbound as cb;
let Some(t) = &self.entities else {
return Ok(());
};
if raw.id == cb::id::SOUND_EFFECT {
let p: cb::SoundEffect = raw.decode_as()?;
if p.sound_id == SPLASH {
let pos = [
f64::from(p.x) / 8.0,
f64::from(p.y) / 8.0,
f64::from(p.z) / 8.0,
];
let me = self.fishing.id();
let others = t
.iter()
.filter(|e| e.entity_type() == BOBBER && Some(e.id()) != me)
.map(ghast_entity::Entity::position);
self.fishing.splash(pos, others, WINDOW);
}
return Ok(());
}
let mut r = ghast_protocol::Reader::new(&raw.body);
let id = r.read_varint()?;
if raw.id == cb::id::SPAWN_ENTITY {
let changed = match t.get(id) {
Some(e) if e.entity_type() == BOBBER => {
self.fishing
.spawned(id, e.data(), self.glide.own_id, e.position())
}
_ => self.fishing.id() == Some(id) && self.fishing.gone(),
};
if changed {
self.glide.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 {
if let (HOOKED, V::VarInt(h)) = (m.key, &m.value) {
self.fishing.hooked(*h);
}
}
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_12::projectile::bobber_liquid_height(world, p) > 0.0
});
if gone {
self.glide.filter_dirty = true;
}
}
}