mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
parent
804a9fd800
commit
fe687f9bdb
2 changed files with 40 additions and 2 deletions
|
@ -1,10 +1,10 @@
|
||||||
use azalea_buf::McBuf;
|
use azalea_buf::McBuf;
|
||||||
|
use azalea_core::ResourceLocation;
|
||||||
use azalea_protocol_macros::ClientboundGamePacket;
|
use azalea_protocol_macros::ClientboundGamePacket;
|
||||||
use azalea_registry::OptionalRegistry;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBuf, ClientboundGamePacket)]
|
#[derive(Clone, Debug, McBuf, ClientboundGamePacket)]
|
||||||
pub struct ClientboundSoundPacket {
|
pub struct ClientboundSoundPacket {
|
||||||
pub sound: OptionalRegistry<azalea_registry::SoundEvent>,
|
pub sound: azalea_registry::CustomRegistry<azalea_registry::SoundEvent, CustomSoundEvent>,
|
||||||
pub source: SoundSource,
|
pub source: SoundSource,
|
||||||
pub x: i32,
|
pub x: i32,
|
||||||
pub y: i32,
|
pub y: i32,
|
||||||
|
@ -14,6 +14,12 @@ pub struct ClientboundSoundPacket {
|
||||||
pub seed: u64,
|
pub seed: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(McBuf, Clone, Debug)]
|
||||||
|
pub struct CustomSoundEvent {
|
||||||
|
pub location: ResourceLocation,
|
||||||
|
pub range: Option<f32>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(McBuf, Clone, Copy, Debug)]
|
#[derive(McBuf, Clone, Copy, Debug)]
|
||||||
pub enum SoundSource {
|
pub enum SoundSource {
|
||||||
Master = 0,
|
Master = 0,
|
||||||
|
|
|
@ -43,6 +43,38 @@ impl<T: Registry> McBufWritable for OptionalRegistry<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A registry that will either take an ID or a resource location.
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
|
pub enum CustomRegistry<D: Registry, C: McBufReadable + McBufWritable> {
|
||||||
|
Direct(D),
|
||||||
|
Custom(C),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<D: Registry, C: McBufReadable + McBufWritable> McBufReadable for CustomRegistry<D, C> {
|
||||||
|
fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
|
||||||
|
let direct_registry = OptionalRegistry::<D>::read_from(buf)?;
|
||||||
|
if let Some(direct_registry) = direct_registry.0 {
|
||||||
|
return Ok(CustomRegistry::Direct(direct_registry));
|
||||||
|
}
|
||||||
|
Ok(CustomRegistry::Custom(C::read_from(buf)?))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<D: Registry, C: McBufReadable + McBufWritable> McBufWritable for CustomRegistry<D, C> {
|
||||||
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
|
match self {
|
||||||
|
CustomRegistry::Direct(direct_registry) => {
|
||||||
|
// write the id + 1
|
||||||
|
(direct_registry.to_u32() + 1).var_write_into(buf)
|
||||||
|
}
|
||||||
|
CustomRegistry::Custom(custom_registry) => {
|
||||||
|
// write 0, then the custom registry
|
||||||
|
0u32.var_write_into(buf)?;
|
||||||
|
custom_registry.write_into(buf)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
registry! {
|
registry! {
|
||||||
/// The AI code that's currently being executed for the entity.
|
/// The AI code that's currently being executed for the entity.
|
||||||
enum Activity {
|
enum Activity {
|
||||||
|
|
Loading…
Add table
Reference in a new issue