aboutsummaryrefslogtreecommitdiff
path: root/azalea-inventory/src
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-03-13 20:46:12 +0000
committermat <git@matdoes.dev>2025-03-13 20:46:12 +0000
commit65fe07215149ab81d0862ab7edac71d6a8417ef8 (patch)
tree9e06778329cbf9a14f87c93d1a3686f6b91f2b4e /azalea-inventory/src
parent7a192acc99358818c2f90cf4e2b8b236f91cfbf7 (diff)
downloadazalea-drasl-65fe07215149ab81d0862ab7edac71d6a8417ef8.tar.xz
fix wrong Consumable component implementation and add set_equipment test
Diffstat (limited to 'azalea-inventory/src')
-rw-r--r--azalea-inventory/src/components.rs7
-rw-r--r--azalea-inventory/src/item/consume_effect.rs37
-rw-r--r--azalea-inventory/src/item/mod.rs2
3 files changed, 43 insertions, 3 deletions
diff --git a/azalea-inventory/src/components.rs b/azalea-inventory/src/components.rs
index b299664f..2ff00d5b 100644
--- a/azalea-inventory/src/components.rs
+++ b/azalea-inventory/src/components.rs
@@ -5,6 +5,7 @@ use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite, BufReadError};
use azalea_chat::FormattedText;
use azalea_core::{
filterable::Filterable, position::GlobalPos, resource_location::ResourceLocation,
+ sound::CustomSound,
};
use azalea_registry::{
Attribute, Block, ConsumeEffectKind, DataComponentKind, Enchantment, EntityKind, HolderSet,
@@ -14,7 +15,7 @@ use simdnbt::owned::{Nbt, NbtCompound};
use tracing::trace;
use uuid::Uuid;
-use crate::ItemStack;
+use crate::{ItemStack, item::consume_effect::ConsumeEffect};
pub trait DataComponent: Send + Sync + Any {
const KIND: DataComponentKind;
@@ -800,9 +801,9 @@ impl DataComponent for JukeboxPlayable {
pub struct Consumable {
pub consume_seconds: f32,
pub animation: ItemUseAnimation,
- pub sound: SoundEvent,
+ pub sound: azalea_registry::Holder<SoundEvent, CustomSound>,
pub has_consume_particles: bool,
- pub on_consuime_effects: Vec<ConsumeEffectKind>,
+ pub on_consume_effects: Vec<ConsumeEffect>,
}
impl DataComponent for Consumable {
const KIND: DataComponentKind = DataComponentKind::Consumable;
diff --git a/azalea-inventory/src/item/consume_effect.rs b/azalea-inventory/src/item/consume_effect.rs
new file mode 100644
index 00000000..898f64ff
--- /dev/null
+++ b/azalea-inventory/src/item/consume_effect.rs
@@ -0,0 +1,37 @@
+use azalea_buf::AzBuf;
+use azalea_core::resource_location::ResourceLocation;
+use azalea_registry::{HolderSet, MobEffect, SoundEvent};
+
+use crate::components::MobEffectInstance;
+
+#[derive(Clone, PartialEq, AzBuf)]
+pub enum ConsumeEffect {
+ ApplyEffects {
+ effects: Vec<MobEffectInstance>,
+ probability: f32,
+ },
+ RemoveEffects(HolderSet<MobEffect, ResourceLocation>),
+ ClearAllEffects,
+ TeleportRandomly {
+ diameter: f32,
+ },
+ PlaySound {
+ sound: SoundEvent,
+ },
+}
+
+impl From<ConsumeEffect> for azalea_registry::ConsumeEffectKind {
+ fn from(effect: ConsumeEffect) -> Self {
+ match effect {
+ ConsumeEffect::ApplyEffects { .. } => azalea_registry::ConsumeEffectKind::ApplyEffects,
+ ConsumeEffect::RemoveEffects { .. } => {
+ azalea_registry::ConsumeEffectKind::RemoveEffects
+ }
+ ConsumeEffect::ClearAllEffects => azalea_registry::ConsumeEffectKind::ClearAllEffects,
+ ConsumeEffect::TeleportRandomly { .. } => {
+ azalea_registry::ConsumeEffectKind::TeleportRandomly
+ }
+ ConsumeEffect::PlaySound { .. } => azalea_registry::ConsumeEffectKind::PlaySound,
+ }
+ }
+}
diff --git a/azalea-inventory/src/item/mod.rs b/azalea-inventory/src/item/mod.rs
index 7f077c6a..bbff2d50 100644
--- a/azalea-inventory/src/item/mod.rs
+++ b/azalea-inventory/src/item/mod.rs
@@ -1,3 +1,5 @@
+pub mod consume_effect;
+
pub trait MaxStackSizeExt {
/// Get the maximum stack size for this item.
///