Skip to content

Commit

Permalink
Add ChatType
Browse files Browse the repository at this point in the history
  • Loading branch information
Snowiiii committed Aug 12, 2024
1 parent 65c2207 commit 5cf19a4
Show file tree
Hide file tree
Showing 16 changed files with 158 additions and 151 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 2 additions & 7 deletions pumpkin-protocol/src/client/config/c_plugin_message.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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);
}
}
12 changes: 6 additions & 6 deletions pumpkin-protocol/src/client/login/c_encryption_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ use crate::{RawBytes, VarInt};
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,
}
Expand Down
6 changes: 3 additions & 3 deletions pumpkin-protocol/src/client/play/c_player_chat_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use pumpkin_macros::packet;
use pumpkin_text::TextComponent;
use serde::Serialize;

use crate::{BitSet, VarInt};
use crate::{uuid::UUID, BitSet, VarInt};

#[derive(Serialize, Clone)]
#[packet(0x39)]
pub struct CPlayerChatMessage<'a> {
sender: uuid::Uuid,
sender: UUID,
index: VarInt,
message_signature: Option<&'a [u8]>,
message: String,
Expand All @@ -29,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,
Expand Down
27 changes: 5 additions & 22 deletions pumpkin-protocol/src/client/play/c_spawn_player.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use pumpkin_macros::packet;
use serde::Serialize;

use crate::{ClientPacket, VarInt};
use crate::{uuid::UUID, VarInt};

#[derive(Clone)]
#[derive(Serialize, Clone)]
#[packet(0x01)]
pub struct CSpawnEntity {
entity_id: VarInt,
entity_uuid: uuid::Uuid,
entity_uuid: UUID,
typ: VarInt,
x: f64,
y: f64,
Expand All @@ -24,7 +25,7 @@ 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,
Expand Down Expand Up @@ -54,21 +55,3 @@ impl CSpawnEntity {
}
}
}

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);
}
}
10 changes: 0 additions & 10 deletions pumpkin-protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions pumpkin-protocol/src/uuid.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use serde::Serialize;

#[derive(Clone)]
pub struct UUID(pub uuid::Uuid);

impl Serialize for UUID {
Expand Down
2 changes: 2 additions & 0 deletions pumpkin-registry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ edition.workspace = true

[dependencies]
pumpkin-protocol = { path = "../pumpkin-protocol"}
pumpkin-text = { path = "../pumpkin-text"}

# nbt
fastnbt = { git = "https://github.com/owengage/fastnbt.git" }
fastsnbt = "0.2"
Expand Down
10 changes: 5 additions & 5 deletions pumpkin-registry/src/chat_type.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use pumpkin_text::style::Style;
use serde::Serialize;

#[derive(Debug, Clone, Serialize)]
Expand All @@ -9,22 +10,21 @@ pub struct ChatType {
#[derive(Debug, Clone, Serialize)]
pub struct Decoration {
translation_key: String,
style: u8,
// TODO
// style: Option<Styles>,
#[serde(default, skip_serializing_if = "Option::is_none")]
style: Option<Style>,
parameters: Vec<String>,
}

impl Default for ChatType {
fn default() -> Self {
Self {
chat: Decoration {
style: 0,
style: None,
parameters: vec!["sender".into(), "content".into()],
translation_key: "chat.type.text".into(),
},
narration: Decoration {
style: 0,
style: None,
parameters: vec!["sender".into(), "content".into()],
translation_key: "chat.type.text.narrate".into(),
},
Expand Down
4 changes: 2 additions & 2 deletions pumpkin-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Registry {
}],
};

let _chat_types = Registry {
let chat_types = Registry {
registry_id: "minecraft:chat_type".to_string(),
registry_entries: vec![RegistryEntry {
entry_id: "minecraft:chat",
Expand All @@ -79,7 +79,7 @@ impl Registry {
biomes,
wolf_variants,
paintings,
// chat_types,
chat_types,
]
}
}
Loading

0 comments on commit 5cf19a4

Please sign in to comment.