forked from Quozul/PicoLimbo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboss_bar_packet.rs
More file actions
105 lines (100 loc) · 2.84 KB
/
boss_bar_packet.rs
File metadata and controls
105 lines (100 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
use minecraft_protocol::prelude::*;
use pico_text_component::prelude::Component;
#[derive(PacketOut)]
pub struct BossBarPacket {
#[pvn(735..)]
pub v1_16_uuid: Uuid,
#[pvn(..735)]
pub uuid_most_sig: u64,
#[pvn(..735)]
pub uuid_least_sig: u64,
pub action: BossBarAction,
}
pub enum BossBarAction {
Add {
title: Component,
health: f32,
color: BossBarColor,
division: BossBarDivision,
flags: u8,
},
Remove,
UpdateHealth {
health: f32,
},
UpdateTitle {
title: Component,
},
UpdateStyle {
color: BossBarColor,
division: BossBarDivision,
},
UpdateFlags {
flags: u8,
},
}
#[derive(Debug, Clone, Copy)]
#[repr(i32)]
pub enum BossBarColor {
Pink = 0,
Blue = 1,
Red = 2,
Green = 3,
Yellow = 4,
Purple = 5,
White = 6,
}
#[derive(Debug, Clone, Copy)]
#[repr(i32)]
pub enum BossBarDivision {
NoDivision = 0,
SixNotches = 1,
TenNotches = 2,
TwelveNotches = 3,
TwentyNotches = 4,
}
impl EncodePacket for BossBarAction {
fn encode(
&self,
writer: &mut BinaryWriter,
protocol_version: ProtocolVersion,
) -> Result<(), BinaryWriterError> {
match self {
BossBarAction::Add {
title,
health,
color,
division,
flags,
} => {
VarInt::new(0).encode(writer, protocol_version)?;
title.clone().encode(writer, protocol_version)?;
health.encode(writer, protocol_version)?;
VarInt::new(*color as i32).encode(writer, protocol_version)?;
VarInt::new(*division as i32).encode(writer, protocol_version)?;
flags.encode(writer, protocol_version)?;
}
BossBarAction::Remove => {
VarInt::new(1).encode(writer, protocol_version)?;
}
BossBarAction::UpdateHealth { health } => {
VarInt::new(2).encode(writer, protocol_version)?;
health.encode(writer, protocol_version)?;
}
BossBarAction::UpdateTitle { title } => {
VarInt::new(3).encode(writer, protocol_version)?;
title.clone().encode(writer, protocol_version)?;
}
BossBarAction::UpdateStyle { color, division } => {
VarInt::new(4).encode(writer, protocol_version)?;
VarInt::new(*color as i32).encode(writer, protocol_version)?;
VarInt::new(*division as i32).encode(writer, protocol_version)?;
}
BossBarAction::UpdateFlags { flags } => {
VarInt::new(5).encode(writer, protocol_version)?;
flags.encode(writer, protocol_version)?;
}
}
Ok(())
}
}