aboutsummaryrefslogtreecommitdiff
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
parent7a192acc99358818c2f90cf4e2b8b236f91cfbf7 (diff)
downloadazalea-drasl-65fe07215149ab81d0862ab7edac71d6a8417ef8.tar.xz
fix wrong Consumable component implementation and add set_equipment test
-rwxr-xr-xazalea-core/src/lib.rs1
-rw-r--r--azalea-core/src/sound.rs9
-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
-rwxr-xr-xazalea-protocol/src/packets/game/c_set_equipment.rs19
-rwxr-xr-xazalea-protocol/src/packets/game/c_sound.rs8
-rwxr-xr-xazalea-protocol/src/packets/game/c_sound_entity.rs3
-rwxr-xr-xazalea-registry/src/lib.rs15
9 files changed, 90 insertions, 11 deletions
diff --git a/azalea-core/src/lib.rs b/azalea-core/src/lib.rs
index ba6d61ef..a539dbd4 100755
--- a/azalea-core/src/lib.rs
+++ b/azalea-core/src/lib.rs
@@ -16,6 +16,7 @@ pub mod objectives;
pub mod position;
pub mod registry_holder;
pub mod resource_location;
+pub mod sound;
#[cfg(feature = "bevy_ecs")]
pub mod tick;
pub mod tier;
diff --git a/azalea-core/src/sound.rs b/azalea-core/src/sound.rs
new file mode 100644
index 00000000..f12205e0
--- /dev/null
+++ b/azalea-core/src/sound.rs
@@ -0,0 +1,9 @@
+use azalea_buf::AzBuf;
+
+use crate::resource_location::ResourceLocation;
+
+#[derive(Clone, Debug, PartialEq, AzBuf)]
+pub struct CustomSound {
+ pub location: ResourceLocation,
+ pub fixed_range: Option<f32>,
+}
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.
///
diff --git a/azalea-protocol/src/packets/game/c_set_equipment.rs b/azalea-protocol/src/packets/game/c_set_equipment.rs
index ad691d66..234de5d9 100755
--- a/azalea-protocol/src/packets/game/c_set_equipment.rs
+++ b/azalea-protocol/src/packets/game/c_set_equipment.rs
@@ -80,3 +80,22 @@ impl EquipmentSlot {
}
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn test_hypixel_set_equipment() {
+ let mut cursor = Cursor::new(
+ [
+ 230, 25, 0, 1, 224, 6, 2, 0, 3, 0, 22, 79, 0, 0, 0, 3, 0, 0, 0, 0, 0,
+ ]
+ .as_slice(),
+ );
+
+ let packet = ClientboundSetEquipment::azalea_read(&mut cursor).unwrap();
+ println!("packet {packet:?}");
+ assert_eq!(cursor.position(), cursor.get_ref().len() as u64);
+ }
+}
diff --git a/azalea-protocol/src/packets/game/c_sound.rs b/azalea-protocol/src/packets/game/c_sound.rs
index 8ec028a7..1a54c7c8 100755
--- a/azalea-protocol/src/packets/game/c_sound.rs
+++ b/azalea-protocol/src/packets/game/c_sound.rs
@@ -1,5 +1,5 @@
use azalea_buf::AzBuf;
-use azalea_core::resource_location::ResourceLocation;
+use azalea_core::sound::CustomSound;
use azalea_protocol_macros::ClientboundGamePacket;
use azalea_registry::SoundEvent;
@@ -16,12 +16,6 @@ pub struct ClientboundSound {
pub seed: u64,
}
-#[derive(Clone, Debug, AzBuf)]
-pub struct CustomSound {
- pub location: ResourceLocation,
- pub fixed_range: Option<f32>,
-}
-
#[derive(AzBuf, Clone, Copy, Debug)]
pub enum SoundSource {
Master = 0,
diff --git a/azalea-protocol/src/packets/game/c_sound_entity.rs b/azalea-protocol/src/packets/game/c_sound_entity.rs
index 37ce1f16..a6d17b72 100755
--- a/azalea-protocol/src/packets/game/c_sound_entity.rs
+++ b/azalea-protocol/src/packets/game/c_sound_entity.rs
@@ -1,9 +1,10 @@
use azalea_buf::AzBuf;
+use azalea_core::sound::CustomSound;
use azalea_protocol_macros::ClientboundGamePacket;
use azalea_registry::SoundEvent;
use azalea_world::MinecraftEntityId;
-use super::c_sound::{CustomSound, SoundSource};
+use super::c_sound::SoundSource;
#[derive(Clone, Debug, AzBuf, ClientboundGamePacket)]
pub struct ClientboundSoundEntity {
diff --git a/azalea-registry/src/lib.rs b/azalea-registry/src/lib.rs
index 4f72689f..59b8101f 100755
--- a/azalea-registry/src/lib.rs
+++ b/azalea-registry/src/lib.rs
@@ -194,6 +194,17 @@ impl<R: Registry + Clone, Direct: AzaleaRead + AzaleaWrite + Clone> Clone for Ho
}
}
}
+impl<R: Registry + PartialEq, Direct: AzaleaRead + AzaleaWrite + PartialEq> PartialEq
+ for Holder<R, Direct>
+{
+ fn eq(&self, other: &Self) -> bool {
+ match (self, other) {
+ (Self::Reference(a), Self::Reference(b)) => a == b,
+ (Self::Direct(a), Self::Direct(b)) => a == b,
+ _ => false,
+ }
+ }
+}
registry! {
/// The AI code that's currently being executed for the entity.
@@ -3832,6 +3843,10 @@ enum SensorKind {
}
registry! {
+/// A known type of sound in Minecraft.
+///
+/// If you need to support custom sounds from resource packs, you should use
+/// `azalea_registry::Holder<SoundEvent, azalea_core::sound::CustomSound>` instead.
enum SoundEvent {
EntityAllayAmbientWithItem => "minecraft:entity.allay.ambient_with_item",
EntityAllayAmbientWithoutItem => "minecraft:entity.allay.ambient_without_item",