Skip to content

Commit 05045b4

Browse files
committed
Added some documentation to entity_metadata.rs, and fixed some other minor things.
1 parent 1187613 commit 05045b4

File tree

2 files changed

+45
-13
lines changed

2 files changed

+45
-13
lines changed

src/bin/src/packet_handlers/login_process.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,12 @@ async fn handle_ack_finish_configuration(
203203
)
204204
.await?;
205205

206+
send_keep_alive(entity_id, &state, &mut writer).await?;
207+
206208
let pos = state.universe.get_mut::<Position>(entity_id)?;
207209
let mut chunk_recv = state.universe.get_mut::<ChunkReceiver>(entity_id)?;
208210
chunk_recv.last_chunk = Some((pos.x as i32, pos.z as i32, String::from("overworld")));
209211
chunk_recv.calculate_chunks().await;
210-
211-
send_keep_alive(entity_id, &state, &mut writer).await?;
212212
}
213213

214214
player_info_update_packets(entity_id, &state).await?;
@@ -275,7 +275,12 @@ async fn broadcast_spawn_entity_packet(entity_id: Entity, state: &GlobalState) -
275275
let packet = SpawnEntityPacket::player(entity_id, state)?;
276276

277277
let start = Instant::now();
278-
broadcast(&packet, state, BroadcastOptions::default()).await?;
278+
broadcast(
279+
&packet,
280+
state,
281+
BroadcastOptions::default().except([entity_id]),
282+
)
283+
.await?;
279284
trace!("Broadcasting spawn entity took: {:?}", start.elapsed());
280285

281286
let writer = state.universe.get_mut::<StreamWriter>(entity_id)?;

src/lib/net/src/packets/outgoing/entity_metadata.rs

+37-10
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,32 @@ use ferrumc_net_codec::net_types::var_int::VarInt;
99
use std::io::Write;
1010
use tokio::io::AsyncWrite;
1111

12+
/// Packet for sending entity metadata updates to clients
1213
#[derive(NetEncode)]
1314
#[packet(packet_id = 0x58)]
1415
pub struct EntityMetadataPacket {
1516
entity_id: VarInt,
1617
metadata: Vec<EntityMetadata>,
17-
terminator: u8,
18+
terminator: u8, // Always 0xFF to indicate end of metadata (Simple is Best)
1819
}
1920

2021
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+
/// ```
2138
pub fn new<T>(entity_id: Entity, metadata: T) -> Self
2239
where
2340
T: IntoIterator<Item = EntityMetadata>,
@@ -30,6 +47,7 @@ impl EntityMetadataPacket {
3047
}
3148
}
3249

50+
/// Single metadata entry containing an index, type and value
3351
#[derive(NetEncode)]
3452
pub struct EntityMetadata {
3553
index: u8,
@@ -78,9 +96,12 @@ pub mod constructors {
7896

7997
mod index_type {
8098
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
81102
pub enum EntityMetadataIndexType {
82-
Byte,
83-
Pose,
103+
Byte, // (0) Used for bit masks and small numbers
104+
Pose, // (21) Used for entity pose
84105
}
85106

86107
impl EntityMetadataIndexType {
@@ -113,6 +134,8 @@ mod index_type {
113134
mod value {
114135
use super::*;
115136
use crate::packets::outgoing::entity_metadata::extra_data_types::EntityPose;
137+
/// Possible metadata values that can be sent
138+
///
116139
/// Couldn't be arsed coming up with the names.
117140
/// Read here:
118141
/// https://minecraft.wiki/w/Minecraft_Wiki:Projects/wiki.vg_merge/Entity_metadata#Entity
@@ -140,6 +163,7 @@ mod entity_state {
140163
use ferrumc_macros::NetEncode;
141164
use std::io::Write;
142165

166+
/// Bit mask for various entity states
143167
#[derive(Debug, NetEncode)]
144168
pub struct EntityStateMask {
145169
mask: u8,
@@ -167,15 +191,17 @@ mod entity_state {
167191
}
168192
}
169193

194+
/// Individual states that can be applied to an entity
195+
/// Multiple states can be combined using a bit mask
170196
#[allow(dead_code)]
171197
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
179205
}
180206

181207
impl EntityState {
@@ -203,6 +229,7 @@ mod extra_data_types {
203229
// USING_TONGUE = 9, SITTING = 10, ROARING = 11, SNIFFING = 12, EMERGING = 13, DIGGING = 14, (1.21.3: SLIDING = 15, SHOOTING = 16,
204230
// INHALING = 17
205231

232+
/// Possible poses/animations an entity can have
206233
#[derive(Debug)]
207234
#[allow(dead_code)]
208235
pub enum EntityPose {

0 commit comments

Comments
 (0)