use std::sync::{Arc, Weak}; use pumpkin_data::entity::EntityType; use crate::entity::{ Entity, ai::goal::{ look_around::RandomLookAroundGoal, look_at_entity::LookAtEntityGoal, swim::SwimGoal, try_find_water::TryFindWaterGoal, wander_around::WanderAroundGoal, }, mob::{Mob, MobEntity}, }; /// Represents a Dolphin, a neutral aquatic mob that can give players the Dolphin's Grace effect. /// /// Wiki: pub struct DolphinEntity { pub mob_entity: MobEntity, } impl DolphinEntity { pub fn new(entity: Entity) -> Arc { let mob_entity = MobEntity::new(entity); let dolphin = Self { mob_entity }; let mob_arc = Arc::new(dolphin); let mob_weak: Weak = { let mob_arc: Arc = mob_arc.clone(); Arc::downgrade(&mob_arc) }; { let mut goal_selector = mob_arc .mob_entity .goals_selector .lock() .unwrap_or_else(std::sync::PoisonError::into_inner); goal_selector.add_goal(0, Box::new(TryFindWaterGoal)); goal_selector.add_goal(0, Box::new(SwimGoal::default())); goal_selector.add_goal(1, Box::new(WanderAroundGoal::new(1.0))); goal_selector.add_goal( 2, LookAtEntityGoal::with_default(mob_weak, &EntityType::PLAYER, 6.0), ); goal_selector.add_goal(3, Box::new(RandomLookAroundGoal::default())); }; mob_arc } } impl Mob for DolphinEntity { fn get_mob_entity(&self) -> &MobEntity { &self.mob_entity } }