@@ -9,15 +9,32 @@ use ferrumc_net_codec::net_types::var_int::VarInt;
9
9
use std:: io:: Write ;
10
10
use tokio:: io:: AsyncWrite ;
11
11
12
+ /// Packet for sending entity metadata updates to clients
12
13
#[ derive( NetEncode ) ]
13
14
#[ packet( packet_id = 0x58 ) ]
14
15
pub struct EntityMetadataPacket {
15
16
entity_id : VarInt ,
16
17
metadata : Vec < EntityMetadata > ,
17
- terminator : u8 ,
18
+ terminator : u8 , // Always 0xFF to indicate end of metadata (Simple is Best)
18
19
}
19
20
20
21
impl EntityMetadataPacket {
22
+ /// Creates a new metadata packet for the specified entity
23
+ ///
24
+ /// # Arguments
25
+ /// * `entity_id` - The entity ID to update metadata for
26
+ /// * `metadata` - Iterator of metadata entries to send
27
+ ///
28
+ /// # Example
29
+ /// ```ignored
30
+ /// let entity_id = ...;
31
+ /// let metadata = vec![
32
+ /// EntityMetadata::entity_sneaking_pressed(),
33
+ /// EntityMetadata::entity_sneaking_visual(),
34
+ /// EntityMetadata::entity_standing()
35
+ /// ];
36
+ /// let packet = EntityMetadataPacket::new(entity_id, metadata);
37
+ /// ```
21
38
pub fn new < T > ( entity_id : Entity , metadata : T ) -> Self
22
39
where
23
40
T : IntoIterator < Item = EntityMetadata > ,
@@ -30,6 +47,7 @@ impl EntityMetadataPacket {
30
47
}
31
48
}
32
49
50
+ /// Single metadata entry containing an index, type and value
33
51
#[ derive( NetEncode ) ]
34
52
pub struct EntityMetadata {
35
53
index : u8 ,
@@ -78,9 +96,12 @@ pub mod constructors {
78
96
79
97
mod index_type {
80
98
use super :: * ;
99
+
100
+ /// Available metadata field types
101
+ /// See: https://minecraft.wiki/w/Minecraft_Wiki:Projects/wiki.vg_merge/Entity_metadata#Entity_Metadata_Format
81
102
pub enum EntityMetadataIndexType {
82
- Byte ,
83
- Pose ,
103
+ Byte , // (0) Used for bit masks and small numbers
104
+ Pose , // (21) Used for entity pose
84
105
}
85
106
86
107
impl EntityMetadataIndexType {
@@ -113,6 +134,8 @@ mod index_type {
113
134
mod value {
114
135
use super :: * ;
115
136
use crate :: packets:: outgoing:: entity_metadata:: extra_data_types:: EntityPose ;
137
+ /// Possible metadata values that can be sent
138
+ ///
116
139
/// Couldn't be arsed coming up with the names.
117
140
/// Read here:
118
141
/// https://minecraft.wiki/w/Minecraft_Wiki:Projects/wiki.vg_merge/Entity_metadata#Entity
@@ -140,6 +163,7 @@ mod entity_state {
140
163
use ferrumc_macros:: NetEncode ;
141
164
use std:: io:: Write ;
142
165
166
+ /// Bit mask for various entity states
143
167
#[ derive( Debug , NetEncode ) ]
144
168
pub struct EntityStateMask {
145
169
mask : u8 ,
@@ -167,15 +191,17 @@ mod entity_state {
167
191
}
168
192
}
169
193
194
+ /// Individual states that can be applied to an entity
195
+ /// Multiple states can be combined using a bit mask
170
196
#[ allow( dead_code) ]
171
197
pub enum EntityState {
172
- OnFire ,
173
- SneakingVisual ,
174
- Sprinting ,
175
- Swimming ,
176
- Invisible ,
177
- Glowing ,
178
- FlyingWithElytra ,
198
+ OnFire , // 0x01
199
+ SneakingVisual , // 0x02
200
+ Sprinting , // 0x08
201
+ Swimming , // 0x10
202
+ Invisible , // 0x20
203
+ Glowing , // 0x40
204
+ FlyingWithElytra , // 0x80
179
205
}
180
206
181
207
impl EntityState {
@@ -203,6 +229,7 @@ mod extra_data_types {
203
229
// USING_TONGUE = 9, SITTING = 10, ROARING = 11, SNIFFING = 12, EMERGING = 13, DIGGING = 14, (1.21.3: SLIDING = 15, SHOOTING = 16,
204
230
// INHALING = 17
205
231
232
+ /// Possible poses/animations an entity can have
206
233
#[ derive( Debug ) ]
207
234
#[ allow( dead_code) ]
208
235
pub enum EntityPose {
0 commit comments