mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
update serialization for set_player_team
This commit is contained in:
parent
c7d53d6532
commit
8012fb90b5
2 changed files with 48 additions and 50 deletions
|
@ -1554,7 +1554,9 @@ impl GamePacketHandler<'_> {
|
|||
pub fn set_display_objective(&mut self, _p: &ClientboundSetDisplayObjective) {}
|
||||
pub fn set_objective(&mut self, _p: &ClientboundSetObjective) {}
|
||||
pub fn set_passengers(&mut self, _p: &ClientboundSetPassengers) {}
|
||||
pub fn set_player_team(&mut self, _p: &ClientboundSetPlayerTeam) {}
|
||||
pub fn set_player_team(&mut self, p: &ClientboundSetPlayerTeam) {
|
||||
debug!("Got set player team packet {p:?}");
|
||||
}
|
||||
pub fn set_score(&mut self, _p: &ClientboundSetScore) {}
|
||||
pub fn set_simulation_distance(&mut self, _p: &ClientboundSetSimulationDistance) {}
|
||||
pub fn set_subtitle_text(&mut self, _p: &ClientboundSetSubtitleText) {}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
use std::io::{Cursor, Write};
|
||||
|
||||
use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite, BufReadError};
|
||||
use azalea_chat::{style::ChatFormatting, FormattedText};
|
||||
use azalea_buf::AzBuf;
|
||||
use azalea_chat::{FormattedText, style::ChatFormatting};
|
||||
use azalea_protocol_macros::ClientboundGamePacket;
|
||||
|
||||
#[derive(Clone, Debug, AzBuf, ClientboundGamePacket)]
|
||||
|
@ -10,7 +8,7 @@ pub struct ClientboundSetPlayerTeam {
|
|||
pub method: Method,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, AzBuf)]
|
||||
pub enum Method {
|
||||
Add((Parameters, PlayerList)),
|
||||
Remove,
|
||||
|
@ -19,56 +17,54 @@ pub enum Method {
|
|||
Leave(PlayerList),
|
||||
}
|
||||
|
||||
impl AzaleaRead for Method {
|
||||
fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
|
||||
Ok(match u8::azalea_read(buf)? {
|
||||
0 => Method::Add((Parameters::azalea_read(buf)?, PlayerList::azalea_read(buf)?)),
|
||||
1 => Method::Remove,
|
||||
2 => Method::Change(Parameters::azalea_read(buf)?),
|
||||
3 => Method::Join(PlayerList::azalea_read(buf)?),
|
||||
4 => Method::Leave(PlayerList::azalea_read(buf)?),
|
||||
id => return Err(BufReadError::UnexpectedEnumVariant { id: i32::from(id) }),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl AzaleaWrite for Method {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
match self {
|
||||
Method::Add((parameters, playerlist)) => {
|
||||
0u8.azalea_write(buf)?;
|
||||
parameters.azalea_write(buf)?;
|
||||
playerlist.azalea_write(buf)?;
|
||||
}
|
||||
Method::Remove => {
|
||||
1u8.azalea_write(buf)?;
|
||||
}
|
||||
Method::Change(parameters) => {
|
||||
2u8.azalea_write(buf)?;
|
||||
parameters.azalea_write(buf)?;
|
||||
}
|
||||
Method::Join(playerlist) => {
|
||||
3u8.azalea_write(buf)?;
|
||||
playerlist.azalea_write(buf)?;
|
||||
}
|
||||
Method::Leave(playerlist) => {
|
||||
4u8.azalea_write(buf)?;
|
||||
playerlist.azalea_write(buf)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(AzBuf, Clone, Debug)]
|
||||
#[derive(Clone, Debug, AzBuf)]
|
||||
pub struct Parameters {
|
||||
pub display_name: FormattedText,
|
||||
pub options: u8,
|
||||
pub nametag_visibility: String,
|
||||
pub collision_rule: String,
|
||||
pub nametag_visibility: NameTagVisibility,
|
||||
pub collision_rule: CollisionRule,
|
||||
pub color: ChatFormatting,
|
||||
pub player_prefix: FormattedText,
|
||||
pub player_suffix: FormattedText,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, AzBuf)]
|
||||
pub enum CollisionRule {
|
||||
Always,
|
||||
Never,
|
||||
PushOtherTeams,
|
||||
PushOwnTeam,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, AzBuf)]
|
||||
pub enum NameTagVisibility {
|
||||
Always,
|
||||
Never,
|
||||
HideForOtherTeams,
|
||||
HideForOwnTeam,
|
||||
}
|
||||
|
||||
type PlayerList = Vec<String>;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::io::Cursor;
|
||||
|
||||
use azalea_buf::AzaleaRead;
|
||||
|
||||
use crate::packets::game::ClientboundSetPlayerTeam;
|
||||
|
||||
#[test]
|
||||
fn test_read_set_player_team() {
|
||||
let contents = [
|
||||
16, 99, 111, 108, 108, 105, 100, 101, 82, 117, 108, 101, 95, 57, 52, 53, 54, 0, 8, 0,
|
||||
16, 99, 111, 108, 108, 105, 100, 101, 82, 117, 108, 101, 95, 57, 52, 53, 54, 1, 0, 1,
|
||||
21, 8, 0, 0, 8, 0, 0, 0,
|
||||
];
|
||||
let mut buf = Cursor::new(contents.as_slice());
|
||||
let packet = ClientboundSetPlayerTeam::azalea_read(&mut buf).unwrap();
|
||||
println!("{:?}", packet);
|
||||
|
||||
assert_eq!(buf.position(), contents.len() as u64);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue