Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
5d6c38d1b2
60 files changed
+1371
-344
No files matched your search
@@ -4,9 +4,9 @@ version.workspace = true
|
||||
edition.workspace = true
|
||||
|
||||
[dependencies]
|
||||
|
||||
pumpkin-macros = { path = "../pumpkin-macros" }
|
||||
pumpkin-world = { path = "../pumpkin-world" }
|
||||
pumpkin-text = { path = "../pumpkin-text" }
|
||||
|
||||
bytes = "1.7"
|
||||
|
||||
@@ -23,11 +23,9 @@ log = "0.4"
|
||||
num-traits = "0.2"
|
||||
num-derive = "0.4"
|
||||
|
||||
# for text component
|
||||
fastnbt = { git = "https://github.com/owengage/fastnbt.git" }
|
||||
|
||||
# encryption
|
||||
aes = "0.8.4"
|
||||
cfb8 = "0.8.1"
|
||||
take_mut = "0.2.2"
|
||||
itertools = "0.13.0"
|
||||
fastnbt = "2.5.0"
|
||||
@@ -0,0 +1,31 @@
|
||||
use pumpkin_macros::packet;
|
||||
use pumpkin_text::TextComponent;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x09)]
|
||||
pub struct CConfigAddResourcePack {
|
||||
uuid: uuid::Uuid,
|
||||
url: String,
|
||||
hash: String,
|
||||
forced: bool,
|
||||
prompt_message: Option<TextComponent>,
|
||||
}
|
||||
|
||||
impl CConfigAddResourcePack {
|
||||
pub fn new(
|
||||
uuid: uuid::Uuid,
|
||||
url: String,
|
||||
hash: String,
|
||||
forced: bool,
|
||||
prompt_message: Option<TextComponent>,
|
||||
) -> Self {
|
||||
Self {
|
||||
uuid,
|
||||
url,
|
||||
hash,
|
||||
forced,
|
||||
prompt_message,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
use pumpkin_macros::packet;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{bytebuf::ByteBuffer, ClientPacket};
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x01)]
|
||||
pub struct CPluginMessage<'a> {
|
||||
channel: &'a str,
|
||||
@@ -13,10 +15,3 @@ impl<'a> CPluginMessage<'a> {
|
||||
Self { channel, data }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ClientPacket for CPluginMessage<'a> {
|
||||
fn write(&self, bytebuf: &mut ByteBuffer) {
|
||||
bytebuf.put_string(self.channel);
|
||||
bytebuf.put_slice(self.data);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
mod c_add_resource_pack;
|
||||
mod c_config_disconnect;
|
||||
mod c_cookie_request;
|
||||
mod c_finish_config;
|
||||
@@ -5,6 +6,7 @@ mod c_known_packs;
|
||||
mod c_plugin_message;
|
||||
mod c_registry_data;
|
||||
|
||||
pub use c_add_resource_pack::*;
|
||||
pub use c_config_disconnect::*;
|
||||
pub use c_cookie_request::*;
|
||||
pub use c_finish_config::*;
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
use pumpkin_macros::packet;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{RawBytes, VarInt};
|
||||
use crate::VarInt;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x01)]
|
||||
pub struct CEncryptionRequest<'a> {
|
||||
server_id: &'a str, // 20
|
||||
public_key_length: VarInt,
|
||||
public_key: RawBytes<'a>,
|
||||
public_key: &'a [u8],
|
||||
verify_token_length: VarInt,
|
||||
verify_token: RawBytes<'a>,
|
||||
verify_token: &'a [u8],
|
||||
should_authenticate: bool,
|
||||
}
|
||||
|
||||
impl<'a> CEncryptionRequest<'a> {
|
||||
pub fn new(
|
||||
server_id: &'a str,
|
||||
public_key: RawBytes<'a>,
|
||||
verify_token: RawBytes<'a>,
|
||||
public_key: &'a [u8],
|
||||
verify_token: &'a [u8],
|
||||
should_authenticate: bool,
|
||||
) -> Self {
|
||||
Self {
|
||||
server_id,
|
||||
public_key_length: public_key.0.len().into(),
|
||||
public_key_length: public_key.len().into(),
|
||||
public_key,
|
||||
verify_token_length: verify_token.0.len().into(),
|
||||
verify_token_length: verify_token.len().into(),
|
||||
verify_token,
|
||||
should_authenticate,
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::{bytebuf::ByteBuffer, ClientPacket, Property};
|
||||
#[packet(0x02)]
|
||||
pub struct CLoginSuccess<'a> {
|
||||
pub uuid: uuid::Uuid,
|
||||
pub username: String, // 16
|
||||
pub username: &'a str, // 16
|
||||
pub properties: &'a [Property],
|
||||
pub strict_error_handling: bool,
|
||||
}
|
||||
@@ -13,7 +13,7 @@ pub struct CLoginSuccess<'a> {
|
||||
impl<'a> CLoginSuccess<'a> {
|
||||
pub fn new(
|
||||
uuid: uuid::Uuid,
|
||||
username: String,
|
||||
username: &'a str,
|
||||
properties: &'a [Property],
|
||||
strict_error_handling: bool,
|
||||
) -> Self {
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
use pumpkin_macros::packet;
|
||||
use pumpkin_text::TextComponent;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x4C)]
|
||||
pub struct CActionBar {
|
||||
action_bar: TextComponent,
|
||||
}
|
||||
|
||||
impl CActionBar {
|
||||
pub fn new(action_bar: TextComponent) -> Self {
|
||||
Self { action_bar }
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
use pumpkin_macros::packet;
|
||||
use pumpkin_text::TextComponent;
|
||||
|
||||
use crate::{text::TextComponent, ClientPacket, VarInt};
|
||||
use crate::{ClientPacket, VarInt};
|
||||
|
||||
#[derive(Clone)]
|
||||
#[packet(0x1E)]
|
||||
|
||||
@@ -4,7 +4,7 @@ use serde::Serialize;
|
||||
|
||||
use crate::VarInt;
|
||||
|
||||
#[derive(Serialize, Clone)]
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x03)]
|
||||
pub struct CEntityAnimation {
|
||||
entity_id: VarInt,
|
||||
|
||||
@@ -3,23 +3,25 @@ use serde::Serialize;
|
||||
|
||||
use crate::VarInt;
|
||||
|
||||
#[derive(Serialize, Clone)]
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x58)]
|
||||
pub struct CSetEntityMetadata {
|
||||
entity_id: VarInt,
|
||||
metadata: Vec<Metadata>,
|
||||
metadata: Metadata,
|
||||
end: u8,
|
||||
}
|
||||
|
||||
impl CSetEntityMetadata {
|
||||
pub fn new(entity_id: VarInt, metadata: Vec<Metadata>) -> Self {
|
||||
pub fn new(entity_id: VarInt, metadata: Metadata) -> Self {
|
||||
Self {
|
||||
entity_id,
|
||||
metadata,
|
||||
end: 255,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Clone)]
|
||||
#[derive(Serialize)]
|
||||
pub struct Metadata {
|
||||
index: u8,
|
||||
typ: VarInt,
|
||||
|
||||
@@ -3,7 +3,7 @@ use serde::Serialize;
|
||||
|
||||
use crate::VarInt;
|
||||
|
||||
#[derive(Serialize, Clone)]
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x48)]
|
||||
pub struct CHeadRot {
|
||||
entity_id: VarInt,
|
||||
|
||||
@@ -5,11 +5,11 @@ use crate::VarInt;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x2B)]
|
||||
pub struct CLogin {
|
||||
pub struct CLogin<'a> {
|
||||
entity_id: i32,
|
||||
is_hardcore: bool,
|
||||
dimension_count: VarInt,
|
||||
dimension_names: Vec<String>,
|
||||
dimension_names: &'a [&'a str],
|
||||
max_players: VarInt,
|
||||
view_distance: VarInt,
|
||||
simulated_distance: VarInt,
|
||||
@@ -17,7 +17,7 @@ pub struct CLogin {
|
||||
enabled_respawn_screen: bool,
|
||||
limited_crafting: bool,
|
||||
dimension_type: VarInt,
|
||||
dimension_name: String,
|
||||
dimension_name: &'a str,
|
||||
hashed_seed: i64,
|
||||
game_mode: u8,
|
||||
previous_gamemode: i8,
|
||||
@@ -28,12 +28,12 @@ pub struct CLogin {
|
||||
enforce_secure_chat: bool,
|
||||
}
|
||||
|
||||
impl CLogin {
|
||||
impl<'a> CLogin<'a> {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
entity_id: i32,
|
||||
is_hardcore: bool,
|
||||
dimension_names: Vec<String>,
|
||||
dimension_names: &'a [&'a str],
|
||||
max_players: VarInt,
|
||||
view_distance: VarInt,
|
||||
simulated_distance: VarInt,
|
||||
@@ -41,7 +41,7 @@ impl CLogin {
|
||||
enabled_respawn_screen: bool,
|
||||
limited_crafting: bool,
|
||||
dimension_type: VarInt,
|
||||
dimension_name: String,
|
||||
dimension_name: &'a str,
|
||||
hashed_seed: i64,
|
||||
game_mode: u8,
|
||||
previous_gamemode: i8,
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
use pumpkin_macros::packet;
|
||||
use pumpkin_text::TextComponent;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::VarInt;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x33)]
|
||||
pub struct COpenScreen {
|
||||
window_id: VarInt,
|
||||
window_type: VarInt,
|
||||
window_title: TextComponent,
|
||||
}
|
||||
|
||||
impl COpenScreen {
|
||||
pub fn new(window_id: VarInt, window_type: VarInt, window_title: TextComponent) -> Self {
|
||||
Self {
|
||||
window_id,
|
||||
window_type,
|
||||
window_title,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
use pumpkin_macros::packet;
|
||||
use pumpkin_text::TextComponent;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::text::TextComponent;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x1D)]
|
||||
pub struct CPlayDisconnect {
|
||||
|
||||
@@ -1,22 +1,26 @@
|
||||
use num_derive::{FromPrimitive, ToPrimitive};
|
||||
use pumpkin_macros::packet;
|
||||
use pumpkin_text::TextComponent;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{text::TextComponent, VarInt};
|
||||
use crate::{uuid::UUID, BitSet, VarInt};
|
||||
|
||||
#[derive(Serialize, Clone)]
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x39)]
|
||||
pub struct CPlayerChatMessage<'a> {
|
||||
sender: uuid::Uuid,
|
||||
sender: UUID,
|
||||
index: VarInt,
|
||||
message_signature: Option<&'a [u8]>,
|
||||
message: String,
|
||||
timestamp: i64,
|
||||
salt: i64,
|
||||
previous_messages_count: VarInt,
|
||||
previous_messages: &'a [PreviousMessage<'a>], // max 20
|
||||
unsigned_content: Option<TextComponent>,
|
||||
/// See `FilterType`
|
||||
filter_type: VarInt,
|
||||
// TODO: THIS IS A HACK, We currently don't support writing or reading bitsets
|
||||
filter_type_bits: bool,
|
||||
chat_type: VarInt,
|
||||
sender_name: TextComponent,
|
||||
target_name: Option<TextComponent>,
|
||||
@@ -25,7 +29,7 @@ pub struct CPlayerChatMessage<'a> {
|
||||
impl<'a> CPlayerChatMessage<'a> {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
sender: uuid::Uuid,
|
||||
sender: UUID,
|
||||
index: VarInt,
|
||||
message_signature: Option<&'a [u8]>,
|
||||
message: String,
|
||||
@@ -45,9 +49,11 @@ impl<'a> CPlayerChatMessage<'a> {
|
||||
message,
|
||||
timestamp,
|
||||
salt,
|
||||
previous_messages_count: previous_messages.len().into(),
|
||||
previous_messages,
|
||||
unsigned_content,
|
||||
filter_type,
|
||||
filter_type_bits: false,
|
||||
chat_type,
|
||||
sender_name,
|
||||
target_name,
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
use pumpkin_macros::packet;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{uuid::UUID, VarInt};
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x3D)]
|
||||
pub struct CRemovePlayerInfo<'a> {
|
||||
players_count: VarInt,
|
||||
players: &'a [UUID],
|
||||
}
|
||||
|
||||
impl<'a> CRemovePlayerInfo<'a> {
|
||||
pub fn new(players_count: VarInt, players: &'a [UUID]) -> Self {
|
||||
Self {
|
||||
players_count,
|
||||
players,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,14 +3,18 @@ use serde::Serialize;
|
||||
|
||||
use crate::VarInt;
|
||||
|
||||
#[derive(Serialize, Clone)]
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x42)]
|
||||
pub struct CRemoveEntities {
|
||||
entitiy_ids: Vec<VarInt>,
|
||||
pub struct CRemoveEntities<'a> {
|
||||
count: VarInt,
|
||||
entitiy_ids: &'a [VarInt],
|
||||
}
|
||||
|
||||
impl CRemoveEntities {
|
||||
pub fn new(entitiy_ids: Vec<VarInt>) -> Self {
|
||||
Self { entitiy_ids }
|
||||
impl<'a> CRemoveEntities<'a> {
|
||||
pub fn new(entitiy_ids: &'a [VarInt]) -> Self {
|
||||
Self {
|
||||
count: VarInt(entitiy_ids.len() as i32),
|
||||
entitiy_ids,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
use pumpkin_macros::packet;
|
||||
use pumpkin_text::TextComponent;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x65)]
|
||||
pub struct CTitleText {
|
||||
title: TextComponent,
|
||||
}
|
||||
|
||||
impl CTitleText {
|
||||
pub fn new(title: TextComponent) -> Self {
|
||||
Self { title }
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,13 @@
|
||||
use pumpkin_macros::packet;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{ClientPacket, VarInt};
|
||||
use crate::{uuid::UUID, VarInt};
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x01)]
|
||||
pub struct CSpawnEntity {
|
||||
entity_id: VarInt,
|
||||
entity_uuid: uuid::Uuid,
|
||||
entity_uuid: UUID,
|
||||
typ: VarInt,
|
||||
x: f64,
|
||||
y: f64,
|
||||
@@ -24,18 +25,18 @@ impl CSpawnEntity {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
entity_id: VarInt,
|
||||
entity_uuid: uuid::Uuid,
|
||||
entity_uuid: UUID,
|
||||
typ: VarInt,
|
||||
x: f64,
|
||||
y: f64,
|
||||
z: f64,
|
||||
pitch: u8, // angle
|
||||
yaw: u8, // angle
|
||||
head_yaw: u8, // angle
|
||||
pitch: f32, // angle
|
||||
yaw: f32, // angle
|
||||
head_yaw: f32, // angle
|
||||
data: VarInt,
|
||||
velocity_x: i16,
|
||||
velocity_y: i16,
|
||||
velocity_z: i16,
|
||||
velocity_x: f32,
|
||||
velocity_y: f32,
|
||||
velocity_z: f32,
|
||||
) -> Self {
|
||||
Self {
|
||||
entity_id,
|
||||
@@ -44,31 +45,13 @@ impl CSpawnEntity {
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
pitch,
|
||||
yaw,
|
||||
head_yaw,
|
||||
pitch: (pitch * 256.0 / 360.0).floor() as u8,
|
||||
yaw: (yaw * 256.0 / 360.0).floor() as u8,
|
||||
head_yaw: (head_yaw * 256.0 / 360.0).floor() as u8,
|
||||
data,
|
||||
velocity_x,
|
||||
velocity_y,
|
||||
velocity_z,
|
||||
velocity_x: (velocity_x.clamp(-3.9, 3.9) * 8000.0) as i16,
|
||||
velocity_y: (velocity_y.clamp(-3.9, 3.9) * 8000.0) as i16,
|
||||
velocity_z: (velocity_z.clamp(-3.9, 3.9) * 8000.0) as i16,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ClientPacket for CSpawnEntity {
|
||||
fn write(&self, bytebuf: &mut crate::bytebuf::ByteBuffer) {
|
||||
bytebuf.put_var_int(&self.entity_id);
|
||||
bytebuf.put_uuid(self.entity_uuid);
|
||||
bytebuf.put_var_int(&self.typ);
|
||||
bytebuf.put_f64(self.x);
|
||||
bytebuf.put_f64(self.y);
|
||||
bytebuf.put_f64(self.z);
|
||||
bytebuf.put_u8(self.pitch);
|
||||
bytebuf.put_u8(self.yaw);
|
||||
bytebuf.put_u8(self.head_yaw);
|
||||
bytebuf.put_var_int(&self.data);
|
||||
bytebuf.put_i16(self.velocity_x);
|
||||
bytebuf.put_i16(self.velocity_y);
|
||||
bytebuf.put_i16(self.velocity_z);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
use pumpkin_macros::packet;
|
||||
use pumpkin_text::TextComponent;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x63)]
|
||||
pub struct CSubtitle {
|
||||
subtitle: TextComponent,
|
||||
}
|
||||
|
||||
impl CSubtitle {
|
||||
pub fn new(subtitle: TextComponent) -> Self {
|
||||
Self { subtitle }
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
use pumpkin_macros::packet;
|
||||
use pumpkin_text::TextComponent;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::text::TextComponent;
|
||||
|
||||
#[derive(Serialize, Clone)]
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x6C)]
|
||||
pub struct CSystemChatMessge {
|
||||
content: TextComponent,
|
||||
|
||||
@@ -3,7 +3,7 @@ use serde::Serialize;
|
||||
|
||||
use crate::VarInt;
|
||||
|
||||
#[derive(Serialize, Clone)]
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x2F)]
|
||||
pub struct CUpdateEntityPosRot {
|
||||
entity_id: VarInt,
|
||||
|
||||
@@ -3,7 +3,7 @@ use serde::Serialize;
|
||||
|
||||
use crate::VarInt;
|
||||
|
||||
#[derive(Serialize, Clone)]
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x2E)]
|
||||
pub struct CUpdateEntityPos {
|
||||
entity_id: VarInt,
|
||||
|
||||
@@ -3,7 +3,7 @@ use serde::Serialize;
|
||||
|
||||
use crate::VarInt;
|
||||
|
||||
#[derive(Serialize, Clone)]
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x30)]
|
||||
pub struct CUpdateEntityRot {
|
||||
entity_id: VarInt,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
mod c_center_chunk;
|
||||
mod c_actionbar;
|
||||
mod c_change_difficulty;
|
||||
mod c_chunk_data;
|
||||
mod c_chunk_data_update_light;
|
||||
@@ -8,13 +9,17 @@ mod c_entity_metadata;
|
||||
mod c_game_event;
|
||||
mod c_head_rot;
|
||||
mod c_login;
|
||||
mod c_open_screen;
|
||||
mod c_play_disconnect;
|
||||
mod c_player_abilities;
|
||||
mod c_player_chat_message;
|
||||
mod c_player_info_update;
|
||||
mod c_player_remove;
|
||||
mod c_remove_entities;
|
||||
mod c_set_held_item;
|
||||
mod c_set_title;
|
||||
mod c_spawn_player;
|
||||
mod c_subtitle;
|
||||
mod c_sync_player_position;
|
||||
mod c_system_chat_message;
|
||||
mod c_update_entitiy_pos_rot;
|
||||
@@ -23,6 +28,7 @@ mod c_update_entity_rot;
|
||||
mod player_action;
|
||||
|
||||
pub use c_center_chunk::*;
|
||||
pub use c_actionbar::*;
|
||||
pub use c_change_difficulty::*;
|
||||
pub use c_chunk_data::*;
|
||||
pub use c_chunk_data_update_light::*;
|
||||
@@ -32,13 +38,17 @@ pub use c_entity_metadata::*;
|
||||
pub use c_game_event::*;
|
||||
pub use c_head_rot::*;
|
||||
pub use c_login::*;
|
||||
pub use c_open_screen::*;
|
||||
pub use c_play_disconnect::*;
|
||||
pub use c_player_abilities::*;
|
||||
pub use c_player_chat_message::*;
|
||||
pub use c_player_info_update::*;
|
||||
pub use c_player_remove::*;
|
||||
pub use c_remove_entities::*;
|
||||
pub use c_set_held_item::*;
|
||||
pub use c_set_title::*;
|
||||
pub use c_spawn_player::*;
|
||||
pub use c_subtitle::*;
|
||||
pub use c_sync_player_position::*;
|
||||
pub use c_system_chat_message::*;
|
||||
pub use c_update_entitiy_pos_rot::*;
|
||||
|
||||
@@ -2,13 +2,13 @@ use std::io::{self, Write};
|
||||
|
||||
use bytebuf::{packet_id::Packet, ByteBuffer, DeserializerError};
|
||||
use bytes::Buf;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::{Deserialize, Serialize, Serializer};
|
||||
use thiserror::Error;
|
||||
|
||||
pub mod bytebuf;
|
||||
pub mod client;
|
||||
pub mod server;
|
||||
pub mod text;
|
||||
pub mod uuid;
|
||||
|
||||
pub mod packet_decoder;
|
||||
pub mod packet_encoder;
|
||||
@@ -91,16 +91,6 @@ impl VarInt {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RawBytes<'a>(pub &'a [u8]);
|
||||
impl<'a> Serialize for RawBytes<'a> {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
serializer.serialize_bytes(self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<i32> for VarInt {
|
||||
fn from(value: i32) -> Self {
|
||||
VarInt(value)
|
||||
|
||||
@@ -22,7 +22,7 @@ pub struct PacketEncoder {
|
||||
}
|
||||
|
||||
impl PacketEncoder {
|
||||
pub fn append_packet<P: ClientPacket>(&mut self, packet: P) -> Result<(), PacketError> {
|
||||
pub fn append_packet<P: ClientPacket>(&mut self, packet: &P) -> Result<(), PacketError> {
|
||||
let start_len = self.buf.len();
|
||||
|
||||
let mut writer = (&mut self.buf).writer();
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
use core::str;
|
||||
|
||||
use fastnbt::SerOpts;
|
||||
use serde::Deserialize;
|
||||
|
||||
// Fepresents a Text component
|
||||
// Reference: https://wiki.vg/Text_formatting#Text_components
|
||||
#[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().as_slice())
|
||||
}
|
||||
}
|
||||
|
||||
impl TextComponent {
|
||||
pub fn encode(&self) -> Vec<u8> {
|
||||
#[derive(serde::Serialize)]
|
||||
struct TempStruct<'a> {
|
||||
text: &'a String,
|
||||
}
|
||||
|
||||
fastnbt::to_bytes_with_opts(&TempStruct { text: &self.text }, SerOpts::network_nbt())
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for TextComponent {
|
||||
fn from(value: String) -> Self {
|
||||
Self { text: value }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for TextComponent {
|
||||
fn from(value: &str) -> Self {
|
||||
Self {
|
||||
text: value.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Text color
|
||||
#[derive(Default, Debug, Clone, Copy)]
|
||||
pub enum Color {
|
||||
/// The default color for the text will be used, which varies by context
|
||||
/// (in some cases, it's white; in others, it's black; in still others, it
|
||||
/// is a shade of gray that isn't normally used on text).
|
||||
#[default]
|
||||
Reset,
|
||||
/// One of the 16 named Minecraft colors
|
||||
Named(NamedColor),
|
||||
}
|
||||
|
||||
/// Named Minecraft color
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||
pub enum NamedColor {
|
||||
Black = 0,
|
||||
DarkBlue,
|
||||
DarkGreen,
|
||||
DarkCyan,
|
||||
DarkRed,
|
||||
Purple,
|
||||
Gold,
|
||||
Gray,
|
||||
DarkGray,
|
||||
Blue,
|
||||
BrightGreen,
|
||||
Cyan,
|
||||
Red,
|
||||
Pink,
|
||||
Yellow,
|
||||
White,
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct UUID(pub uuid::Uuid);
|
||||
|
||||
impl Serialize for UUID {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
serializer.serialize_bytes(self.0.as_bytes())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user