Begin Refactoring Clientbound Packets to new structure
See https://github.com/Snowiiii/Pumpkin/issues/19 for details
This commit is contained in:
1 parent
1e114c008e
commit
9e634295ca
14 files changed
+76
-151
No files matched your search
@@ -1,20 +1,15 @@
|
||||
use pumpkin_macros::packet;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{bytebuf::ByteBuffer, ClientPacket};
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x00)]
|
||||
pub struct CLoginDisconnect<'a> {
|
||||
reason: &'a str,
|
||||
json_reason: &'a str,
|
||||
}
|
||||
|
||||
impl<'a> CLoginDisconnect<'a> {
|
||||
pub fn new(reason: &'a str) -> Self {
|
||||
Self { reason }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ClientPacket for CLoginDisconnect<'a> {
|
||||
fn write(&self, bytebuf: &mut ByteBuffer) {
|
||||
bytebuf.put_string(&serde_json::to_string_pretty(&self.reason).unwrap());
|
||||
// input json!
|
||||
pub fn new(json_reason: &'a str) -> Self {
|
||||
Self { json_reason }
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,16 @@
|
||||
use pumpkin_macros::packet;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{bytebuf::ByteBuffer, ClientPacket, VarInt};
|
||||
use crate::VarInt32;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x03)]
|
||||
pub struct CSetCompression {
|
||||
threshold: VarInt,
|
||||
threshold: VarInt32,
|
||||
}
|
||||
|
||||
impl CSetCompression {
|
||||
pub fn new(threshold: VarInt) -> Self {
|
||||
pub fn new(threshold: VarInt32) -> Self {
|
||||
Self { threshold }
|
||||
}
|
||||
}
|
||||
|
||||
impl ClientPacket for CSetCompression {
|
||||
fn write(&self, bytebuf: &mut ByteBuffer) {
|
||||
bytebuf.put_var_int(self.threshold);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
use pumpkin_macros::packet;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{bytebuf::ByteBuffer, ClientPacket};
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x0B)]
|
||||
pub struct CChangeDifficulty {
|
||||
difficulty: u8,
|
||||
@@ -13,10 +13,3 @@ impl CChangeDifficulty {
|
||||
Self { difficulty, locked }
|
||||
}
|
||||
}
|
||||
|
||||
impl ClientPacket for CChangeDifficulty {
|
||||
fn write(&self, bytebuf: &mut ByteBuffer) {
|
||||
bytebuf.put_u8(self.difficulty);
|
||||
bytebuf.put_bool(self.locked);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
use pumpkin_macros::packet;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{bytebuf::ByteBuffer, ClientPacket};
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x22)]
|
||||
pub struct CGameEvent {
|
||||
event: u8,
|
||||
@@ -13,10 +13,3 @@ impl CGameEvent {
|
||||
Self { event, value }
|
||||
}
|
||||
}
|
||||
|
||||
impl ClientPacket for CGameEvent {
|
||||
fn write(&self, bytebuf: &mut ByteBuffer) {
|
||||
bytebuf.put_u8(self.event);
|
||||
bytebuf.put_f32(self.value);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
use pumpkin_macros::packet;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{bytebuf::ByteBuffer, text::TextComponent, ClientPacket};
|
||||
use crate::text::TextComponent;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x1D)]
|
||||
pub struct CPlayDisconnect {
|
||||
reason: TextComponent,
|
||||
@@ -12,9 +14,3 @@ impl CPlayDisconnect {
|
||||
Self { reason }
|
||||
}
|
||||
}
|
||||
|
||||
impl ClientPacket for CPlayDisconnect {
|
||||
fn write(&self, bytebuf: &mut ByteBuffer) {
|
||||
bytebuf.put_slice(&self.reason.encode());
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
use pumpkin_macros::packet;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{bytebuf::ByteBuffer, ClientPacket};
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x53)]
|
||||
pub struct CSetHeldItem {
|
||||
slot: i8,
|
||||
@@ -12,9 +12,3 @@ impl CSetHeldItem {
|
||||
Self { slot }
|
||||
}
|
||||
}
|
||||
|
||||
impl ClientPacket for CSetHeldItem {
|
||||
fn write(&self, bytebuf: &mut ByteBuffer) {
|
||||
bytebuf.put_i8(self.slot);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
use pumpkin_macros::packet;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{bytebuf::ByteBuffer, ClientPacket, VarInt};
|
||||
use crate::VarInt32;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x40)]
|
||||
pub struct CSyncPlayerPostion {
|
||||
x: f64,
|
||||
@@ -10,7 +12,7 @@ pub struct CSyncPlayerPostion {
|
||||
yaw: f32,
|
||||
pitch: f32,
|
||||
flags: i8,
|
||||
teleport_id: VarInt,
|
||||
teleport_id: VarInt32,
|
||||
}
|
||||
|
||||
impl CSyncPlayerPostion {
|
||||
@@ -21,7 +23,7 @@ impl CSyncPlayerPostion {
|
||||
yaw: f32,
|
||||
pitch: f32,
|
||||
flags: i8,
|
||||
teleport_id: VarInt,
|
||||
teleport_id: VarInt32,
|
||||
) -> Self {
|
||||
Self {
|
||||
x,
|
||||
@@ -34,15 +36,3 @@ impl CSyncPlayerPostion {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ClientPacket for CSyncPlayerPostion {
|
||||
fn write(&self, bytebuf: &mut ByteBuffer) {
|
||||
bytebuf.put_f64(self.x);
|
||||
bytebuf.put_f64(self.y);
|
||||
bytebuf.put_f64(self.z);
|
||||
bytebuf.put_f32(self.yaw.to_degrees());
|
||||
bytebuf.put_f32(self.pitch.to_degrees());
|
||||
bytebuf.put_i8(self.flags);
|
||||
bytebuf.put_var_int(self.teleport_id);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
use pumpkin_macros::packet;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{bytebuf::ByteBuffer, text::TextComponent, ClientPacket};
|
||||
use crate::text::TextComponent;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x6C)]
|
||||
pub struct CSystemChatMessge {
|
||||
content: TextComponent,
|
||||
@@ -13,10 +15,3 @@ impl CSystemChatMessge {
|
||||
Self { content, overlay }
|
||||
}
|
||||
}
|
||||
|
||||
impl ClientPacket for CSystemChatMessge {
|
||||
fn write(&self, bytebuf: &mut ByteBuffer) {
|
||||
bytebuf.put_slice(&self.content.encode());
|
||||
bytebuf.put_bool(self.overlay);
|
||||
}
|
||||
}
|
||||
@@ -90,6 +90,12 @@ impl VarInt32 {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<i32> for VarInt32 {
|
||||
fn from(value: i32) -> Self {
|
||||
VarInt32(value)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug, Error)]
|
||||
pub enum VarIntDecodeError {
|
||||
#[error("incomplete VarInt decode")]
|
||||
|
||||
Reference in new issue
Block a user