pub struct SoundEvent {
pub sound_name: Identifier,
pub fixed_range: Option<Float>,
}Expand description
Describes a sound that can be played.
A sound event contains its resource Identifier, followed by a boolean
indicating whether a fixed range is present, followed by the optional
Float range itself. In memory, the boolean is represented by whether
fixed_range is Some:
Identifier + Boolean(has fixed range) + Optional FloatWhen no fixed range is supplied, playback volume varies with distance according to the sound’s normal behavior.
§Examples
use mcproto_types::{Float, Identifier, SoundEvent, TypeCodec};
let sound = SoundEvent::fixed(
Identifier::new("minecraft:block.note_block.harp")?,
Float(16.0),
);
let mut encoded = Vec::new();
sound.encode(&mut encoded)?;
let mut input = encoded.as_slice();
assert_eq!(SoundEvent::decode(&mut input)?, sound);
assert!(input.is_empty());Fields§
§sound_name: IdentifierThe sound’s resource identifier.
fixed_range: Option<Float>Maximum playback range, or None for distance-dependent volume.
Implementations§
Source§impl SoundEvent
impl SoundEvent
Sourcepub const fn new(sound_name: Identifier, fixed_range: Option<Float>) -> Self
pub const fn new(sound_name: Identifier, fixed_range: Option<Float>) -> Self
Creates a sound event with an optional fixed range.
Sourcepub const fn variable(sound_name: Identifier) -> Self
pub const fn variable(sound_name: Identifier) -> Self
Creates a sound event with distance-dependent volume.
Sourcepub const fn fixed(sound_name: Identifier, fixed_range: Float) -> Self
pub const fn fixed(sound_name: Identifier, fixed_range: Float) -> Self
Creates a sound event with a fixed maximum range.
Sourcepub const fn has_fixed_range(&self) -> bool
pub const fn has_fixed_range(&self) -> bool
Returns whether this sound has a fixed maximum range.
Trait Implementations§
Source§impl Clone for SoundEvent
impl Clone for SoundEvent
Source§fn clone(&self) -> SoundEvent
fn clone(&self) -> SoundEvent
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SoundEvent
impl Debug for SoundEvent
Source§impl PartialEq for SoundEvent
impl PartialEq for SoundEvent
impl StructuralPartialEq for SoundEvent
Auto Trait Implementations§
impl Freeze for SoundEvent
impl RefUnwindSafe for SoundEvent
impl Send for SoundEvent
impl Sync for SoundEvent
impl Unpin for SoundEvent
impl UnsafeUnpin for SoundEvent
impl UnwindSafe for SoundEvent
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ContextualCodec for Twhere
T: TypeCodec,
impl<T> ContextualCodec for Twhere
T: TypeCodec,
Source§fn encode_with_context(
&self,
writer: &mut impl Write,
_context: &Context,
) -> Result<(), CodecError>
fn encode_with_context( &self, writer: &mut impl Write, _context: &Context, ) -> Result<(), CodecError>
Encodes this value using context supplied by its enclosing structure.
Source§fn decode_with_context(
reader: &mut impl Read,
_context: &Context,
) -> Result<T, CodecError>where
T: Sized,
fn decode_with_context(
reader: &mut impl Read,
_context: &Context,
) -> Result<T, CodecError>where
T: Sized,
Decodes this value using context supplied by its enclosing structure.