feat(client): add looking_at field

This commit is contained in:
Ryan 2025-02-16 20:19:01 -05:00
parent 083dd7f707
commit d6abd3fd06
Signed by: ErrorNoInternet
GPG Key ID: 2486BFB7B1E6A4A3

View File

@ -10,6 +10,7 @@ use super::{
use azalea::{ use azalea::{
Client as AzaleaClient, Client as AzaleaClient,
entity::metadata::{AirSupply, Score}, entity::metadata::{AirSupply, Score},
interact::HitResultComponent,
}; };
use mlua::{Lua, Result, UserData, UserDataFields, UserDataMethods}; use mlua::{Lua, Result, UserData, UserDataFields, UserDataMethods};
@ -49,6 +50,30 @@ impl UserData for Client {
}) })
}); });
f.add_field_method_get("looking_at", |lua, this| {
let hr = this
.inner
.as_ref()
.unwrap()
.component::<HitResultComponent>();
Ok(if hr.miss {
None
} else {
let result = lua.create_table()?;
result.set(
"position",
Vec3 {
x: f64::from(hr.block_pos.x),
y: f64::from(hr.block_pos.y),
z: f64::from(hr.block_pos.z),
},
)?;
result.set("inside", hr.inside)?;
result.set("world_border", hr.world_border)?;
Some(result)
})
});
f.add_field_method_get("position", |_, this| { f.add_field_method_get("position", |_, this| {
let p = this.inner.as_ref().unwrap().position(); let p = this.inner.as_ref().unwrap().position();
Ok(Vec3 { Ok(Vec3 {