mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
more docs
This commit is contained in:
parent
c65e1fc660
commit
329f8b1784
32 changed files with 78 additions and 32 deletions
|
@ -1,4 +1,4 @@
|
|||
use crate::{component::Component, style::Style};
|
||||
use crate::{style::Style, Component};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct BaseComponent {
|
||||
|
|
|
@ -13,6 +13,7 @@ use crate::{
|
|||
translatable_component::{StringOrComponent, TranslatableComponent},
|
||||
};
|
||||
|
||||
/// A chat component, basically anything you can see in chat.
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Component {
|
||||
Text(TextComponent),
|
||||
|
@ -57,7 +58,22 @@ impl Component {
|
|||
Ok(None)
|
||||
}
|
||||
|
||||
/// Convert this component into an ansi string
|
||||
/// Convert this component into an
|
||||
/// [ANSI string](https://en.wikipedia.org/wiki/ANSI_escape_code), so you
|
||||
/// can print it to your terminal and get styling.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// use azalea_chat::Component;
|
||||
///
|
||||
/// let component = Component::deserialize(&serde_json::json!({
|
||||
/// "text": "Hello, world!",
|
||||
/// "color": "red",
|
||||
/// })).unwrap();
|
||||
///
|
||||
/// println!("{}", component.to_ansi());
|
||||
/// ```
|
||||
pub fn to_ansi(&self, default_style: Option<&Style>) -> String {
|
||||
// default the default_style to white if it's not set
|
||||
let default_style: &Style = default_style.unwrap_or(&DEFAULT_STYLE);
|
||||
|
|
|
@ -5,7 +5,9 @@
|
|||
extern crate lazy_static;
|
||||
|
||||
pub mod base_component;
|
||||
pub mod component;
|
||||
mod component;
|
||||
pub mod style;
|
||||
pub mod text_component;
|
||||
pub mod translatable_component;
|
||||
|
||||
pub use component::Component;
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
use std::fmt::Display;
|
||||
|
||||
use crate::{base_component::BaseComponent, component::Component, style::ChatFormatting};
|
||||
use crate::{base_component::BaseComponent, style::ChatFormatting, Component};
|
||||
|
||||
/// A component that contains text that's the same in all locales.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct TextComponent {
|
||||
pub base: BaseComponent,
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
use std::fmt::{self, Display, Formatter};
|
||||
|
||||
use crate::{
|
||||
base_component::BaseComponent, component::Component, style::Style,
|
||||
text_component::TextComponent,
|
||||
base_component::BaseComponent, style::Style, text_component::TextComponent, Component,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
@ -11,6 +10,7 @@ pub enum StringOrComponent {
|
|||
Component(Component),
|
||||
}
|
||||
|
||||
/// A message whose content depends on the client's language.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct TranslatableComponent {
|
||||
pub base: BaseComponent,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use azalea_chat::{
|
||||
component::Component,
|
||||
style::{Ansi, ChatFormatting, TextColor},
|
||||
Component,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use serde_json::Value;
|
||||
|
|
|
@ -6,6 +6,18 @@ use uuid::Uuid;
|
|||
/// Something that can join Minecraft servers.
|
||||
///
|
||||
/// To join a server using this account, use [`crate::Client::join`].
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust,no_run
|
||||
/// use azalea_client::Account;
|
||||
///
|
||||
/// # #[tokio::main]
|
||||
/// # async fn main() {
|
||||
/// let account = Account::microsoft("example@example.com").await;
|
||||
/// // or Account::offline("example");
|
||||
/// # }
|
||||
/// ```
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Account {
|
||||
/// The Minecraft username of the account.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{movement::MoveDirection, Account, Player};
|
||||
use azalea_auth::game_profile::GameProfile;
|
||||
use azalea_chat::component::Component;
|
||||
use azalea_chat::Component;
|
||||
use azalea_core::{ChunkPos, ResourceLocation, Vec3};
|
||||
use azalea_protocol::{
|
||||
connect::{Connection, ConnectionError, ReadConnection, WriteConnection},
|
||||
|
@ -62,6 +62,7 @@ pub enum Event {
|
|||
Packet(Box<ClientboundGamePacket>),
|
||||
}
|
||||
|
||||
/// A chat packet, either a system message or a chat message.
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ChatPacket {
|
||||
System(ClientboundSystemChatPacket),
|
||||
|
@ -69,6 +70,7 @@ pub enum ChatPacket {
|
|||
}
|
||||
|
||||
impl ChatPacket {
|
||||
/// Get the message shown in chat for this packet.
|
||||
pub fn message(&self) -> Component {
|
||||
match self {
|
||||
ChatPacket::System(p) => p.content.clone(),
|
||||
|
|
|
@ -14,7 +14,7 @@ pub mod ping;
|
|||
mod player;
|
||||
|
||||
pub use account::Account;
|
||||
pub use client::{Client, ClientInformation, Event, JoinError};
|
||||
pub use client::{ChatPacket, Client, ClientInformation, Event, JoinError};
|
||||
pub use movement::MoveDirection;
|
||||
pub use player::Player;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use azalea_buf::{
|
||||
BufReadError, McBuf, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable,
|
||||
};
|
||||
use azalea_chat::component::Component;
|
||||
use azalea_chat::Component;
|
||||
use azalea_protocol_macros::ClientboundGamePacket;
|
||||
use std::io::Cursor;
|
||||
use std::io::Write;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use azalea_buf::McBuf;
|
||||
use azalea_chat::component::Component;
|
||||
use azalea_chat::Component;
|
||||
use azalea_protocol_macros::ClientboundGamePacket;
|
||||
|
||||
#[derive(Clone, Debug, McBuf, ClientboundGamePacket)]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use azalea_buf::McBuf;
|
||||
use azalea_chat::component::Component;
|
||||
use azalea_chat::Component;
|
||||
use azalea_protocol_macros::ClientboundGamePacket;
|
||||
|
||||
#[derive(Clone, Debug, McBuf, ClientboundGamePacket)]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use azalea_buf::{BufReadError, McBuf};
|
||||
use azalea_buf::{McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable};
|
||||
use azalea_chat::component::Component;
|
||||
use azalea_chat::Component;
|
||||
use azalea_protocol_macros::ClientboundGamePacket;
|
||||
use std::io::{Cursor, Write};
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use azalea_buf::McBuf;
|
||||
use azalea_chat::component::Component;
|
||||
use azalea_chat::Component;
|
||||
use azalea_protocol_macros::ClientboundGamePacket;
|
||||
|
||||
#[derive(Clone, Debug, McBuf, ClientboundGamePacket)]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use azalea_buf::McBuf;
|
||||
use azalea_chat::{
|
||||
component::Component,
|
||||
translatable_component::{StringOrComponent, TranslatableComponent},
|
||||
Component,
|
||||
};
|
||||
use azalea_core::BitSet;
|
||||
use azalea_crypto::{MessageSignature, SignedMessageHeader};
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use azalea_buf::McBuf;
|
||||
use azalea_chat::component::Component;
|
||||
use azalea_chat::Component;
|
||||
use azalea_protocol_macros::ClientboundGamePacket;
|
||||
|
||||
/// Used to send a respawn screen.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::packets::login::serverbound_hello_packet::ProfilePublicKeyData;
|
||||
use azalea_buf::{BufReadError, McBuf};
|
||||
use azalea_buf::{McBufReadable, McBufWritable};
|
||||
use azalea_chat::component::Component;
|
||||
use azalea_chat::Component;
|
||||
use azalea_protocol_macros::ClientboundGamePacket;
|
||||
use std::io::{Cursor, Write};
|
||||
use uuid::Uuid;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use azalea_buf::McBuf;
|
||||
use azalea_chat::component::Component;
|
||||
use azalea_chat::Component;
|
||||
use azalea_protocol_macros::ClientboundGamePacket;
|
||||
|
||||
#[derive(Clone, Debug, McBuf, ClientboundGamePacket)]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use azalea_buf::McBuf;
|
||||
use azalea_chat::component::Component;
|
||||
use azalea_chat::Component;
|
||||
use azalea_protocol_macros::ClientboundGamePacket;
|
||||
|
||||
#[derive(Clone, Debug, McBuf, ClientboundGamePacket)]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use azalea_buf::McBuf;
|
||||
use azalea_chat::component::Component;
|
||||
use azalea_chat::Component;
|
||||
use azalea_protocol_macros::ClientboundGamePacket;
|
||||
|
||||
#[derive(Clone, Debug, McBuf, ClientboundGamePacket)]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use azalea_buf::{BufReadError, McBuf, McBufReadable, McBufWritable};
|
||||
use azalea_chat::component::Component;
|
||||
use azalea_chat::Component;
|
||||
use azalea_protocol_macros::ClientboundGamePacket;
|
||||
use std::io::{Cursor, Write};
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use azalea_buf::{BufReadError, McBuf, McBufReadable, McBufWritable};
|
||||
use azalea_chat::{component::Component, style::ChatFormatting};
|
||||
use azalea_chat::{style::ChatFormatting, Component};
|
||||
use azalea_protocol_macros::ClientboundGamePacket;
|
||||
use std::io::{Cursor, Write};
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use azalea_buf::McBuf;
|
||||
use azalea_chat::component::Component;
|
||||
use azalea_chat::Component;
|
||||
use azalea_protocol_macros::ClientboundGamePacket;
|
||||
|
||||
#[derive(Clone, Debug, McBuf, ClientboundGamePacket)]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use azalea_buf::McBuf;
|
||||
use azalea_chat::component::Component;
|
||||
use azalea_chat::Component;
|
||||
use azalea_protocol_macros::ClientboundGamePacket;
|
||||
|
||||
#[derive(Clone, Debug, McBuf, ClientboundGamePacket)]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use azalea_buf::McBuf;
|
||||
use azalea_chat::component::Component;
|
||||
use azalea_chat::Component;
|
||||
use azalea_protocol_macros::ClientboundGamePacket;
|
||||
|
||||
#[derive(Clone, Debug, McBuf, ClientboundGamePacket)]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use azalea_buf::McBuf;
|
||||
use azalea_chat::component::Component;
|
||||
use azalea_chat::Component;
|
||||
use azalea_protocol_macros::ClientboundGamePacket;
|
||||
|
||||
#[derive(Clone, Debug, McBuf, ClientboundGamePacket)]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use azalea_buf::McBuf;
|
||||
use azalea_chat::component::Component;
|
||||
use azalea_chat::Component;
|
||||
use azalea_core::{ResourceLocation, Slot};
|
||||
use azalea_protocol_macros::ClientboundGamePacket;
|
||||
use std::collections::HashMap;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use azalea_buf::McBuf;
|
||||
use azalea_chat::component::Component;
|
||||
use azalea_chat::Component;
|
||||
use azalea_protocol_macros::ClientboundLoginPacket;
|
||||
|
||||
#[derive(Clone, Debug, McBuf, ClientboundLoginPacket)]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use azalea_buf::{BufReadError, McBufReadable, McBufWritable};
|
||||
use azalea_chat::component::Component;
|
||||
use azalea_chat::Component;
|
||||
use azalea_protocol_macros::ClientboundStatusPacket;
|
||||
use serde::Deserialize;
|
||||
use serde_json::Value;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use azalea_buf::{BufReadError, McBufVarReadable};
|
||||
use azalea_buf::{McBuf, McBufReadable, McBufWritable};
|
||||
use azalea_chat::component::Component;
|
||||
use azalea_chat::Component;
|
||||
use azalea_core::{BlockPos, Direction, GlobalPos, Particle, Slot};
|
||||
use std::io::{Cursor, Write};
|
||||
use uuid::Uuid;
|
||||
|
|
|
@ -94,8 +94,10 @@ where
|
|||
/// The address of the server that we're connecting to. This can be a
|
||||
/// `&str`, [`ServerAddress`], or anything that implements
|
||||
/// `TryInto<ServerAddress>`.
|
||||
///
|
||||
/// [`ServerAddress`]: azalea_protocol::ServerAddress
|
||||
pub address: A,
|
||||
/// The account that's going to join the server,
|
||||
/// The account that's going to join the server.
|
||||
pub account: Account,
|
||||
/// A list of plugins that are going to be used. Plugins are external
|
||||
/// crates that add extra functionality to Azalea.
|
||||
|
@ -116,6 +118,17 @@ where
|
|||
/// ```
|
||||
pub state: S,
|
||||
/// The function that's called whenever we get an event.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// use anyhow::Result;
|
||||
/// use azalea::prelude::*;
|
||||
///
|
||||
/// async fn handle(bot: Client, event: Event, state: State) -> anyhow::Result<()> {
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
pub handle: HandleFn<Fut, S>,
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ def burger_type_to_rust_type(burger_type, field_name: Optional[str] = None, inst
|
|||
|
||||
elif burger_type == 'chatcomponent':
|
||||
field_type_rs = 'Component'
|
||||
uses.add('azalea_chat::component::Component')
|
||||
uses.add('azalea_chat::Component')
|
||||
elif burger_type == 'identifier':
|
||||
field_type_rs = 'ResourceLocation'
|
||||
uses.add('azalea_core::ResourceLocation')
|
||||
|
|
Loading…
Add table
Reference in a new issue