feat(client): add menu field

This commit is contained in:
2025-02-23 17:19:26 -05:00
parent 543f0af741
commit 9b0f8ec406
4 changed files with 48 additions and 10 deletions

View File

@@ -5,6 +5,12 @@ pub struct ItemStack {
pub inner: azalea::inventory::ItemStack,
}
impl From<azalea::inventory::ItemStack> for ItemStack {
fn from(inner: azalea::inventory::ItemStack) -> Self {
Self { inner }
}
}
impl UserData for ItemStack {
fn add_fields<F: UserDataFields<Self>>(f: &mut F) {
f.add_field_method_get("is_empty", |_, this| Ok(this.inner.is_empty()));
@@ -38,9 +44,7 @@ impl UserData for ItemStack {
fn add_methods<M: UserDataMethods<Self>>(m: &mut M) {
m.add_method_mut("split", |_, this, count: u32| {
Ok(ItemStack {
inner: this.inner.split(count),
})
Ok(ItemStack::from(this.inner.split(count)))
});
m.add_method_mut("update_empty", |_, this, (): ()| {
this.inner.update_empty();

View File

@@ -25,7 +25,7 @@ impl UserData for Container {
f.add_field_method_get("contents", |_, this| {
Ok(this.inner.contents().map(|v| {
v.iter()
.map(|i| ItemStack { inner: i.clone() })
.map(|i| ItemStack::from(i.to_owned()))
.collect::<Vec<_>>()
}))
});
@@ -58,7 +58,7 @@ impl UserData for ContainerRef {
f.add_field_method_get("contents", |_, this| {
Ok(this.inner.contents().map(|v| {
v.iter()
.map(|i| ItemStack { inner: i.clone() })
.map(|i| ItemStack::from(i.to_owned()))
.collect::<Vec<_>>()
}))
});