-
-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
185 changed files
with
3,910 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
# TODO | ||
# valence_packet | ||
|
||
This contain all (some) the packets structures of the minecraft protocol #763. | ||
|
||
## Naming | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use std::borrow::Cow; | ||
use std::io::Write; | ||
|
||
use anyhow::bail; | ||
use uuid::Uuid; | ||
use valence_core::ident::Ident; | ||
use valence_core::property::Property; | ||
use valence_core::protocol::raw::RawBytes; | ||
use valence_core::protocol::var_int::VarInt; | ||
use valence_core::protocol::{packet_id, Decode, Encode, Packet}; | ||
use valence_core::text::Text; | ||
|
||
pub mod handshaking; | ||
pub mod login; | ||
pub mod play; | ||
pub mod status; |
18 changes: 18 additions & 0 deletions
18
crates/valence_packet/src/packets/handshaking/handshake_c2s.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use super::*; | ||
|
||
#[derive(Clone, Debug, Encode, Decode, Packet)] | ||
#[packet(id = packet_id::HANDSHAKE_C2S, state = PacketState::Handshaking)] | ||
pub struct HandshakeC2s<'a> { | ||
pub protocol_version: VarInt, | ||
pub server_address: &'a str, | ||
pub server_port: u16, | ||
pub next_state: HandshakeNextState, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Encode, Decode)] | ||
pub enum HandshakeNextState { | ||
#[packet(tag = 1)] | ||
Status, | ||
#[packet(tag = 2)] | ||
Login, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use valence_core::protocol::PacketState; | ||
|
||
use super::*; | ||
|
||
pub mod handshake_c2s; |
9 changes: 9 additions & 0 deletions
9
crates/valence_packet/src/packets/login/login_compression_s2c.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use valence_core::protocol::PacketState; | ||
|
||
use super::*; | ||
|
||
#[derive(Copy, Clone, Debug, Encode, Decode, Packet)] | ||
#[packet(id = packet_id::LOGIN_COMPRESSION_S2C, state = PacketState::Login)] | ||
pub struct LoginCompressionS2c { | ||
pub threshold: VarInt, | ||
} |
7 changes: 7 additions & 0 deletions
7
crates/valence_packet/src/packets/login/login_disconnect_s2c.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use super::*; | ||
|
||
#[derive(Clone, Debug, Encode, Decode, Packet)] | ||
#[packet(id = packet_id::LOGIN_DISCONNECT_S2C, state = PacketState::Login)] | ||
pub struct LoginDisconnectS2c<'a> { | ||
pub reason: Cow<'a, Text>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use super::*; | ||
|
||
#[derive(Clone, Debug, Encode, Decode, Packet)] | ||
#[packet(id = packet_id::LOGIN_HELLO_C2S, state = PacketState::Login)] | ||
pub struct LoginHelloC2s<'a> { | ||
pub username: &'a str, // TODO: bound this | ||
pub profile_id: Option<Uuid>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use super::*; | ||
|
||
#[derive(Copy, Clone, Debug, Encode, Decode, Packet)] | ||
#[packet(id = packet_id::LOGIN_HELLO_S2C, state = PacketState::Login)] | ||
pub struct LoginHelloS2c<'a> { | ||
pub server_id: &'a str, | ||
pub public_key: &'a [u8], | ||
pub verify_token: &'a [u8], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use super::*; | ||
|
||
#[derive(Clone, Debug, Encode, Decode, Packet)] | ||
#[packet(id = packet_id::LOGIN_KEY_C2S, state = PacketState::Login)] | ||
pub struct LoginKeyC2s<'a> { | ||
pub shared_secret: &'a [u8], | ||
pub verify_token: &'a [u8], | ||
} |
9 changes: 9 additions & 0 deletions
9
crates/valence_packet/src/packets/login/login_query_request_s2c.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use super::*; | ||
|
||
#[derive(Clone, Debug, Encode, Decode, Packet)] | ||
#[packet(id = packet_id::LOGIN_QUERY_REQUEST_S2C, state = PacketState::Login)] | ||
pub struct LoginQueryRequestS2c<'a> { | ||
pub message_id: VarInt, | ||
pub channel: Ident<Cow<'a, str>>, | ||
pub data: RawBytes<'a>, | ||
} |
8 changes: 8 additions & 0 deletions
8
crates/valence_packet/src/packets/login/login_query_response_c2s.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use super::*; | ||
|
||
#[derive(Clone, Debug, Encode, Decode, Packet)] | ||
#[packet(id = packet_id::LOGIN_QUERY_RESPONSE_C2S, state = PacketState::Login)] | ||
pub struct LoginQueryResponseC2s<'a> { | ||
pub message_id: VarInt, | ||
pub data: Option<RawBytes<'a>>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use super::*; | ||
|
||
#[derive(Clone, Debug, Encode, Decode, Packet)] | ||
#[packet(id = packet_id::LOGIN_SUCCESS_S2C, state = PacketState::Login)] | ||
pub struct LoginSuccessS2c<'a> { | ||
pub uuid: Uuid, | ||
pub username: &'a str, // TODO: bound this. | ||
pub properties: Cow<'a, [Property]>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use valence_core::protocol::PacketState; | ||
|
||
use super::*; | ||
|
||
pub mod login_compression_s2c; | ||
pub mod login_disconnect_s2c; | ||
pub mod login_hello_c2s; | ||
pub mod login_hello_s2c; | ||
pub mod login_key_c2s; | ||
pub mod login_query_request_s2c; | ||
pub mod login_query_response_c2s; | ||
pub mod login_success_s2c; |
8 changes: 8 additions & 0 deletions
8
crates/valence_packet/src/packets/play/advancement_tab_c2s.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use super::*; | ||
|
||
#[derive(Clone, Debug, Encode, Decode, Packet)] | ||
#[packet(id = packet_id::ADVANCEMENT_TAB_C2S)] | ||
pub enum AdvancementTabC2s<'a> { | ||
OpenedTab { tab_id: Ident<Cow<'a, str>> }, | ||
ClosedScreen, | ||
} |
80 changes: 80 additions & 0 deletions
80
crates/valence_packet/src/packets/play/advancement_update_s2c.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use super::*; | ||
|
||
#[derive(Clone, Debug, Encode, Decode, Packet)] | ||
#[packet(id = packet_id::ADVANCEMENT_UPDATE_S2C)] | ||
pub struct GenericAdvancementUpdateS2c<'a, AM: 'a> { | ||
pub reset: bool, | ||
pub advancement_mapping: Vec<AM>, | ||
pub identifiers: Vec<Ident<Cow<'a, str>>>, | ||
pub progress_mapping: Vec<(Ident<Cow<'a, str>>, Vec<AdvancementCriteria<'a>>)>, | ||
} | ||
|
||
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode)] | ||
pub struct AdvancementCriteria<'a> { | ||
pub criterion_identifier: Ident<Cow<'a, str>>, | ||
/// If present, the criteria has been achieved at the | ||
/// time wrapped; time represented as millis since epoch | ||
pub criterion_progress: Option<i64>, | ||
} | ||
|
||
#[derive(Clone, PartialEq, Debug)] | ||
pub struct AdvancementDisplay<'a, I> { | ||
pub title: Cow<'a, Text>, | ||
pub description: Cow<'a, Text>, | ||
pub icon: I, | ||
pub frame_type: VarInt, | ||
pub flags: i32, | ||
pub background_texture: Option<Ident<Cow<'a, str>>>, | ||
pub x_coord: f32, | ||
pub y_coord: f32, | ||
} | ||
|
||
impl<I: Encode> Encode for AdvancementDisplay<'_, I> { | ||
fn encode(&self, mut w: impl Write) -> anyhow::Result<()> { | ||
self.title.encode(&mut w)?; | ||
self.description.encode(&mut w)?; | ||
self.icon.encode(&mut w)?; | ||
self.frame_type.encode(&mut w)?; | ||
self.flags.encode(&mut w)?; | ||
|
||
match self.background_texture.as_ref() { | ||
None => {} | ||
Some(texture) => texture.encode(&mut w)?, | ||
} | ||
|
||
self.x_coord.encode(&mut w)?; | ||
self.y_coord.encode(&mut w)?; | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
impl<'a, I: Decode<'a>> Decode<'a> for AdvancementDisplay<'a, I> { | ||
fn decode(r: &mut &'a [u8]) -> anyhow::Result<Self> { | ||
let title = <Cow<'a, Text>>::decode(r)?; | ||
let description = <Cow<'a, Text>>::decode(r)?; | ||
let icon = I::decode(r)?; | ||
let frame_type = VarInt::decode(r)?; | ||
let flags = i32::decode(r)?; | ||
|
||
let background_texture = if flags & 1 == 1 { | ||
Some(Ident::decode(r)?) | ||
} else { | ||
None | ||
}; | ||
|
||
let x_coord = f32::decode(r)?; | ||
let y_coord = f32::decode(r)?; | ||
|
||
Ok(Self { | ||
title, | ||
description, | ||
icon, | ||
frame_type, | ||
flags, | ||
background_texture, | ||
x_coord, | ||
y_coord, | ||
}) | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
crates/valence_packet/src/packets/play/block_breaking_progress_s2c.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use super::*; | ||
|
||
#[derive(Copy, Clone, Debug, Encode, Decode, Packet)] | ||
#[packet(id = packet_id::BLOCK_BREAKING_PROGRESS_S2C)] | ||
pub struct BlockBreakingProgressS2c { | ||
pub entity_id: VarInt, | ||
pub position: BlockPos, | ||
pub destroy_stage: u8, | ||
} |
9 changes: 9 additions & 0 deletions
9
crates/valence_packet/src/packets/play/block_entity_update_s2c.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use super::*; | ||
|
||
#[derive(Clone, Debug, Encode, Decode, Packet)] | ||
#[packet(id = packet_id::BLOCK_ENTITY_UPDATE_S2C)] | ||
pub struct BlockEntityUpdateS2c<'a> { | ||
pub position: BlockPos, | ||
pub kind: VarInt, | ||
pub data: Cow<'a, Compound>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use super::*; | ||
|
||
#[derive(Copy, Clone, Debug, Encode, Decode, Packet)] | ||
#[packet(id = packet_id::BLOCK_EVENT_S2C)] | ||
pub struct BlockEventS2c { | ||
pub position: BlockPos, | ||
pub action_id: u8, | ||
pub action_parameter: u8, | ||
pub block_type: VarInt, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use super::*; | ||
|
||
#[derive(Copy, Clone, Debug, Encode, Decode, Packet)] | ||
#[packet(id = packet_id::BLOCK_UPDATE_S2C)] | ||
pub struct BlockUpdateS2c { | ||
pub position: BlockPos, | ||
pub block_id: VarInt, | ||
} |
8 changes: 8 additions & 0 deletions
8
crates/valence_packet/src/packets/play/boat_paddle_state_c2s.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use super::*; | ||
|
||
#[derive(Copy, Clone, Debug, Encode, Decode, Packet)] | ||
#[packet(id = packet_id::BOAT_PADDLE_STATE_C2S)] | ||
pub struct BoatPaddleStateC2s { | ||
pub left_paddle_turning: bool, | ||
pub right_paddle_turning: bool, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use super::*; | ||
|
||
#[derive(Clone, Debug, Encode, Decode, Packet)] | ||
#[packet(id = packet_id::BOOK_UPDATE_C2S)] | ||
pub struct BookUpdateC2s<'a> { | ||
pub slot: VarInt, | ||
pub entries: Vec<&'a str>, | ||
pub title: Option<&'a str>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use valence_core::boss_bar::{BossBarColor, BossBarDivision, BossBarFlags}; | ||
|
||
use super::*; | ||
|
||
#[derive(Clone, Debug, Encode, Decode, Packet)] | ||
#[packet(id = packet_id::BOSS_BAR_S2C)] | ||
pub struct BossBarS2c<'a> { | ||
pub id: Uuid, | ||
pub action: BossBarAction<'a>, | ||
} | ||
|
||
#[derive(Clone, PartialEq, Debug, Encode, Decode)] | ||
pub enum BossBarAction<'a> { | ||
Add { | ||
title: Cow<'a, Text>, | ||
health: f32, | ||
color: BossBarColor, | ||
division: BossBarDivision, | ||
flags: BossBarFlags, | ||
}, | ||
Remove, | ||
UpdateHealth(f32), | ||
UpdateTitle(Cow<'a, Text>), | ||
UpdateStyle(BossBarColor, BossBarDivision), | ||
UpdateFlags(BossBarFlags), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use super::*; | ||
|
||
#[derive(Copy, Clone, Debug, Encode, Decode, Packet)] | ||
#[packet(id = packet_id::BUNDLE_SPLITTER)] | ||
pub struct BundleSplitterS2c; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use super::*; | ||
|
||
#[derive(Copy, Clone, Debug, Encode, Decode, Packet)] | ||
#[packet(id = packet_id::BUTTON_CLICK_C2S)] | ||
pub struct ButtonClickC2s { | ||
pub window_id: i8, | ||
pub button_id: i8, | ||
} |
Oops, something went wrong.