refactor(client): simplify usage with deref
This commit is contained in:
@@ -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(())
|
||||
}
|
||||
|
Reference in New Issue
Block a user