diff --git a/src/lua/container/item_stack.rs b/src/lua/container/item_stack.rs index 8fadb69..44f3ab8 100644 --- a/src/lua/container/item_stack.rs +++ b/src/lua/container/item_stack.rs @@ -1,4 +1,4 @@ -use azalea::inventory::components::{CustomName, Damage, MaxDamage}; +use azalea::inventory::components::{CustomName, Damage, Food, MaxDamage}; use mlua::{UserData, UserDataFields, UserDataMethods}; pub struct ItemStack { @@ -36,6 +36,25 @@ impl UserData for ItemStack { .as_present() .map(|data| data.components.get::().map(|d| d.amount))) }); + + f.add_field_method_get("food", |lua, this| { + Ok( + if let Some(food) = this + .inner + .as_present() + .and_then(|data| data.components.get::()) + { + let table = lua.create_table()?; + table.set("nutrition", food.nutrition)?; + table.set("saturation", food.saturation)?; + table.set("can_always_eat", food.can_always_eat)?; + table.set("eat_seconds", food.eat_seconds)?; + Some(table) + } else { + None + }, + ) + }); } fn add_methods>(m: &mut M) {