refactor(client): simplify usage with deref

This commit is contained in:
2025-02-18 21:34:57 -05:00
parent 93a2dda8c6
commit 75d4a9c183
7 changed files with 68 additions and 108 deletions

View File

@@ -3,18 +3,19 @@ use azalea::{
ClientInformation,
entity::metadata::{AirSupply, Score},
};
use log::error;
use mlua::{Lua, Result, Table, UserDataRef};
pub fn air_supply(_lua: &Lua, client: &Client) -> Result<i32> {
Ok(client.inner.as_ref().unwrap().component::<AirSupply>().0)
Ok(client.component::<AirSupply>().0)
}
pub fn health(_lua: &Lua, client: &Client) -> Result<f32> {
Ok(client.inner.as_ref().unwrap().health())
Ok(client.health())
}
pub fn hunger(lua: &Lua, client: &Client) -> Result<Table> {
let h = client.inner.as_ref().unwrap().hunger();
let h = client.hunger();
let hunger = lua.create_table()?;
hunger.set("food", h.food)?;
@@ -23,7 +24,7 @@ pub fn hunger(lua: &Lua, client: &Client) -> Result<Table> {
}
pub fn score(_lua: &Lua, client: &Client) -> Result<i32> {
Ok(client.inner.as_ref().unwrap().component::<Score>().0)
Ok(client.component::<Score>().0)
}
pub async fn set_client_information(
@@ -31,15 +32,14 @@ pub async fn set_client_information(
client: UserDataRef<Client>,
client_information: Table,
) -> Result<()> {
client
.inner
.as_ref()
.unwrap()
if let Err(error) = client
.set_client_information(ClientInformation {
view_distance: client_information.get("view_distance")?,
..ClientInformation::default()
})
.await
.unwrap();
{
error!("failed to set client client information: {error:?}");
}
Ok(())
}