11use azalea:: {
2- BlockPos , SprintDirection , WalkDirection ,
2+ BlockPos , Client as AzaleaClient , SprintDirection , WalkDirection ,
33 core:: { entity_id:: MinecraftEntityId , hit_result:: HitResult } ,
44 entity:: Position ,
55 interact:: pick:: HitResultComponent ,
@@ -12,6 +12,7 @@ use azalea::{
1212use mlua:: { FromLua , Lua , Result , Table , UserDataRef , Value } ;
1313
1414use super :: { Client , Direction , Vec3 } ;
15+ use crate :: unpack;
1516
1617#[ derive( Debug ) ]
1718struct AnyGoal ( Box < dyn Goal > ) ;
@@ -27,7 +28,7 @@ impl Goal for AnyGoal {
2728}
2829
2930#[ allow( clippy:: cast_possible_truncation) ]
30- fn to_goal ( lua : & Lua , client : & Client , data : Table , kind : u8 ) -> Result < AnyGoal > {
31+ fn to_goal ( lua : & Lua , client : & AzaleaClient , data : Table , kind : u8 ) -> Result < AnyGoal > {
3132 let goal: Box < dyn Goal > = match kind {
3233 1 => {
3334 let pos = Vec3 :: from_lua ( data. get ( "position" ) ?, lua) ?;
@@ -68,6 +69,7 @@ pub fn go_to_reached(_lua: &Lua, client: &Client) -> Result<bool> {
6869}
6970
7071pub async fn wait_until_goal_reached ( _lua : Lua , client : UserDataRef < Client > , ( ) : ( ) ) -> Result < ( ) > {
72+ let client = unpack ! ( client) ;
7173 client. wait_until_goto_target_reached ( ) . await ;
7274 Ok ( ( ) )
7375}
@@ -77,6 +79,8 @@ pub async fn go_to(
7779 client : UserDataRef < Client > ,
7880 ( data, metadata) : ( Table , Option < Table > ) ,
7981) -> Result < ( ) > {
82+ let client = unpack ! ( client) ;
83+
8084 let metadata = metadata. unwrap_or ( lua. create_table ( ) ?) ;
8185 let options = metadata. get ( "options" ) . unwrap_or ( lua. create_table ( ) ?) ;
8286 let goal = to_goal (
@@ -85,12 +89,13 @@ pub async fn go_to(
8589 data,
8690 metadata. get ( "type" ) . unwrap_or_default ( ) ,
8791 ) ?;
88- if options. get ( "without_mining" ) . unwrap_or_default ( ) {
89- client. start_goto_with_opts ( goal, PathfinderOpts :: new ( ) . allow_mining ( false ) ) ;
90- client. wait_until_goto_target_reached ( ) . await ;
91- } else {
92- client. goto ( goal) . await ;
93- }
92+ client
93+ . goto_with_opts (
94+ goal,
95+ PathfinderOpts :: new ( ) . allow_mining ( options. get ( "without_mining" ) . unwrap_or_default ( ) ) ,
96+ )
97+ . await ;
98+
9499 Ok ( ( ) )
95100}
96101
@@ -99,6 +104,8 @@ pub async fn start_go_to(
99104 client : UserDataRef < Client > ,
100105 ( data, metadata) : ( Table , Option < Table > ) ,
101106) -> Result < ( ) > {
107+ let client = unpack ! ( client) ;
108+
102109 let metadata = metadata. unwrap_or ( lua. create_table ( ) ?) ;
103110 let options = metadata. get ( "options" ) . unwrap_or ( lua. create_table ( ) ?) ;
104111 let goal = to_goal (
0 commit comments