1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 06:16:04 +00:00

fix wrong Consumable component implementation and add set_equipment test

This commit is contained in:
mat 2025-03-13 20:46:12 +00:00
parent 7a192acc99
commit 65fe072151
9 changed files with 90 additions and 11 deletions

View file

@ -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;

9
azalea-core/src/sound.rs Normal file
View file

@ -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>,
}

View file

@ -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;

View file

@ -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,
}
}
}

View file

@ -1,3 +1,5 @@
pub mod consume_effect;
pub trait MaxStackSizeExt {
/// Get the maximum stack size for this item.
///

View file

@ -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);
}
}

View file

@ -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,

View file

@ -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 {

View file

@ -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",