use super::*;
use ghast_entity::EntityType;
const SPLASH: &str = "random.splash";
const WINDOW: u8 = 10;
const BOBBER: EntityType = EntityType::LegacyObject(90);
impl Sim18 {
#[cold]
#[inline(never)]
pub(super) fn fishing_packet(&mut self, raw: &RawPacket) -> Result<(), SimError> {
use ghast_protocol::v1_8::play::clientbound as cb;
let Some(t) = &self.entities else {
return Ok(());
};
if raw.id == cb::id::NAMED_SOUND_EFFECT {
let p: cb::NamedSoundEffect = raw.decode_as()?;
if &*p.sound_name == 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()?;
let Some(own) = self.own_id else {
return Ok(());
};
let changed = match t.get(id) {
Some(e) if e.entity_type() == BOBBER => {
self.fishing.spawned(id, e.data(), own, e.position())
}
_ => self.fishing.id() == Some(id) && self.fishing.gone(),
};
if changed {
self.filter_dirty = true;
}
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_8::projectile::water_at(world, p));
if gone {
self.filter_dirty = true;
}
}
}