aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src/chat.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2024-11-27 19:31:40 -0600
committerGitHub <noreply@github.com>2024-11-27 19:31:40 -0600
commit08958c2278b15ebeac8a964f392ebb792e479b61 (patch)
tree4ae3664cea38d7fd1a8f1e95ed06fac04ffe519e /azalea-client/src/chat.rs
parent139d77d3c2b0922fba5e9d4fa2bd9819d78bd773 (diff)
downloadazalea-drasl-08958c2278b15ebeac8a964f392ebb792e479b61.tar.xz
Refactor azalea-protocol (#190)
* start updating to 1.21.4 * fix block codegen and stop using block data from burger * rename packet related modules and structs to be simpler * ItemSlot -> ItemStack for more consistency with mojmap * .get() -> .into_packet() * simplify declare_state_packets by removing packet ids * rename read_from and write_into to azalea_read and azalea_write * rename McBufReadable and McBufWritable to AzaleaRead and AzaleaWrite * McBuf -> AzBuf * remove most uses of into_variant * update codegen and use resourcelocation names for packets * implement #[limit(i)] attribute for AzBuf derive macro * fixes for 1.21.4 * fix examples * update some physics code and fix ChatType * remove unused imports in codegen * re-add some things to migrate.py and update +mc version numbers automatically * downgrade to 1.21.3 lol
Diffstat (limited to 'azalea-client/src/chat.rs')
-rwxr-xr-xazalea-client/src/chat.rs50
1 files changed, 25 insertions, 25 deletions
diff --git a/azalea-client/src/chat.rs b/azalea-client/src/chat.rs
index 80c52baf..de0b8a7d 100755
--- a/azalea-client/src/chat.rs
+++ b/azalea-client/src/chat.rs
@@ -6,12 +6,15 @@ use std::{
};
use azalea_chat::FormattedText;
-use azalea_protocol::packets::game::{
- clientbound_disguised_chat_packet::ClientboundDisguisedChatPacket,
- clientbound_player_chat_packet::ClientboundPlayerChatPacket,
- clientbound_system_chat_packet::ClientboundSystemChatPacket,
- serverbound_chat_command_packet::ServerboundChatCommandPacket,
- serverbound_chat_packet::{LastSeenMessagesUpdate, ServerboundChatPacket},
+use azalea_protocol::packets::{
+ game::{
+ c_disguised_chat::ClientboundDisguisedChat,
+ c_player_chat::ClientboundPlayerChat,
+ c_system_chat::ClientboundSystemChat,
+ s_chat::{LastSeenMessagesUpdate, ServerboundChat},
+ s_chat_command::ServerboundChatCommand,
+ },
+ Packet,
};
use bevy_app::{App, Plugin, Update};
use bevy_ecs::{
@@ -30,9 +33,9 @@ use crate::{
/// A chat packet, either a system message or a chat message.
#[derive(Debug, Clone, PartialEq)]
pub enum ChatPacket {
- System(Arc<ClientboundSystemChatPacket>),
- Player(Arc<ClientboundPlayerChatPacket>),
- Disguised(Arc<ClientboundDisguisedChatPacket>),
+ System(Arc<ClientboundSystemChat>),
+ Player(Arc<ClientboundPlayerChat>),
+ Disguised(Arc<ClientboundDisguisedChat>),
}
macro_rules! regex {
@@ -111,10 +114,10 @@ impl ChatPacket {
self.split_sender_and_content().1
}
- /// Create a new ChatPacket from a string. This is meant to be used as a
+ /// Create a new Chat from a string. This is meant to be used as a
/// convenience function for testing.
pub fn new(message: &str) -> Self {
- ChatPacket::System(Arc::new(ClientboundSystemChatPacket {
+ ChatPacket::System(Arc::new(ClientboundSystemChat {
content: FormattedText::from(message),
overlay: false,
}))
@@ -141,7 +144,7 @@ impl Client {
self.ecs.lock().send_event(SendChatKindEvent {
entity: self.entity,
content: message.to_string(),
- kind: ChatPacketKind::Message,
+ kind: ChatKind::Message,
});
self.run_schedule_sender.send(()).unwrap();
}
@@ -152,7 +155,7 @@ impl Client {
self.ecs.lock().send_event(SendChatKindEvent {
entity: self.entity,
content: command.to_string(),
- kind: ChatPacketKind::Command,
+ kind: ChatKind::Command,
});
self.run_schedule_sender.send(()).unwrap();
}
@@ -215,13 +218,13 @@ pub fn handle_send_chat_event(
send_chat_kind_events.send(SendChatKindEvent {
entity: event.entity,
content: event.content[1..].to_string(),
- kind: ChatPacketKind::Command,
+ kind: ChatKind::Command,
});
} else {
send_chat_kind_events.send(SendChatKindEvent {
entity: event.entity,
content: event.content.clone(),
- kind: ChatPacketKind::Message,
+ kind: ChatKind::Message,
});
}
}
@@ -240,11 +243,11 @@ pub fn handle_send_chat_event(
pub struct SendChatKindEvent {
pub entity: Entity,
pub content: String,
- pub kind: ChatPacketKind,
+ pub kind: ChatKind,
}
/// A kind of chat packet, either a chat message or a command.
-pub enum ChatPacketKind {
+pub enum ChatKind {
Message,
Command,
}
@@ -261,7 +264,7 @@ pub fn handle_send_chat_kind_event(
.take(256)
.collect::<String>();
let packet = match event.kind {
- ChatPacketKind::Message => ServerboundChatPacket {
+ ChatKind::Message => ServerboundChat {
message: content,
timestamp: SystemTime::now()
.duration_since(UNIX_EPOCH)
@@ -273,17 +276,14 @@ pub fn handle_send_chat_kind_event(
signature: None,
last_seen_messages: LastSeenMessagesUpdate::default(),
}
- .get(),
- ChatPacketKind::Command => {
+ .into_variant(),
+ ChatKind::Command => {
// TODO: chat signing
- ServerboundChatCommandPacket { command: content }.get()
+ ServerboundChatCommand { command: content }.into_variant()
}
};
- send_packet_events.send(SendPacketEvent {
- entity: event.entity,
- packet,
- });
+ send_packet_events.send(SendPacketEvent::new(event.entity, packet));
}
}