feat(item_stack): add custom consumable component
This commit is contained in:
parent
417a234cd2
commit
c9a5640436
@ -1,6 +1,6 @@
|
|||||||
use azalea::inventory::{
|
use azalea::inventory::{
|
||||||
self,
|
self,
|
||||||
components::{CustomName, Damage, Food, MaxDamage},
|
components::{Consumable, CustomName, Damage, Food, MaxDamage},
|
||||||
};
|
};
|
||||||
use mlua::{UserData, UserDataFields, UserDataMethods};
|
use mlua::{UserData, UserDataFields, UserDataMethods};
|
||||||
|
|
||||||
@ -32,6 +32,24 @@ impl UserData for ItemStack {
|
|||||||
.map(|data| data.components.get::<MaxDamage>().map(|d| d.amount)))
|
.map(|data| data.components.get::<MaxDamage>().map(|d| d.amount)))
|
||||||
});
|
});
|
||||||
|
|
||||||
|
f.add_field_method_get("consumable", |lua, this| {
|
||||||
|
Ok(
|
||||||
|
if let Some(consumable) = this
|
||||||
|
.0
|
||||||
|
.as_present()
|
||||||
|
.and_then(|data| data.components.get::<Consumable>())
|
||||||
|
{
|
||||||
|
let table = lua.create_table()?;
|
||||||
|
table.set("animation", consumable.animation as u8)?;
|
||||||
|
table.set("consume_seconds", consumable.consume_seconds)?;
|
||||||
|
table.set("has_consume_particles", consumable.has_consume_particles)?;
|
||||||
|
Some(table)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
},
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
f.add_field_method_get("food", |lua, this| {
|
f.add_field_method_get("food", |lua, this| {
|
||||||
Ok(
|
Ok(
|
||||||
if let Some(food) = this
|
if let Some(food) = this
|
||||||
|
Loading…
x
Reference in New Issue
Block a user