documentation improvements
This commit is contained in:
1 parent
9e634295ca
commit
530a5c8667
6 files changed
+70
-45
No files matched your search
+40
-11
@@ -21,14 +21,43 @@ Packets in the Pumpkin protocol are organized by functionality and state.
|
||||
### How to add a Packet ?
|
||||
You can find all Minecraft Java packets at https://wiki.vg/Protocol. There you also can see in which [State](State) they are.
|
||||
You also can see all the information the Packets has which we can either Write or Read depending if its Serverbound or Clientbound
|
||||
#### Adding a Serverbound Packet
|
||||
Serverbound Packets do use the trait `ServerPacket` which has an packet id (use hex) and can read incoming Client packets.
|
||||
https://wiki.vg/Protocol gives you the Packet structure which you can than read. Feel free to orientate on already existing Packets.
|
||||
Please use a name structure like `SPacketName` for the struct, The 'S' representing its Serverbound.
|
||||
Registering: Don't forget to register the Packet. All Packets before the Player is created so before the Play state. Are using the `ClientPacketProcessor` which calls the packet at `Client::handle_packet` (both in the pumpkin crate)
|
||||
#### Adding a Clientbound Packet
|
||||
Clientbound Packets do use the trait `ClientPacket` which has an packet id (use hex) and can write outgoining Server packets.
|
||||
https://wiki.vg/Protocol gives you the Packet structure which you can than write. Feel free to orientate on already existing Packets.
|
||||
Please use a name structure like `CPacketName` for the struct, The 'C' representing its Clientbound.
|
||||
You don't need to register the Packet anywhere, You should just be able now to send it via `Client::send_packet` this will get a result. You should kick the client when an important Packet could't been send. Otherwise
|
||||
just log an warn.
|
||||
#### Adding a Packet
|
||||
Adding a Packet is easy. First you have to dereive serde Serialize.
|
||||
```rust
|
||||
#[derive(Serialize)]
|
||||
```
|
||||
Next you have set the packet id using the packet macro
|
||||
```rust
|
||||
#[packet(0x1D)]
|
||||
```
|
||||
Now you can create the Field. Please start the Packet name with "C" if its Clientbound and with "S" if its Serverbound.
|
||||
Example:
|
||||
```rust
|
||||
pub struct CPlayDisconnect {
|
||||
reason: TextComponent,
|
||||
more fields...
|
||||
}
|
||||
```
|
||||
Also don't forgot to impl a new function for Clientbound Packets so we can actaully send then by putting in the values :D
|
||||
Example:
|
||||
```rust
|
||||
impl CPlayDisconnect {
|
||||
pub fn new(reason: TextComponent) -> Self {
|
||||
Self { reason }
|
||||
}
|
||||
}
|
||||
```
|
||||
At the End everything should come together
|
||||
```rust
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x1D)]
|
||||
pub struct CPlayDisconnect {
|
||||
reason: TextComponent,
|
||||
}
|
||||
|
||||
impl CPlayDisconnect {
|
||||
pub fn new(reason: TextComponent) -> Self {
|
||||
Self { reason }
|
||||
}
|
||||
}
|
||||
``
|
||||
@@ -132,14 +132,14 @@ pub enum ConnectionState {
|
||||
Play,
|
||||
}
|
||||
|
||||
impl ConnectionState {
|
||||
pub fn from_varint(var_int: VarInt) -> Self {
|
||||
match var_int {
|
||||
impl From<VarInt> for ConnectionState {
|
||||
fn from(value: VarInt) -> Self {
|
||||
match value {
|
||||
1 => Self::Status,
|
||||
2 => Self::Login,
|
||||
3 => Self::Transfer,
|
||||
_ => {
|
||||
log::info!("Unexpected Status {}", var_int);
|
||||
log::info!("Unexpected Status {}", value);
|
||||
Self::Status
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ impl ServerPacket for SHandShake {
|
||||
protocol_version: bytebuf.get_var_int(),
|
||||
server_address: bytebuf.get_string_len(255).unwrap(),
|
||||
server_port: bytebuf.get_u16(),
|
||||
next_state: ConnectionState::from_varint(bytebuf.get_var_int()),
|
||||
next_state: bytebuf.get_var_int().into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ use core::str;
|
||||
use fastnbt::SerOpts;
|
||||
use serde::Deserialize;
|
||||
|
||||
// represents a text component
|
||||
// Fepresents a Text component
|
||||
// Reference: https://wiki.vg/Text_formatting#Text_components
|
||||
#[derive(Clone, PartialEq, Default, Debug, Deserialize)]
|
||||
pub struct TextComponent {
|
||||
|
||||
Reference in new issue
Block a user