1
+ use std:: rc:: Rc ;
2
+ use std:: time:: Duration ;
3
+
1
4
use packets:: types:: UUID ;
5
+ use tokio:: sync:: Notify ;
2
6
3
- use crate :: client:: runner:: GlobalState ;
4
- use crate :: protocol:: McProtocol ;
5
- use crate :: storage:: world:: WorldBlocks ;
6
- use crate :: types:: Location ;
7
- use crate :: storage:: block:: BlockLocation ;
8
- // use crate::client::pathfind::bidirectional::a_star_bi;
9
- use crate :: client:: pathfind:: progress_checker:: { NoVehicleProgressor , NoVehicleHeuristic , NoVehicleGoalCheck , GoalCheck } ;
7
+ use crate :: client:: follow:: Follower ;
10
8
use crate :: client:: pathfind:: context:: { GlobalContext , MoveContext } ;
11
9
use crate :: client:: pathfind:: incremental:: { AStar , PathResult } ;
12
- use std :: time :: Duration ;
10
+ use crate :: client :: pathfind :: progress_checker :: { GoalCheck , NoVehicleGoalCheck , NoVehicleHeuristic , NoVehicleProgressor } ;
13
11
use crate :: client:: timing:: Increment ;
14
- use crate :: client:: follow:: Follower ;
12
+ use crate :: protocol:: McProtocol ;
13
+ use crate :: storage:: block:: BlockLocation ;
14
+ use crate :: storage:: world:: WorldBlocks ;
15
+ use crate :: types:: Location ;
16
+ use crate :: client:: state:: local:: State ;
17
+ use crate :: client:: state:: global:: GlobalState ;
18
+
15
19
16
20
#[ derive( Debug ) ]
17
21
pub struct ClientInfo {
@@ -20,25 +24,21 @@ pub struct ClientInfo {
20
24
pub entity_id : u32 ,
21
25
}
22
26
23
-
24
- pub struct State {
25
- pub ticks : usize ,
26
- pub info : ClientInfo ,
27
- pub destination : BlockLocation ,
28
- pub alive : bool ,
29
- pub follower : Option < Follower > ,
30
- pub finder_problem : Option < TravelProblem > ,
31
- pub location : Location
32
- }
33
-
34
27
pub struct TravelPath {
35
- blocks : Vec < BlockLocation >
28
+ blocks : Vec < BlockLocation > ,
36
29
}
37
30
38
31
pub struct TravelProblem {
39
- a_star : AStar < MoveContext > ,
40
- heuristic : NoVehicleHeuristic ,
41
- goal_checker : NoVehicleGoalCheck
32
+ pub a_star : AStar < MoveContext > ,
33
+ pub heuristic : NoVehicleHeuristic ,
34
+ pub goal_checker : NoVehicleGoalCheck ,
35
+ pub notifier : Rc < Notify > ,
36
+ }
37
+
38
+ impl Drop for TravelProblem {
39
+ fn drop ( & mut self ) {
40
+ self . notifier . notify_one ( ) ;
41
+ }
42
42
}
43
43
44
44
pub struct Client < T : McProtocol > {
@@ -53,20 +53,10 @@ const fn ticks_from_secs(seconds: usize) -> usize {
53
53
impl < T : McProtocol > Client < T > {
54
54
pub fn run_sync ( & mut self , global : & mut GlobalState ) {
55
55
self . move_around ( ) ;
56
- self . anti_afk ( ) ;
57
-
58
56
self . state . ticks += 1 ;
59
57
}
60
58
61
- fn anti_afk ( & mut self ) {
62
- const MESSAGE_TICKS : usize = ticks_from_secs ( 15 ) ; // every 15 seconds
63
- if self . state . ticks % MESSAGE_TICKS == 0 {
64
- // throwaway command to prevent anti afk
65
- self . protocol . send_chat ( "/wot" ) ;
66
- }
67
- }
68
-
69
- fn move_around ( & mut self ) {
59
+ fn move_around ( & mut self ) {
70
60
if self . state . ticks % 20 != 0 {
71
61
return ;
72
62
}
@@ -78,27 +68,23 @@ impl<T: McProtocol> Client<T> {
78
68
}
79
69
80
70
81
-
82
- pub fn run_threaded ( client : & mut State , global : & GlobalState ) {
83
-
84
- if let Some ( traverse) = client. finder_problem . as_mut ( ) {
85
-
71
+ pub fn run_threaded ( client : & mut State , global : & GlobalState ) {
72
+ if let Some ( traverse) = client. travel_problem . as_mut ( ) {
86
73
let ctx = GlobalContext {
87
74
path_config : & global. travel_config ,
88
- world : & global. world_blocks
75
+ world : & global. world_blocks ,
89
76
} ;
90
77
91
78
let progressor = NoVehicleProgressor :: new ( ctx) ;
92
79
93
80
let res = traverse. a_star . iterate_for ( Duration :: from_millis ( 30 ) , & traverse. heuristic , & progressor, & traverse. goal_checker ) ;
94
81
95
82
if let Increment :: Finished ( res) = res {
96
-
97
83
if let Some ( res) = res {
98
84
client. follower = Follower :: new ( res) ;
99
85
}
100
86
// we are done finding the path
101
- client. finder_problem = None ;
87
+ client. travel_problem = None ;
102
88
}
103
89
}
104
- }
90
+ }
0 commit comments