//! Contains a few ways to style numbers. At the time of writing, Minecraft only //! uses this for rendering scoreboard objectives. use std::io::{self, Cursor, Write}; #[cfg(feature = "azalea-buf")] use azalea_buf::{AzaleaRead, AzaleaWrite}; use azalea_registry::NumberFormatKind; use simdnbt::owned::Nbt; use crate::FormattedText; #[derive(Clone, Debug)] pub enum NumberFormat { Blank, Styled { style: Nbt }, Fixed { value: FormattedText }, } #[cfg(feature = "azalea-buf")] impl AzaleaRead for NumberFormat { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let kind = NumberFormatKind::azalea_read(buf)?; match kind { NumberFormatKind::Blank => Ok(NumberFormat::Blank), NumberFormatKind::Styled => Ok(NumberFormat::Styled { style: simdnbt::owned::read(buf)?, }), NumberFormatKind::Fixed => Ok(NumberFormat::Fixed { value: FormattedText::azalea_read(buf)?, }), } } } #[cfg(feature = "azalea-buf")] impl AzaleaWrite for NumberFormat { fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> { match self { NumberFormat::Blank => NumberFormatKind::Blank.azalea_write(buf)?, NumberFormat::Styled { style } => { NumberFormatKind::Styled.azalea_write(buf)?; style.azalea_write(buf)?; } NumberFormat::Fixed { value } => { NumberFormatKind::Fixed.azalea_write(buf)?; value.azalea_write(buf)?; } } Ok(()) } }