diff options
| author | mat <github@matdoes.dev> | 2022-05-07 19:46:06 -0500 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-05-07 19:46:06 -0500 |
| commit | e53ef8b0ddd46b3a85e597e7da57139960304e35 (patch) | |
| tree | 272a3dfb42113dc53e51b5d21052e033bae92fd7 /azalea-protocol/src/packets | |
| parent | 0b84e1cbb826f1a502ffc81efc000369a3c5bb85 (diff) | |
| download | azalea-drasl-e53ef8b0ddd46b3a85e597e7da57139960304e35.tar.xz | |
update advancements packet
Diffstat (limited to 'azalea-protocol/src/packets')
| -rw-r--r-- | azalea-protocol/src/packets/game/clientbound_update_advancements_packet.rs | 90 | ||||
| -rwxr-xr-x | azalea-protocol/src/packets/game/mod.rs | 2 |
2 files changed, 92 insertions, 0 deletions
diff --git a/azalea-protocol/src/packets/game/clientbound_update_advancements_packet.rs b/azalea-protocol/src/packets/game/clientbound_update_advancements_packet.rs new file mode 100644 index 00000000..fe2c226d --- /dev/null +++ b/azalea-protocol/src/packets/game/clientbound_update_advancements_packet.rs @@ -0,0 +1,90 @@ +use crate::packets::{McBufReadable, McBufWritable}; +use azalea_chat::component::Component; +use azalea_core::{resource_location::ResourceLocation, Slot}; +use packet_macros::{GamePacket, McBufReadable, McBufWritable}; +use std::{ + collections::HashMap, + io::{Read, Write}, +}; + +#[derive(Clone, Debug, GamePacket)] +pub struct ClientboundUpdateAdvancementsPacket { + pub reset: bool, + pub added: HashMap<ResourceLocation, Advancement>, + pub removed: Vec<ResourceLocation>, + pub progress: HashMap<ResourceLocation, AdvancementProgress>, +} + +#[derive(Clone, Debug, McBufReadable, McBufWritable)] +pub struct Advancement { + parent_id: Option<ResourceLocation>, + display: Option<DisplayInfo>, + // rewards: AdvancementRewards.EMPTY, + criteria: HashMap<ResourceLocation, Criterion>, + requirements: Vec<Vec<String>>, + // requirements_strategy: RequirementsStrategy.AND +} + +#[derive(Clone, Debug, McBufReadable, McBufWritable)] +pub struct DisplayInfo { + pub title: Component, + pub description: Component, + pub icon: Slot, + pub frame: FrameType, + pub flags: DisplayFlags, + pub background: Option<ResourceLocation>, + pub x: f32, + pub y: f32, +} + +#[derive(Clone, Debug)] +pub struct DisplayFlags { + pub background: bool, + pub show_toast: bool, + pub hidden: bool, +} + +impl McBufReadable for DisplayFlags { + fn read_into(buf: &mut impl Read) -> Result<Self, String> { + let data = u32::read_into(buf)?; + Ok(DisplayFlags { + background: (data & 0b1) != 0, + show_toast: (data & 0b10) != 0, + hidden: (data & 0b100) != 0, + }) + } +} + +impl McBufWritable for DisplayFlags { + fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { + let mut data = 0; + if self.background { + data |= 0b1; + } + if self.show_toast { + data |= 0b10; + } + if self.hidden { + data |= 0b100; + } + u32::write_into(&data, buf) + } +} + +#[derive(Clone, Debug, Copy, McBufReadable, McBufWritable)] +pub enum FrameType { + Task = 0, + Challenge = 1, + Goal = 2, +} + +// nothing is written here +#[derive(Clone, Debug, McBufReadable, McBufWritable)] +pub struct Criterion {} + +pub type AdvancementProgress = HashMap<ResourceLocation, CriterionProgress>; + +#[derive(Clone, Debug, McBufReadable, McBufWritable)] +pub struct CriterionProgress { + date: Option<u64>, +} diff --git a/azalea-protocol/src/packets/game/mod.rs b/azalea-protocol/src/packets/game/mod.rs index d3ea7281..db1c0b11 100755 --- a/azalea-protocol/src/packets/game/mod.rs +++ b/azalea-protocol/src/packets/game/mod.rs @@ -25,6 +25,7 @@ pub mod clientbound_set_experience_packet; pub mod clientbound_set_health_packet; pub mod clientbound_set_time_packet; pub mod clientbound_teleport_entity_packet; +pub mod clientbound_update_advancements_packet; pub mod clientbound_update_attributes_packet; pub mod clientbound_update_recipes_packet; pub mod clientbound_update_tags_packet; @@ -67,6 +68,7 @@ declare_state_packets!( 0x52: clientbound_set_health_packet::ClientboundSetHealthPacket, 0x59: clientbound_set_time_packet::ClientboundSetTimePacket, 0x62: clientbound_teleport_entity_packet::ClientboundTeleportEntityPacket, + 0x63: clientbound_update_advancements_packet::ClientboundUpdateAdvancementsPacket, 0x64: clientbound_update_attributes_packet::ClientboundUpdateAttributesPacket, 0x66: clientbound_update_recipes_packet::ClientboundUpdateRecipesPacket, 0x67: clientbound_update_tags_packet::ClientboundUpdateTagsPacket, |
