diff --git a/pumpkin-protocol/src/client/play/c_reset_score.rs b/pumpkin-protocol/src/client/play/c_reset_score.rs index d694e870b..1dcfbc8b6 100644 --- a/pumpkin-protocol/src/client/play/c_reset_score.rs +++ b/pumpkin-protocol/src/client/play/c_reset_score.rs @@ -7,3 +7,12 @@ pub struct CResetScore { entity_name: String, objective_name: Option, } + +impl CResetScore { + pub fn new(entity_name: String, objective_name: Option) -> Self { + Self { + entity_name, + objective_name, + } + } +} diff --git a/pumpkin-protocol/src/client/play/c_update_objectives.rs b/pumpkin-protocol/src/client/play/c_update_objectives.rs new file mode 100644 index 000000000..60845dc56 --- /dev/null +++ b/pumpkin-protocol/src/client/play/c_update_objectives.rs @@ -0,0 +1,80 @@ +use pumpkin_core::text::{style::Style, TextComponent}; +use pumpkin_macros::packet; + +use crate::{ClientPacket, VarInt}; + +#[packet(0x5E)] +pub struct CUpdateObjectives<'a> { + objective_name: &'a str, + mode: u8, + display_name: TextComponent<'a>, + render_type: VarInt, + number_format: Option>, +} + +impl<'a> CUpdateObjectives<'a> { + pub fn new( + objective_name: &'a str, + mode: u8, + display_name: TextComponent<'a>, + render_type: VarInt, + number_format: Option>, + ) -> Self { + Self { + objective_name, + mode, + display_name, + render_type, + number_format, + } + } +} + +impl<'a> ClientPacket for CUpdateObjectives<'a> { + fn write(&self, bytebuf: &mut crate::bytebuf::ByteBuffer) { + bytebuf.put_string(self.objective_name); + bytebuf.put_u8(self.mode); + if self.mode == 0 || self.mode == 2 { + bytebuf.put_slice(&self.display_name.encode()); + bytebuf.put_var_int(&self.render_type); + bytebuf.put_option(&self.number_format, |p, v| { + match v { + NumberFormat::Blank => { + p.put_var_int(&VarInt(0)); + } + NumberFormat::Styled(style) => { + p.put_var_int(&VarInt(1)); + // TODO + p.put_slice(&fastnbt::to_bytes(style).unwrap()); + } + NumberFormat::Fixed(text_component) => { + p.put_var_int(&VarInt(2)); + p.put_slice(&text_component.encode()); + } + } + }); + } + } +} + +#[repr(u8)] +pub enum Mode { + Add, + Remove, + Update, +} + +#[repr(i32)] +pub enum RenderType { + Integer, + Hearts, +} + +pub enum NumberFormat<'a> { + /// Show nothing + Blank, + /// The styling to be used when formatting the score number + Styled(Style<'a>), + /// The text to be used as placeholder. + Fixed(TextComponent<'a>), +} diff --git a/pumpkin-protocol/src/client/play/mod.rs b/pumpkin-protocol/src/client/play/mod.rs index 297904773..816f4a8b7 100644 --- a/pumpkin-protocol/src/client/play/mod.rs +++ b/pumpkin-protocol/src/client/play/mod.rs @@ -42,6 +42,7 @@ mod c_unload_chunk; mod c_update_entity_pos; mod c_update_entity_pos_rot; mod c_update_entity_rot; +mod c_update_objectives; mod c_worldevent; mod player_action; @@ -89,5 +90,6 @@ pub use c_unload_chunk::*; pub use c_update_entity_pos::*; pub use c_update_entity_pos_rot::*; pub use c_update_entity_rot::*; +pub use c_update_objectives::*; pub use c_worldevent::*; pub use player_action::*;