refactor(client): simplify usage with deref
This commit is contained in:
@@ -8,31 +8,18 @@ use mlua::{Lua, Result, UserDataRef};
|
||||
|
||||
pub fn container(_lua: &Lua, client: &Client) -> Result<Option<ContainerRef>> {
|
||||
Ok(client
|
||||
.inner
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.get_open_container()
|
||||
.map(|c| ContainerRef { inner: c }))
|
||||
}
|
||||
|
||||
pub fn held_item(_lua: &Lua, client: &Client) -> Result<ItemStack> {
|
||||
Ok(ItemStack {
|
||||
inner: client
|
||||
.inner
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.component::<Inventory>()
|
||||
.held_item(),
|
||||
inner: client.component::<Inventory>().held_item(),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn held_slot(_lua: &Lua, client: &Client) -> Result<u8> {
|
||||
Ok(client
|
||||
.inner
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.component::<Inventory>()
|
||||
.selected_hotbar_slot)
|
||||
Ok(client.component::<Inventory>().selected_hotbar_slot)
|
||||
}
|
||||
|
||||
pub async fn open_container_at(
|
||||
@@ -42,9 +29,7 @@ pub async fn open_container_at(
|
||||
) -> Result<Option<Container>> {
|
||||
#[allow(clippy::cast_possible_truncation)]
|
||||
Ok(client
|
||||
.inner
|
||||
.clone()
|
||||
.unwrap()
|
||||
.open_container_at(BlockPos::new(
|
||||
position.x as i32,
|
||||
position.y as i32,
|
||||
@@ -55,12 +40,7 @@ pub async fn open_container_at(
|
||||
}
|
||||
|
||||
pub fn open_inventory(_lua: &Lua, client: &mut Client, _: ()) -> Result<Option<Container>> {
|
||||
Ok(client
|
||||
.inner
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.open_inventory()
|
||||
.map(|c| Container { inner: c }))
|
||||
Ok(client.open_inventory().map(|c| Container { inner: c }))
|
||||
}
|
||||
|
||||
pub fn set_held_slot(_lua: &Lua, client: &Client, slot: u8) -> Result<()> {
|
||||
@@ -68,7 +48,6 @@ pub fn set_held_slot(_lua: &Lua, client: &Client, slot: u8) -> Result<()> {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let client = client.inner.as_ref().unwrap();
|
||||
{
|
||||
let mut ecs = client.ecs.lock();
|
||||
let mut inventory = client.query::<&mut Inventory>(&mut ecs);
|
||||
|
Reference in New Issue
Block a user