diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2024-11-27 19:31:40 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-27 19:31:40 -0600 |
| commit | 08958c2278b15ebeac8a964f392ebb792e479b61 (patch) | |
| tree | 4ae3664cea38d7fd1a8f1e95ed06fac04ffe519e /azalea-protocol/src/packets/game/c_boss_event.rs | |
| parent | 139d77d3c2b0922fba5e9d4fa2bd9819d78bd773 (diff) | |
| download | azalea-drasl-08958c2278b15ebeac8a964f392ebb792e479b61.tar.xz | |
Refactor azalea-protocol (#190)
* start updating to 1.21.4
* fix block codegen and stop using block data from burger
* rename packet related modules and structs to be simpler
* ItemSlot -> ItemStack for more consistency with mojmap
* .get() -> .into_packet()
* simplify declare_state_packets by removing packet ids
* rename read_from and write_into to azalea_read and azalea_write
* rename McBufReadable and McBufWritable to AzaleaRead and AzaleaWrite
* McBuf -> AzBuf
* remove most uses of into_variant
* update codegen and use resourcelocation names for packets
* implement #[limit(i)] attribute for AzBuf derive macro
* fixes for 1.21.4
* fix examples
* update some physics code and fix ChatType
* remove unused imports in codegen
* re-add some things to migrate.py and update +mc version numbers automatically
* downgrade to 1.21.3 lol
Diffstat (limited to 'azalea-protocol/src/packets/game/c_boss_event.rs')
| -rwxr-xr-x | azalea-protocol/src/packets/game/c_boss_event.rs | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/azalea-protocol/src/packets/game/c_boss_event.rs b/azalea-protocol/src/packets/game/c_boss_event.rs new file mode 100755 index 00000000..e54ab59f --- /dev/null +++ b/azalea-protocol/src/packets/game/c_boss_event.rs @@ -0,0 +1,143 @@ +use std::io::Cursor; +use std::io::Write; + +use azalea_buf::{AzBuf, AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError}; +use azalea_chat::FormattedText; +use azalea_core::bitset::FixedBitSet; +use azalea_protocol_macros::ClientboundGamePacket; +use uuid::Uuid; + +#[derive(Clone, Debug, AzBuf, ClientboundGamePacket)] +pub struct ClientboundBossEvent { + pub id: Uuid, + pub operation: Operation, +} + +#[derive(Clone, Debug)] +pub enum Operation { + Add(AddOperation), + Remove, + UpdateProgress(f32), + UpdateName(FormattedText), + UpdateStyle(Style), + UpdateProperties(Properties), +} + +impl AzaleaRead for Operation { + fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { + let operation_id = u32::azalea_read_var(buf)?; + Ok(match operation_id { + 0 => Operation::Add(AddOperation::azalea_read(buf)?), + 1 => Operation::Remove, + 2 => Operation::UpdateProgress(f32::azalea_read(buf)?), + 3 => Operation::UpdateName(FormattedText::azalea_read(buf)?), + 4 => Operation::UpdateStyle(Style::azalea_read(buf)?), + 5 => Operation::UpdateProperties(Properties::azalea_read(buf)?), + _ => { + return Err(BufReadError::UnexpectedEnumVariant { + id: operation_id as i32, + }) + } + }) + } +} + +impl AzaleaWrite for Operation { + fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { + match self { + Operation::Add(add) => { + 0u32.azalea_write_var(buf)?; + add.azalea_write(buf)?; + } + Operation::Remove => { + 1u32.azalea_write_var(buf)?; + } + Operation::UpdateProgress(progress) => { + 2u32.azalea_write_var(buf)?; + progress.azalea_write(buf)?; + } + Operation::UpdateName(name) => { + 3u32.azalea_write_var(buf)?; + name.azalea_write(buf)?; + } + Operation::UpdateStyle(style) => { + 4u32.azalea_write_var(buf)?; + style.azalea_write(buf)?; + } + Operation::UpdateProperties(properties) => { + 5u32.azalea_write_var(buf)?; + properties.azalea_write(buf)?; + } + } + Ok(()) + } +} + +#[derive(Clone, Debug, AzBuf)] +pub struct AddOperation { + pub name: FormattedText, + pub progress: f32, + pub style: Style, + pub properties: Properties, +} + +#[derive(Clone, Debug, AzBuf)] +pub struct Style { + pub color: BossBarColor, + pub overlay: BossBarOverlay, +} + +#[derive(AzBuf, Clone, Copy, Debug)] +pub enum BossBarColor { + Pink = 0, + Blue = 1, + Red = 2, + Green = 3, + Yellow = 4, + Purple = 5, + White = 6, +} + +#[derive(AzBuf, Clone, Copy, Debug)] +pub enum BossBarOverlay { + Progress = 0, + Notched6 = 1, + Notched10 = 2, + Notched12 = 3, + Notched20 = 4, +} + +#[derive(Clone, Debug)] +pub struct Properties { + pub darken_screen: bool, + pub play_music: bool, + pub create_world_fog: bool, +} + +impl AzaleaRead for Properties { + fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { + let set = FixedBitSet::<3>::azalea_read(buf)?; + Ok(Self { + darken_screen: set.index(0), + play_music: set.index(1), + create_world_fog: set.index(2), + }) + } +} + +impl AzaleaWrite for Properties { + fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { + let mut set = FixedBitSet::<3>::new(); + if self.darken_screen { + set.set(0); + } + if self.play_music { + set.set(1); + } + if self.create_world_fog { + set.set(2); + } + set.azalea_write(buf)?; + Ok(()) + } +} |
