mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
* make azalea-pathfinder dir * start writing d* lite impl * more work on d* lite * work more on implementing d* lite * full d* lite impl * updated edges * add next() function * add NoPathError * why does dstar lite not work * fix d* lite implementation * make the test actually check the coords * replace while loop with if statement * fix clippy complaints * make W only have to be PartialOrd * fix PartialOrd issues * implement mtd* lite * add a test to mtd* lite * remove normal d* lite * make heuristic only take in one arg * add `success` function * Update README.md * evil black magic to make .entity not need dimension * start adding moves * slightly improve the vec3/position situation new macro that implements all the useful functions * moves stuff * make it compile * update deps in az-pathfinder * make it compile again * more pathfinding stuff * add Bot::look_at * replace EntityMut and EntityRef with just Entity * block pos pathfinding stuff * rename movedirection to walkdirection * execute path every tick * advance path * change az-pf version * make azalea_client keep plugin state * fix Plugins::get * why does it think there is air * start debugging incorrect air * update some From methods to use rem_euclid * start adding swarm * fix deadlock i still don't understand why it was happening but the solution was to keep the Client::player lock for shorter so it didn't overlap with the Client::dimension lock * make lookat actually work probably * fix going too fast * Update main.rs * make a thing immutable * direction_looking_at * fix rotations * import swarm in an example * fix stuff from merge * remove azalea_pathfinder import * delete azalea-pathfinder crate already in azalea::pathfinder module * swarms * start working on shared dimensions * Shared worlds work * start adding Swarm::add_account * add_account works * change "client" to "bot" in some places * Fix issues from merge * Update world.rs * add SwarmEvent::Disconnect(Account) * almost add SwarmEvent::Chat and new plugin system it panics rn * make plugins have to provide the State associated type * improve comments * make fn build slightly cleaner * fix SwarmEvent::Chat * change a println in bot/main.rs * Client::shutdown -> disconnect * polish fix clippy warnings + improve some docs a bit * fix shared worlds* *there's a bug that entities and bots will have their positions exaggerated because the relative movement packet is applied for every entity once per bot * i am being trolled by rust for some reason some stuff is really slow for literally no reason and it makes no sense i am going insane * make world an RwLock again * remove debug messages * fix skipping event ticks unfortunately now sending events is `.send().await?` instead of just `.send()` * fix deadlock + warnings * turns out my floor_mod impl was wrong and i32::rem_euclid has the correct behavior LOL * still errors with lots of bots * make swarm iter & fix new chunks not loading * improve docs * start fixing tests * fix all the tests except the examples i don't know how to exclude them from the tests * improve docs some more
161 lines
4.9 KiB
Rust
Executable file
161 lines
4.9 KiB
Rust
Executable file
use azalea_buf::McBuf;
|
|
use azalea_chat::{
|
|
translatable_component::{StringOrComponent, TranslatableComponent},
|
|
Component,
|
|
};
|
|
use azalea_core::BitSet;
|
|
use azalea_crypto::{MessageSignature, SignedMessageHeader};
|
|
use azalea_protocol_macros::ClientboundGamePacket;
|
|
use uuid::Uuid;
|
|
|
|
#[derive(Clone, Debug, McBuf, ClientboundGamePacket, PartialEq)]
|
|
pub struct ClientboundPlayerChatPacket {
|
|
pub message: PlayerChatMessage,
|
|
pub chat_type: ChatTypeBound,
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, McBuf, PartialEq, Eq)]
|
|
pub enum ChatType {
|
|
Chat = 0,
|
|
SayCommand = 1,
|
|
MsgCommandIncoming = 2,
|
|
MsgCommandOutgoing = 3,
|
|
TeamMsgCommandIncoming = 4,
|
|
TeamMsgCommandOutgoing = 5,
|
|
EmoteCommand = 6,
|
|
}
|
|
|
|
#[derive(Clone, Debug, McBuf, PartialEq)]
|
|
pub struct ChatTypeBound {
|
|
pub chat_type: ChatType,
|
|
pub name: Component,
|
|
pub target_name: Option<Component>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, McBuf, PartialEq)]
|
|
pub struct PlayerChatMessage {
|
|
pub signed_header: SignedMessageHeader,
|
|
pub header_signature: MessageSignature,
|
|
pub signed_body: SignedMessageBody,
|
|
pub unsigned_content: Option<Component>,
|
|
pub filter_mask: FilterMask,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, McBuf)]
|
|
pub struct SignedMessageBody {
|
|
pub content: ChatMessageContent,
|
|
pub timestamp: u64,
|
|
pub salt: u64,
|
|
pub last_seen: Vec<LastSeenMessagesEntry>,
|
|
}
|
|
|
|
impl PlayerChatMessage {
|
|
/// Returns the content of the message. If you want to get the Component
|
|
/// for the whole message including the sender part, use
|
|
/// [`ClientboundPlayerChatPacket::message`].
|
|
pub fn content(&self, only_secure_chat: bool) -> Component {
|
|
if only_secure_chat {
|
|
return self
|
|
.signed_body
|
|
.content
|
|
.decorated
|
|
.clone()
|
|
.unwrap_or_else(|| Component::from(self.signed_body.content.plain.clone()));
|
|
}
|
|
self.unsigned_content
|
|
.clone()
|
|
.unwrap_or_else(|| self.content(true))
|
|
}
|
|
}
|
|
|
|
impl ClientboundPlayerChatPacket {
|
|
/// Get the full message, including the sender part.
|
|
pub fn message(&self, only_secure_chat: bool) -> Component {
|
|
let sender = self.chat_type.name.clone();
|
|
let content = self.message.content(only_secure_chat);
|
|
let target = self.chat_type.target_name.clone();
|
|
|
|
let translation_key = self.chat_type.chat_type.chat_translation_key();
|
|
|
|
let mut args = vec![
|
|
StringOrComponent::Component(sender),
|
|
StringOrComponent::Component(content),
|
|
];
|
|
if let Some(target) = target {
|
|
args.push(StringOrComponent::Component(target));
|
|
}
|
|
|
|
let component = TranslatableComponent::new(translation_key.to_string(), args);
|
|
|
|
Component::Translatable(component)
|
|
}
|
|
}
|
|
|
|
impl ChatType {
|
|
pub fn chat_translation_key(&self) -> &'static str {
|
|
match self {
|
|
ChatType::Chat => "chat.type.text",
|
|
ChatType::SayCommand => "chat.type.announcement",
|
|
ChatType::MsgCommandIncoming => "commands.message.display.incoming",
|
|
ChatType::MsgCommandOutgoing => "commands.message.display.outgoing",
|
|
ChatType::TeamMsgCommandIncoming => "chat.type.team.text",
|
|
ChatType::TeamMsgCommandOutgoing => "chat.type.team.sent",
|
|
ChatType::EmoteCommand => "chat.type.emote",
|
|
}
|
|
}
|
|
|
|
pub fn narrator_translation_key(&self) -> &'static str {
|
|
match self {
|
|
ChatType::Chat => "chat.type.text.narrate",
|
|
ChatType::SayCommand => "chat.type.text.narrate",
|
|
ChatType::MsgCommandIncoming => "chat.type.text.narrate",
|
|
ChatType::MsgCommandOutgoing => "chat.type.text.narrate",
|
|
ChatType::TeamMsgCommandIncoming => "chat.type.text.narrate",
|
|
ChatType::TeamMsgCommandOutgoing => "chat.type.text.narrate",
|
|
ChatType::EmoteCommand => "chat.type.emote",
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, McBuf, PartialEq)]
|
|
pub struct LastSeenMessagesEntry {
|
|
pub profile_id: Uuid,
|
|
pub last_signature: MessageSignature,
|
|
}
|
|
|
|
#[derive(Clone, Debug, McBuf, Default)]
|
|
pub struct LastSeenMessagesUpdate {
|
|
pub last_seen: Vec<LastSeenMessagesEntry>,
|
|
pub last_received: Option<LastSeenMessagesEntry>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, McBuf, PartialEq)]
|
|
pub struct ChatMessageContent {
|
|
pub plain: String,
|
|
/// Only sent if the decorated message is different than the plain.
|
|
pub decorated: Option<Component>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, McBuf, PartialEq)]
|
|
pub enum FilterMask {
|
|
PassThrough,
|
|
FullyFiltered,
|
|
PartiallyFiltered(BitSet),
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
use azalea_buf::McBufReadable;
|
|
use std::io::Cursor;
|
|
|
|
#[test]
|
|
fn test_chat_type() {
|
|
let chat_type_enum = ChatType::read_from(&mut Cursor::new(&[0x06])).unwrap();
|
|
assert_eq!(chat_type_enum, ChatType::EmoteCommand);
|
|
assert_eq!(
|
|
ChatType::read_from(&mut Cursor::new(&[0x07])).unwrap(),
|
|
ChatType::Chat
|
|
);
|
|
}
|
|
}
|