Update serializer for more types
This commit is contained in:
parent
a5110eb939
commit
1fed6dca5f
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1185,6 +1185,7 @@ dependencies = [
|
||||
"cfb8",
|
||||
"fastnbt 2.5.0 (git+https://github.com/owengage/fastnbt.git)",
|
||||
"log",
|
||||
"pumpkin-macros",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"take_mut",
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
[workspace]
|
||||
resolver = "2"
|
||||
members = [ "pumpkin-macros", "pumpkin-protocol/", "pumpkin-registry/", "pumpkin-world", "pumpkin/"]
|
||||
members = [ "pumpkin-macros/", "pumpkin-protocol/", "pumpkin-registry/", "pumpkin-world", "pumpkin/" ]
|
||||
|
||||
[workspace.package]
|
||||
version = "0.1.0"
|
||||
@ -8,4 +8,3 @@ edition = "2021"
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
|
||||
|
||||
@ -4,6 +4,9 @@ version.workspace = true
|
||||
edition.workspace = true
|
||||
|
||||
[dependencies]
|
||||
|
||||
pumpkin-macros = { path = "../pumpkin-macros" }
|
||||
|
||||
bytes = "1.7"
|
||||
|
||||
uuid = "1.10"
|
||||
|
||||
@ -35,7 +35,6 @@ where
|
||||
P: Packet + Serialize,
|
||||
{
|
||||
fn write(&self, bytebuf: &mut ByteBuffer) {
|
||||
dbg!(P::PACKET_ID);
|
||||
take_mut::take(bytebuf, |bytebuf| {
|
||||
let mut serializer = serializer::Serializer::new(bytebuf);
|
||||
self.serialize(&mut serializer)
|
||||
|
||||
@ -5,6 +5,7 @@ use thiserror::Error;
|
||||
|
||||
use super::ByteBuffer;
|
||||
|
||||
|
||||
pub struct Serializer {
|
||||
output: ByteBuffer,
|
||||
}
|
||||
@ -66,32 +67,37 @@ impl<'a> ser::Serializer for &'a mut Serializer {
|
||||
Ok(())
|
||||
}
|
||||
fn serialize_char(self, _v: char) -> Result<Self::Ok, Self::Error> {
|
||||
todo!()
|
||||
unimplemented!()
|
||||
}
|
||||
fn serialize_f32(self, _v: f32) -> Result<Self::Ok, Self::Error> {
|
||||
todo!()
|
||||
fn serialize_f32(self, v: f32) -> Result<Self::Ok, Self::Error> {
|
||||
self.output.put_f32(v);
|
||||
Ok(())
|
||||
}
|
||||
fn serialize_f64(self, _v: f64) -> Result<Self::Ok, Self::Error> {
|
||||
todo!()
|
||||
fn serialize_f64(self, v: f64) -> Result<Self::Ok, Self::Error> {
|
||||
self.output.put_f64(v);
|
||||
Ok(())
|
||||
}
|
||||
fn serialize_i128(self, _v: i128) -> Result<Self::Ok, Self::Error> {
|
||||
todo!()
|
||||
unimplemented!()
|
||||
}
|
||||
fn serialize_i16(self, _v: i16) -> Result<Self::Ok, Self::Error> {
|
||||
todo!()
|
||||
fn serialize_i16(self, v: i16) -> Result<Self::Ok, Self::Error> {
|
||||
self.output.put_i16(v);
|
||||
Ok(())
|
||||
}
|
||||
fn serialize_i32(self, _v: i32) -> Result<Self::Ok, Self::Error> {
|
||||
todo!()
|
||||
fn serialize_i32(self, v: i32) -> Result<Self::Ok, Self::Error> {
|
||||
self.output.put_i32(v);
|
||||
Ok(())
|
||||
}
|
||||
fn serialize_i64(self, v: i64) -> Result<Self::Ok, Self::Error> {
|
||||
self.output.put_i64(v);
|
||||
Ok(())
|
||||
}
|
||||
fn serialize_i8(self, _v: i8) -> Result<Self::Ok, Self::Error> {
|
||||
todo!()
|
||||
fn serialize_i8(self, v: i8) -> Result<Self::Ok, Self::Error> {
|
||||
self.output.put_i8(v);
|
||||
Ok(())
|
||||
}
|
||||
fn serialize_map(self, _len: Option<usize>) -> Result<Self::SerializeMap, Self::Error> {
|
||||
todo!()
|
||||
unimplemented!()
|
||||
}
|
||||
fn serialize_newtype_struct<T>(
|
||||
self,
|
||||
@ -101,7 +107,7 @@ impl<'a> ser::Serializer for &'a mut Serializer {
|
||||
where
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
todo!()
|
||||
unimplemented!()
|
||||
}
|
||||
fn serialize_newtype_variant<T>(
|
||||
self,
|
||||
@ -113,19 +119,19 @@ impl<'a> ser::Serializer for &'a mut Serializer {
|
||||
where
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
todo!()
|
||||
unimplemented!()
|
||||
}
|
||||
fn serialize_none(self) -> Result<Self::Ok, Self::Error> {
|
||||
todo!()
|
||||
unimplemented!()
|
||||
}
|
||||
fn serialize_seq(self, _len: Option<usize>) -> Result<Self::SerializeSeq, Self::Error> {
|
||||
todo!()
|
||||
unimplemented!()
|
||||
}
|
||||
fn serialize_some<T>(self, _value: &T) -> Result<Self::Ok, Self::Error>
|
||||
where
|
||||
T: ?Sized + Serialize,
|
||||
{
|
||||
todo!()
|
||||
unimplemented!()
|
||||
}
|
||||
fn serialize_str(self, v: &str) -> Result<Self::Ok, Self::Error> {
|
||||
self.output.put_string(v);
|
||||
@ -145,17 +151,17 @@ impl<'a> ser::Serializer for &'a mut Serializer {
|
||||
_variant: &'static str,
|
||||
_len: usize,
|
||||
) -> Result<Self::SerializeStructVariant, Self::Error> {
|
||||
todo!()
|
||||
unimplemented!()
|
||||
}
|
||||
fn serialize_tuple(self, _len: usize) -> Result<Self::SerializeTuple, Self::Error> {
|
||||
todo!()
|
||||
unimplemented!()
|
||||
}
|
||||
fn serialize_tuple_struct(
|
||||
self,
|
||||
_name: &'static str,
|
||||
_len: usize,
|
||||
) -> Result<Self::SerializeTupleStruct, Self::Error> {
|
||||
todo!()
|
||||
unimplemented!()
|
||||
}
|
||||
fn serialize_tuple_variant(
|
||||
self,
|
||||
@ -164,25 +170,29 @@ impl<'a> ser::Serializer for &'a mut Serializer {
|
||||
_variant: &'static str,
|
||||
_len: usize,
|
||||
) -> Result<Self::SerializeTupleVariant, Self::Error> {
|
||||
todo!()
|
||||
unimplemented!()
|
||||
}
|
||||
fn serialize_u128(self, _v: u128) -> Result<Self::Ok, Self::Error> {
|
||||
todo!()
|
||||
unimplemented!()
|
||||
}
|
||||
fn serialize_u16(self, _v: u16) -> Result<Self::Ok, Self::Error> {
|
||||
todo!()
|
||||
fn serialize_u16(self, v: u16) -> Result<Self::Ok, Self::Error> {
|
||||
self.output.put_u16(v);
|
||||
Ok(())
|
||||
}
|
||||
fn serialize_u32(self, _v: u32) -> Result<Self::Ok, Self::Error> {
|
||||
todo!()
|
||||
fn serialize_u32(self, v: u32) -> Result<Self::Ok, Self::Error> {
|
||||
self.output.put_u32(v);
|
||||
Ok(())
|
||||
}
|
||||
fn serialize_u64(self, _v: u64) -> Result<Self::Ok, Self::Error> {
|
||||
todo!()
|
||||
fn serialize_u64(self, v: u64) -> Result<Self::Ok, Self::Error> {
|
||||
self.output.put_u64(v);
|
||||
Ok(())
|
||||
}
|
||||
fn serialize_u8(self, _v: u8) -> Result<Self::Ok, Self::Error> {
|
||||
todo!()
|
||||
fn serialize_u8(self, v: u8) -> Result<Self::Ok, Self::Error> {
|
||||
self.output.put_u8(v);
|
||||
Ok(())
|
||||
}
|
||||
fn serialize_unit(self) -> Result<Self::Ok, Self::Error> {
|
||||
todo!()
|
||||
unimplemented!()
|
||||
}
|
||||
fn serialize_unit_struct(self, _name: &'static str) -> Result<Self::Ok, Self::Error> {
|
||||
todo!()
|
||||
|
||||
@ -1,14 +1,11 @@
|
||||
use crate::bytebuf::packet_id::Packet;
|
||||
use pumpkin_macros::packet;
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
#[packet(0x02)]
|
||||
pub struct CConfigDisconnect<'a> {
|
||||
reason: &'a str,
|
||||
}
|
||||
|
||||
impl<'a> Packet for CConfigDisconnect<'a> {
|
||||
const PACKET_ID: i32 = 0x02;
|
||||
}
|
||||
|
||||
impl<'a> CConfigDisconnect<'a> {
|
||||
pub fn new(reason: &'a str) -> Self {
|
||||
Self { reason }
|
||||
|
||||
@ -1,18 +1,12 @@
|
||||
use pumpkin_macros::packet;
|
||||
|
||||
use crate::{
|
||||
bytebuf::{packet_id::Packet, ByteBuffer},
|
||||
ClientPacket, Identifier, VarInt,
|
||||
};
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
#[packet(0x00)]
|
||||
pub struct CCookieRequest {
|
||||
key: Identifier,
|
||||
}
|
||||
|
||||
impl Packet for CCookieRequest {
|
||||
const PACKET_ID: VarInt = 0x00;
|
||||
}
|
||||
|
||||
impl ClientPacket for CCookieRequest {
|
||||
fn write(&self, bytebuf: &mut ByteBuffer) {
|
||||
bytebuf.put_string(&self.key);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
use pumpkin_macros::packet;
|
||||
|
||||
use crate::{bytebuf::packet_id::Packet, VarInt};
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
#[packet(0x03)]
|
||||
pub struct CFinishConfig {}
|
||||
|
||||
impl Default for CFinishConfig {
|
||||
@ -14,7 +17,3 @@ impl CFinishConfig {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
impl Packet for CFinishConfig {
|
||||
const PACKET_ID: VarInt = 0x03;
|
||||
}
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
use pumpkin_macros::packet;
|
||||
|
||||
use crate::{
|
||||
bytebuf::{packet_id::Packet, ByteBuffer},
|
||||
ClientPacket, KnownPack, VarInt,
|
||||
};
|
||||
|
||||
#[packet(0x0E)]
|
||||
pub struct CKnownPacks<'a> {
|
||||
known_packs: &'a [KnownPack<'a>],
|
||||
}
|
||||
@ -13,10 +16,6 @@ impl<'a> CKnownPacks<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Packet for CKnownPacks<'a> {
|
||||
const PACKET_ID: VarInt = 0x0E;
|
||||
}
|
||||
|
||||
impl<'a> ClientPacket for CKnownPacks<'a> {
|
||||
fn write(&self, bytebuf: &mut ByteBuffer) {
|
||||
bytebuf.put_list::<KnownPack>(self.known_packs, |p, v| {
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
use pumpkin_macros::packet;
|
||||
|
||||
use crate::{
|
||||
bytebuf::{packet_id::Packet, ByteBuffer},
|
||||
ClientPacket, VarInt,
|
||||
};
|
||||
|
||||
#[packet(0x01)]
|
||||
pub struct CPluginMessage<'a> {
|
||||
channel: &'a str,
|
||||
data: &'a [u8],
|
||||
@ -14,10 +17,6 @@ impl<'a> CPluginMessage<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Packet for CPluginMessage<'a> {
|
||||
const PACKET_ID: VarInt = 0x01;
|
||||
}
|
||||
|
||||
impl<'a> ClientPacket for CPluginMessage<'a> {
|
||||
fn write(&self, bytebuf: &mut ByteBuffer) {
|
||||
bytebuf.put_string(self.channel);
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
use pumpkin_macros::packet;
|
||||
|
||||
use crate::{
|
||||
bytebuf::{packet_id::Packet, ByteBuffer},
|
||||
ClientPacket, VarInt,
|
||||
};
|
||||
|
||||
#[packet(0x07)]
|
||||
pub struct CRegistryData<'a> {
|
||||
registry_id: &'a str,
|
||||
entries: &'a [RegistryEntry<'a>],
|
||||
@ -22,10 +25,6 @@ pub struct RegistryEntry<'a> {
|
||||
pub data: Vec<u8>,
|
||||
}
|
||||
|
||||
impl<'a> Packet for CRegistryData<'a> {
|
||||
const PACKET_ID: VarInt = 0x07;
|
||||
}
|
||||
|
||||
impl<'a> ClientPacket for CRegistryData<'a> {
|
||||
fn write(&self, bytebuf: &mut ByteBuffer) {
|
||||
bytebuf.put_string(self.registry_id);
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
use pumpkin_macros::packet;
|
||||
|
||||
use crate::{
|
||||
bytebuf::{packet_id::Packet, ByteBuffer},
|
||||
ClientPacket, VarInt,
|
||||
};
|
||||
|
||||
#[packet(0x01)]
|
||||
pub struct CEncryptionRequest<'a> {
|
||||
server_id: &'a str, // 20
|
||||
public_key: &'a [u8],
|
||||
@ -26,10 +29,6 @@ impl<'a> CEncryptionRequest<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Packet for CEncryptionRequest<'a> {
|
||||
const PACKET_ID: VarInt = 0x01;
|
||||
}
|
||||
|
||||
impl<'a> ClientPacket for CEncryptionRequest<'a> {
|
||||
fn write(&self, bytebuf: &mut ByteBuffer) {
|
||||
bytebuf.put_string(self.server_id);
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
use pumpkin_macros::packet;
|
||||
|
||||
use crate::{
|
||||
bytebuf::{packet_id::Packet, ByteBuffer},
|
||||
ClientPacket, VarInt,
|
||||
};
|
||||
|
||||
#[packet(0x00)]
|
||||
pub struct CLoginDisconnect<'a> {
|
||||
reason: &'a str,
|
||||
}
|
||||
@ -13,10 +16,6 @@ impl<'a> CLoginDisconnect<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Packet for CLoginDisconnect<'a> {
|
||||
const PACKET_ID: VarInt = 0x00;
|
||||
}
|
||||
|
||||
impl<'a> ClientPacket for CLoginDisconnect<'a> {
|
||||
fn write(&self, bytebuf: &mut ByteBuffer) {
|
||||
bytebuf.put_string(&serde_json::to_string_pretty(&self.reason).unwrap());
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
use pumpkin_macros::packet;
|
||||
|
||||
use crate::{
|
||||
bytebuf::{packet_id::Packet, ByteBuffer},
|
||||
ClientPacket, Property, VarInt,
|
||||
};
|
||||
|
||||
#[packet(0x02)]
|
||||
pub struct CLoginSuccess<'a> {
|
||||
pub uuid: uuid::Uuid,
|
||||
pub username: String, // 16
|
||||
@ -26,10 +29,6 @@ impl<'a> CLoginSuccess<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Packet for CLoginSuccess<'a> {
|
||||
const PACKET_ID: VarInt = 0x02;
|
||||
}
|
||||
|
||||
impl<'a> ClientPacket for CLoginSuccess<'a> {
|
||||
fn write(&self, bytebuf: &mut ByteBuffer) {
|
||||
bytebuf.put_uuid(self.uuid);
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
use pumpkin_macros::packet;
|
||||
|
||||
use crate::{
|
||||
bytebuf::{packet_id::Packet, ByteBuffer},
|
||||
ClientPacket, VarInt,
|
||||
};
|
||||
|
||||
#[packet(0x03)]
|
||||
pub struct CSetCompression {
|
||||
threshold: VarInt,
|
||||
}
|
||||
@ -13,10 +16,6 @@ impl CSetCompression {
|
||||
}
|
||||
}
|
||||
|
||||
impl Packet for CSetCompression {
|
||||
const PACKET_ID: VarInt = 0x03;
|
||||
}
|
||||
|
||||
impl ClientPacket for CSetCompression {
|
||||
fn write(&self, bytebuf: &mut ByteBuffer) {
|
||||
bytebuf.put_var_int(self.threshold);
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
use pumpkin_macros::packet;
|
||||
|
||||
use crate::{
|
||||
bytebuf::{packet_id::Packet, ByteBuffer},
|
||||
ClientPacket, VarInt,
|
||||
};
|
||||
|
||||
#[packet(0x0B)]
|
||||
pub struct CChangeDifficulty {
|
||||
difficulty: u8,
|
||||
locked: bool,
|
||||
@ -14,10 +17,6 @@ impl CChangeDifficulty {
|
||||
}
|
||||
}
|
||||
|
||||
impl Packet for CChangeDifficulty {
|
||||
const PACKET_ID: VarInt = 0x0B;
|
||||
}
|
||||
|
||||
impl ClientPacket for CChangeDifficulty {
|
||||
fn write(&self, bytebuf: &mut ByteBuffer) {
|
||||
bytebuf.put_u8(self.difficulty);
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
use pumpkin_macros::packet;
|
||||
|
||||
use crate::{
|
||||
bytebuf::{packet_id::Packet, ByteBuffer},
|
||||
BitSet, ClientPacket, VarInt,
|
||||
};
|
||||
|
||||
#[packet(0x27)]
|
||||
pub struct CChunkDataUpdateLight {
|
||||
chunk_x: i32,
|
||||
chunk_y: i32,
|
||||
@ -45,10 +48,6 @@ impl CChunkDataUpdateLight {
|
||||
}
|
||||
}
|
||||
|
||||
impl Packet for CChunkDataUpdateLight {
|
||||
const PACKET_ID: VarInt = 0x27;
|
||||
}
|
||||
|
||||
impl ClientPacket for CChunkDataUpdateLight {
|
||||
fn write(&self, bytebuf: &mut ByteBuffer) {
|
||||
bytebuf.put_i32(self.chunk_x);
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
use pumpkin_macros::packet;
|
||||
|
||||
use crate::{
|
||||
bytebuf::{packet_id::Packet, ByteBuffer},
|
||||
ClientPacket, VarInt,
|
||||
};
|
||||
|
||||
#[packet(0x22)]
|
||||
pub struct CGameEvent {
|
||||
event: u8,
|
||||
value: f32,
|
||||
@ -14,10 +17,6 @@ impl CGameEvent {
|
||||
}
|
||||
}
|
||||
|
||||
impl Packet for CGameEvent {
|
||||
const PACKET_ID: VarInt = 0x22;
|
||||
}
|
||||
|
||||
impl ClientPacket for CGameEvent {
|
||||
fn write(&self, bytebuf: &mut ByteBuffer) {
|
||||
bytebuf.put_u8(self.event);
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
use pumpkin_macros::packet;
|
||||
|
||||
use crate::{
|
||||
bytebuf::{packet_id::Packet, ByteBuffer},
|
||||
ClientPacket, VarInt,
|
||||
};
|
||||
|
||||
#[packet(0x2B)]
|
||||
pub struct CLogin {
|
||||
entity_id: i32,
|
||||
is_hardcore: bool,
|
||||
@ -78,10 +81,6 @@ impl CLogin {
|
||||
}
|
||||
}
|
||||
|
||||
impl Packet for CLogin {
|
||||
const PACKET_ID: VarInt = 0x2B;
|
||||
}
|
||||
|
||||
impl ClientPacket for CLogin {
|
||||
fn write(&self, bytebuf: &mut ByteBuffer) {
|
||||
bytebuf.put_i32(self.entity_id);
|
||||
|
||||
@ -1,23 +1,22 @@
|
||||
use pumpkin_macros::packet;
|
||||
|
||||
use crate::{
|
||||
bytebuf::{packet_id::Packet, ByteBuffer},
|
||||
text::Text,
|
||||
text::TextComponent,
|
||||
ClientPacket, VarInt,
|
||||
};
|
||||
|
||||
#[packet(0x1D)]
|
||||
pub struct CPlayDisconnect {
|
||||
reason: Text,
|
||||
reason: TextComponent,
|
||||
}
|
||||
|
||||
impl CPlayDisconnect {
|
||||
pub fn new(reason: Text) -> Self {
|
||||
pub fn new(reason: TextComponent) -> Self {
|
||||
Self { reason }
|
||||
}
|
||||
}
|
||||
|
||||
impl Packet for CPlayDisconnect {
|
||||
const PACKET_ID: VarInt = 0x1D;
|
||||
}
|
||||
|
||||
impl ClientPacket for CPlayDisconnect {
|
||||
fn write(&self, bytebuf: &mut ByteBuffer) {
|
||||
bytebuf.put_slice(&self.reason.encode());
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
use pumpkin_macros::packet;
|
||||
|
||||
use crate::{
|
||||
bytebuf::{packet_id::Packet, ByteBuffer},
|
||||
ClientPacket, VarInt,
|
||||
};
|
||||
|
||||
#[packet(0x38)]
|
||||
pub struct CPlayerAbilities {
|
||||
flags: i8,
|
||||
flying_speed: f32,
|
||||
@ -19,10 +22,6 @@ impl CPlayerAbilities {
|
||||
}
|
||||
}
|
||||
|
||||
impl Packet for CPlayerAbilities {
|
||||
const PACKET_ID: VarInt = 0x38;
|
||||
}
|
||||
|
||||
impl ClientPacket for CPlayerAbilities {
|
||||
fn write(&self, bytebuf: &mut ByteBuffer) {
|
||||
bytebuf.put_i8(self.flags);
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
use pumpkin_macros::packet;
|
||||
|
||||
use crate::{
|
||||
bytebuf::{packet_id::Packet, ByteBuffer},
|
||||
ClientPacket, Property, VarInt,
|
||||
@ -5,15 +7,12 @@ use crate::{
|
||||
|
||||
use super::PlayerAction;
|
||||
|
||||
#[packet(0x3E)]
|
||||
pub struct CPlayerInfoUpdate<'a> {
|
||||
pub actions: i8,
|
||||
pub players: &'a [Player<'a>],
|
||||
}
|
||||
|
||||
impl<'a> Packet for CPlayerInfoUpdate<'a> {
|
||||
const PACKET_ID: VarInt = 0x3E;
|
||||
}
|
||||
|
||||
pub struct Player<'a> {
|
||||
pub uuid: uuid::Uuid,
|
||||
pub actions: &'a [PlayerAction],
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
use pumpkin_macros::packet;
|
||||
|
||||
use crate::{
|
||||
bytebuf::{packet_id::Packet, ByteBuffer},
|
||||
ClientPacket, VarInt,
|
||||
};
|
||||
|
||||
#[packet(0x53)]
|
||||
pub struct CSetHeldItem {
|
||||
slot: i8,
|
||||
}
|
||||
@ -13,10 +16,6 @@ impl CSetHeldItem {
|
||||
}
|
||||
}
|
||||
|
||||
impl Packet for CSetHeldItem {
|
||||
const PACKET_ID: VarInt = 0x53;
|
||||
}
|
||||
|
||||
impl ClientPacket for CSetHeldItem {
|
||||
fn write(&self, bytebuf: &mut ByteBuffer) {
|
||||
bytebuf.put_i8(self.slot);
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
use pumpkin_macros::packet;
|
||||
|
||||
use crate::{
|
||||
bytebuf::{packet_id::Packet, ByteBuffer},
|
||||
ClientPacket, VarInt,
|
||||
};
|
||||
|
||||
#[packet(0x40)]
|
||||
pub struct CSyncPlayerPostion {
|
||||
x: f64,
|
||||
y: f64,
|
||||
@ -35,10 +38,6 @@ impl CSyncPlayerPostion {
|
||||
}
|
||||
}
|
||||
|
||||
impl Packet for CSyncPlayerPostion {
|
||||
const PACKET_ID: VarInt = 0x40;
|
||||
}
|
||||
|
||||
impl ClientPacket for CSyncPlayerPostion {
|
||||
fn write(&self, bytebuf: &mut ByteBuffer) {
|
||||
bytebuf.put_f64(self.x);
|
||||
|
||||
23
pumpkin-protocol/src/client/play/c_system_chat_message.rs
Normal file
23
pumpkin-protocol/src/client/play/c_system_chat_message.rs
Normal file
@ -0,0 +1,23 @@
|
||||
use pumpkin_macros::packet;
|
||||
|
||||
use crate::{bytebuf::ByteBuffer, text::TextComponent, ClientPacket, VarInt};
|
||||
|
||||
|
||||
#[packet(0x6C)]
|
||||
pub struct CSystemChatMessge {
|
||||
content: TextComponent,
|
||||
overlay: bool,
|
||||
}
|
||||
|
||||
impl CSystemChatMessge {
|
||||
pub fn new(content: TextComponent, overlay: bool) -> Self {
|
||||
Self { content, overlay }
|
||||
}
|
||||
}
|
||||
|
||||
impl ClientPacket for CSystemChatMessge {
|
||||
fn write(&self, bytebuf: &mut ByteBuffer) {
|
||||
bytebuf.put_slice(&self.content.encode());
|
||||
bytebuf.put_bool(self.overlay);
|
||||
}
|
||||
}
|
||||
@ -7,6 +7,7 @@ mod c_player_abilities;
|
||||
mod c_player_info_update;
|
||||
mod c_set_held_item;
|
||||
mod c_sync_player_position;
|
||||
mod c_system_chat_message;
|
||||
mod player_action;
|
||||
|
||||
pub use c_change_difficulty::*;
|
||||
@ -18,4 +19,5 @@ pub use c_player_abilities::*;
|
||||
pub use c_player_info_update::*;
|
||||
pub use c_set_held_item::*;
|
||||
pub use c_sync_player_position::*;
|
||||
pub use c_system_chat_message::*;
|
||||
pub use player_action::*;
|
||||
|
||||
@ -1,14 +1,13 @@
|
||||
use pumpkin_macros::packet;
|
||||
|
||||
use crate::{bytebuf::packet_id::Packet, VarInt};
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
#[packet(0x01)]
|
||||
pub struct CPingResponse {
|
||||
payload: i64, // must responde with the same as in `SPingRequest`
|
||||
}
|
||||
|
||||
impl Packet for CPingResponse {
|
||||
const PACKET_ID: VarInt = 0x01;
|
||||
}
|
||||
|
||||
impl CPingResponse {
|
||||
pub fn new(payload: i64) -> Self {
|
||||
Self { payload }
|
||||
|
||||
@ -1,8 +1,12 @@
|
||||
use pumpkin_macros::packet;
|
||||
|
||||
use crate::{
|
||||
bytebuf::{packet_id::Packet, ByteBuffer},
|
||||
ClientPacket, VarInt,
|
||||
};
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
#[packet(0x00)]
|
||||
pub struct CStatusResponse<'a> {
|
||||
json_response: &'a str, // 32767
|
||||
}
|
||||
@ -12,12 +16,4 @@ impl<'a> CStatusResponse<'a> {
|
||||
Self { json_response }
|
||||
}
|
||||
}
|
||||
impl<'a> Packet for CStatusResponse<'a> {
|
||||
const PACKET_ID: VarInt = 0x00;
|
||||
}
|
||||
|
||||
impl<'a> ClientPacket for CStatusResponse<'a> {
|
||||
fn write(&self, bytebuf: &mut ByteBuffer) {
|
||||
bytebuf.put_string(self.json_response);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,18 +1,33 @@
|
||||
use core::str;
|
||||
|
||||
use fastnbt::SerOpts;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::Deserialize;
|
||||
|
||||
// represents a text component
|
||||
// Reference: https://wiki.vg/Text_formatting#Text_components
|
||||
#[derive(Clone, PartialEq, Default, Debug, Serialize, Deserialize)]
|
||||
#[derive(Clone, PartialEq, Default, Debug, Deserialize)]
|
||||
pub struct TextComponent {
|
||||
pub text: String,
|
||||
}
|
||||
|
||||
impl serde::Serialize for TextComponent {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
serializer.serialize_bytes(&self.encode())
|
||||
}
|
||||
}
|
||||
|
||||
impl TextComponent {
|
||||
pub fn encode(&self) -> Vec<u8> {
|
||||
fastnbt::to_bytes_with_opts(&self, SerOpts::network_nbt()).unwrap()
|
||||
#[derive(serde::Serialize)]
|
||||
struct TempStruct<'a> {
|
||||
text: &'a String,
|
||||
}
|
||||
|
||||
fastnbt::to_bytes_with_opts(&TempStruct { text: &self.text }, SerOpts::network_nbt())
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user