Skip to content

Commit e37dcba

Browse files
committed
reorganise all packets
1 parent 0428c3e commit e37dcba

File tree

185 files changed

+3910
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

185 files changed

+3910
-1
lines changed

crates/valence_packet/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition.workspace = true
66
[dependencies]
77
valence_core.workspace = true
88
valence_nbt.workspace = true
9+
valence_registry.workspace = true
910
anyhow.workspace = true
1011
bitfield-struct.workspace = true
1112
byteorder.workspace = true

crates/valence_packet/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
# TODO
1+
# valence_packet
2+
3+
This contain all (some) the packets structures of the minecraft protocol #763.
4+
5+
## Naming
6+
7+
Tha naming of the struct are based on the yarn mapping name and the packet side, for that reason it can be a bit different from the [wiki.vg](https://wiki.vg) name.

crates/valence_packet/src/client.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,24 @@ pub struct PlayerSpawnPositionS2c {
378378
pub angle: f32,
379379
}
380380

381+
// https://wiki.vg/Protocol#Spawn_Player
382+
/// This packet is sent by the server when a player comes into visible range,
383+
/// not when a player joins.
384+
///
385+
/// This packet must be sent after the Player Info Update packet that adds the
386+
/// player data for the client to use when spawning a player. If the Player Info
387+
/// for the player spawned by this packet is not present when this packet
388+
/// arrives, Notchian clients will not spawn the player entity. The Player Info
389+
/// packet includes skin/cape data.
390+
///
391+
/// Servers can, however, safely spawn player entities for players not in
392+
/// visible range. The client appears to handle it correctly.
393+
///
394+
/// wiki : [Spawn Player](https://wiki.vg/Protocol#Spawn_Player)
381395
#[derive(Copy, Clone, Debug, Encode, Decode, Packet)]
382396
#[packet(id = packet_id::PLAYER_SPAWN_S2C)]
383397
pub struct PlayerSpawnS2c {
398+
/// A unique integer ID mostly used in the protocol to identify the player.
384399
pub entity_id: VarInt,
385400
pub player_uuid: Uuid,
386401
pub position: DVec3,

crates/valence_packet/src/entity.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ pub struct EntitySetHeadYawS2c {
171171
pub head_yaw: ByteAngle,
172172
}
173173

174+
// https://wiki.vg/Protocol#Spawn_Experience_Orb
175+
/// Sent by the server when a vehicle or other non-living entity is created.
176+
///
177+
/// wiki : [Spawn Entity](https://wiki.vg/Protocol#Spawn_Experience_Orb)
174178
#[derive(Copy, Clone, Debug, Encode, Decode, Packet)]
175179
#[packet(id = packet_id::ENTITY_SPAWN_S2C)]
176180
pub struct EntitySpawnS2c {
@@ -227,11 +231,16 @@ pub struct EntityVelocityUpdateS2c {
227231
pub velocity: [i16; 3],
228232
}
229233

234+
// https://wiki.vg/Protocol#Spawn_Experience_Orb
235+
/// Spawns one or more experience orbs.
236+
///
237+
/// wiki : [Spawn Experience Orb](https://wiki.vg/Protocol#Spawn_Experience_Orb)
230238
#[derive(Copy, Clone, Debug, Encode, Decode, Packet)]
231239
#[packet(id = packet_id::EXPERIENCE_ORB_SPAWN_S2C)]
232240
pub struct ExperienceOrbSpawnS2c {
233241
pub entity_id: VarInt,
234242
pub position: DVec3,
243+
/// The amount of experience this orb will reward once collected.
235244
pub count: i16,
236245
}
237246

crates/valence_packet/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub mod instance;
3333
pub mod inventory;
3434
pub mod map;
3535
pub mod network;
36+
pub mod packets;
3637
pub mod player_list;
3738
pub mod scoreboard;
3839
pub mod sound;

crates/valence_packet/src/packets.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use std::borrow::Cow;
2+
use std::io::Write;
3+
4+
use anyhow::bail;
5+
use uuid::Uuid;
6+
use valence_core::ident::Ident;
7+
use valence_core::property::Property;
8+
use valence_core::protocol::raw::RawBytes;
9+
use valence_core::protocol::var_int::VarInt;
10+
use valence_core::protocol::{packet_id, Decode, Encode, Packet};
11+
use valence_core::text::Text;
12+
13+
pub mod handshaking;
14+
pub mod login;
15+
pub mod play;
16+
pub mod status;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use super::*;
2+
3+
#[derive(Clone, Debug, Encode, Decode, Packet)]
4+
#[packet(id = packet_id::HANDSHAKE_C2S, state = PacketState::Handshaking)]
5+
pub struct HandshakeC2s<'a> {
6+
pub protocol_version: VarInt,
7+
pub server_address: &'a str,
8+
pub server_port: u16,
9+
pub next_state: HandshakeNextState,
10+
}
11+
12+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Encode, Decode)]
13+
pub enum HandshakeNextState {
14+
#[packet(tag = 1)]
15+
Status,
16+
#[packet(tag = 2)]
17+
Login,
18+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
use valence_core::protocol::PacketState;
2+
3+
use super::*;
4+
5+
pub mod handshake_c2s;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use valence_core::protocol::PacketState;
2+
3+
use super::*;
4+
5+
#[derive(Copy, Clone, Debug, Encode, Decode, Packet)]
6+
#[packet(id = packet_id::LOGIN_COMPRESSION_S2C, state = PacketState::Login)]
7+
pub struct LoginCompressionS2c {
8+
pub threshold: VarInt,
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use super::*;
2+
3+
#[derive(Clone, Debug, Encode, Decode, Packet)]
4+
#[packet(id = packet_id::LOGIN_DISCONNECT_S2C, state = PacketState::Login)]
5+
pub struct LoginDisconnectS2c<'a> {
6+
pub reason: Cow<'a, Text>,
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use super::*;
2+
3+
#[derive(Clone, Debug, Encode, Decode, Packet)]
4+
#[packet(id = packet_id::LOGIN_HELLO_C2S, state = PacketState::Login)]
5+
pub struct LoginHelloC2s<'a> {
6+
pub username: &'a str, // TODO: bound this
7+
pub profile_id: Option<Uuid>,
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use super::*;
2+
3+
#[derive(Copy, Clone, Debug, Encode, Decode, Packet)]
4+
#[packet(id = packet_id::LOGIN_HELLO_S2C, state = PacketState::Login)]
5+
pub struct LoginHelloS2c<'a> {
6+
pub server_id: &'a str,
7+
pub public_key: &'a [u8],
8+
pub verify_token: &'a [u8],
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use super::*;
2+
3+
#[derive(Clone, Debug, Encode, Decode, Packet)]
4+
#[packet(id = packet_id::LOGIN_KEY_C2S, state = PacketState::Login)]
5+
pub struct LoginKeyC2s<'a> {
6+
pub shared_secret: &'a [u8],
7+
pub verify_token: &'a [u8],
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use super::*;
2+
3+
#[derive(Clone, Debug, Encode, Decode, Packet)]
4+
#[packet(id = packet_id::LOGIN_QUERY_REQUEST_S2C, state = PacketState::Login)]
5+
pub struct LoginQueryRequestS2c<'a> {
6+
pub message_id: VarInt,
7+
pub channel: Ident<Cow<'a, str>>,
8+
pub data: RawBytes<'a>,
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use super::*;
2+
3+
#[derive(Clone, Debug, Encode, Decode, Packet)]
4+
#[packet(id = packet_id::LOGIN_QUERY_RESPONSE_C2S, state = PacketState::Login)]
5+
pub struct LoginQueryResponseC2s<'a> {
6+
pub message_id: VarInt,
7+
pub data: Option<RawBytes<'a>>,
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use super::*;
2+
3+
#[derive(Clone, Debug, Encode, Decode, Packet)]
4+
#[packet(id = packet_id::LOGIN_SUCCESS_S2C, state = PacketState::Login)]
5+
pub struct LoginSuccessS2c<'a> {
6+
pub uuid: Uuid,
7+
pub username: &'a str, // TODO: bound this.
8+
pub properties: Cow<'a, [Property]>,
9+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use valence_core::protocol::PacketState;
2+
3+
use super::*;
4+
5+
pub mod login_compression_s2c;
6+
pub mod login_disconnect_s2c;
7+
pub mod login_hello_c2s;
8+
pub mod login_hello_s2c;
9+
pub mod login_key_c2s;
10+
pub mod login_query_request_s2c;
11+
pub mod login_query_response_c2s;
12+
pub mod login_success_s2c;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use super::*;
2+
3+
#[derive(Clone, Debug, Encode, Decode, Packet)]
4+
#[packet(id = packet_id::ADVANCEMENT_TAB_C2S)]
5+
pub enum AdvancementTabC2s<'a> {
6+
OpenedTab { tab_id: Ident<Cow<'a, str>> },
7+
ClosedScreen,
8+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
use super::*;
2+
3+
#[derive(Clone, Debug, Encode, Decode, Packet)]
4+
#[packet(id = packet_id::ADVANCEMENT_UPDATE_S2C)]
5+
pub struct GenericAdvancementUpdateS2c<'a, AM: 'a> {
6+
pub reset: bool,
7+
pub advancement_mapping: Vec<AM>,
8+
pub identifiers: Vec<Ident<Cow<'a, str>>>,
9+
pub progress_mapping: Vec<(Ident<Cow<'a, str>>, Vec<AdvancementCriteria<'a>>)>,
10+
}
11+
12+
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode)]
13+
pub struct AdvancementCriteria<'a> {
14+
pub criterion_identifier: Ident<Cow<'a, str>>,
15+
/// If present, the criteria has been achieved at the
16+
/// time wrapped; time represented as millis since epoch
17+
pub criterion_progress: Option<i64>,
18+
}
19+
20+
#[derive(Clone, PartialEq, Debug)]
21+
pub struct AdvancementDisplay<'a, I> {
22+
pub title: Cow<'a, Text>,
23+
pub description: Cow<'a, Text>,
24+
pub icon: I,
25+
pub frame_type: VarInt,
26+
pub flags: i32,
27+
pub background_texture: Option<Ident<Cow<'a, str>>>,
28+
pub x_coord: f32,
29+
pub y_coord: f32,
30+
}
31+
32+
impl<I: Encode> Encode for AdvancementDisplay<'_, I> {
33+
fn encode(&self, mut w: impl Write) -> anyhow::Result<()> {
34+
self.title.encode(&mut w)?;
35+
self.description.encode(&mut w)?;
36+
self.icon.encode(&mut w)?;
37+
self.frame_type.encode(&mut w)?;
38+
self.flags.encode(&mut w)?;
39+
40+
match self.background_texture.as_ref() {
41+
None => {}
42+
Some(texture) => texture.encode(&mut w)?,
43+
}
44+
45+
self.x_coord.encode(&mut w)?;
46+
self.y_coord.encode(&mut w)?;
47+
48+
Ok(())
49+
}
50+
}
51+
52+
impl<'a, I: Decode<'a>> Decode<'a> for AdvancementDisplay<'a, I> {
53+
fn decode(r: &mut &'a [u8]) -> anyhow::Result<Self> {
54+
let title = <Cow<'a, Text>>::decode(r)?;
55+
let description = <Cow<'a, Text>>::decode(r)?;
56+
let icon = I::decode(r)?;
57+
let frame_type = VarInt::decode(r)?;
58+
let flags = i32::decode(r)?;
59+
60+
let background_texture = if flags & 1 == 1 {
61+
Some(Ident::decode(r)?)
62+
} else {
63+
None
64+
};
65+
66+
let x_coord = f32::decode(r)?;
67+
let y_coord = f32::decode(r)?;
68+
69+
Ok(Self {
70+
title,
71+
description,
72+
icon,
73+
frame_type,
74+
flags,
75+
background_texture,
76+
x_coord,
77+
y_coord,
78+
})
79+
}
80+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use super::*;
2+
3+
#[derive(Copy, Clone, Debug, Encode, Decode, Packet)]
4+
#[packet(id = packet_id::BLOCK_BREAKING_PROGRESS_S2C)]
5+
pub struct BlockBreakingProgressS2c {
6+
pub entity_id: VarInt,
7+
pub position: BlockPos,
8+
pub destroy_stage: u8,
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use super::*;
2+
3+
#[derive(Clone, Debug, Encode, Decode, Packet)]
4+
#[packet(id = packet_id::BLOCK_ENTITY_UPDATE_S2C)]
5+
pub struct BlockEntityUpdateS2c<'a> {
6+
pub position: BlockPos,
7+
pub kind: VarInt,
8+
pub data: Cow<'a, Compound>,
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use super::*;
2+
3+
#[derive(Copy, Clone, Debug, Encode, Decode, Packet)]
4+
#[packet(id = packet_id::BLOCK_EVENT_S2C)]
5+
pub struct BlockEventS2c {
6+
pub position: BlockPos,
7+
pub action_id: u8,
8+
pub action_parameter: u8,
9+
pub block_type: VarInt,
10+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use super::*;
2+
3+
#[derive(Copy, Clone, Debug, Encode, Decode, Packet)]
4+
#[packet(id = packet_id::BLOCK_UPDATE_S2C)]
5+
pub struct BlockUpdateS2c {
6+
pub position: BlockPos,
7+
pub block_id: VarInt,
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use super::*;
2+
3+
#[derive(Copy, Clone, Debug, Encode, Decode, Packet)]
4+
#[packet(id = packet_id::BOAT_PADDLE_STATE_C2S)]
5+
pub struct BoatPaddleStateC2s {
6+
pub left_paddle_turning: bool,
7+
pub right_paddle_turning: bool,
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use super::*;
2+
3+
#[derive(Clone, Debug, Encode, Decode, Packet)]
4+
#[packet(id = packet_id::BOOK_UPDATE_C2S)]
5+
pub struct BookUpdateC2s<'a> {
6+
pub slot: VarInt,
7+
pub entries: Vec<&'a str>,
8+
pub title: Option<&'a str>,
9+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use valence_core::boss_bar::{BossBarColor, BossBarDivision, BossBarFlags};
2+
3+
use super::*;
4+
5+
#[derive(Clone, Debug, Encode, Decode, Packet)]
6+
#[packet(id = packet_id::BOSS_BAR_S2C)]
7+
pub struct BossBarS2c<'a> {
8+
pub id: Uuid,
9+
pub action: BossBarAction<'a>,
10+
}
11+
12+
#[derive(Clone, PartialEq, Debug, Encode, Decode)]
13+
pub enum BossBarAction<'a> {
14+
Add {
15+
title: Cow<'a, Text>,
16+
health: f32,
17+
color: BossBarColor,
18+
division: BossBarDivision,
19+
flags: BossBarFlags,
20+
},
21+
Remove,
22+
UpdateHealth(f32),
23+
UpdateTitle(Cow<'a, Text>),
24+
UpdateStyle(BossBarColor, BossBarDivision),
25+
UpdateFlags(BossBarFlags),
26+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
use super::*;
2+
3+
#[derive(Copy, Clone, Debug, Encode, Decode, Packet)]
4+
#[packet(id = packet_id::BUNDLE_SPLITTER)]
5+
pub struct BundleSplitterS2c;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use super::*;
2+
3+
#[derive(Copy, Clone, Debug, Encode, Decode, Packet)]
4+
#[packet(id = packet_id::BUTTON_CLICK_C2S)]
5+
pub struct ButtonClickC2s {
6+
pub window_id: i8,
7+
pub button_id: i8,
8+
}

0 commit comments

Comments
 (0)