steel_core/entity/ai/goal/
interact.rs1use super::look_at_player::LookAtPlayerGoal;
2use super::selector::{Goal, GoalControls};
3use crate::entity::PathfinderMob;
4use crate::entity::SharedEntity;
5
6pub struct InteractGoal {
7 look_at: LookAtPlayerGoal,
8}
9
10impl InteractGoal {
11 #[must_use]
12 pub(crate) fn new_player(look_distance: f64, probability: f32) -> Self {
13 Self {
14 look_at: LookAtPlayerGoal::new_for_players_with_controls(
15 look_distance,
16 probability,
17 false,
18 GoalControls::LOOK | GoalControls::MOVE,
19 ),
20 }
21 }
22}
23
24impl Goal for InteractGoal {
25 fn controls(&self) -> GoalControls {
26 self.look_at.controls()
27 }
28
29 fn can_use(&mut self, mob: &dyn PathfinderMob) -> bool {
30 self.look_at.can_use(mob)
31 }
32
33 fn can_continue_to_use(&mut self, mob: &dyn PathfinderMob) -> bool {
34 self.look_at.can_continue_to_use(mob)
35 }
36
37 fn start(&mut self, mob: &dyn PathfinderMob) {
38 self.look_at.start(mob);
39 }
40
41 fn stop(&mut self, mob: &dyn PathfinderMob) {
42 self.look_at.stop(mob);
43 }
44
45 fn tick(&mut self, mob: &dyn PathfinderMob, entity: &SharedEntity) {
46 self.look_at.tick(mob, entity);
47 }
48}
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn interact_goal_claims_look_and_move_controls_like_vanilla() {
56 let goal = InteractGoal::new_player(3.0, 1.0);
57
58 assert_eq!(goal.controls(), GoalControls::LOOK | GoalControls::MOVE);
59 }
60}