diff --git a/Cargo.lock b/Cargo.lock index 279293d3..5bb13622 100755 --- a/Cargo.lock +++ b/Cargo.lock @@ -100,7 +100,7 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "azalea" -version = "0.2.4" +version = "0.3.0" dependencies = [ "anyhow", "async-trait", @@ -115,7 +115,7 @@ dependencies = [ [[package]] name = "azalea-auth" -version = "0.2.2" +version = "0.3.0" dependencies = [ "azalea-buf", "azalea-crypto", @@ -133,7 +133,7 @@ dependencies = [ [[package]] name = "azalea-block" -version = "0.2.0" +version = "0.3.0" dependencies = [ "azalea-block-macros", "azalea-buf", @@ -141,7 +141,7 @@ dependencies = [ [[package]] name = "azalea-block-macros" -version = "0.2.0" +version = "0.3.0" dependencies = [ "proc-macro2", "quote", @@ -150,11 +150,11 @@ dependencies = [ [[package]] name = "azalea-brigadier" -version = "0.2.0" +version = "0.3.0" [[package]] name = "azalea-buf" -version = "0.2.0" +version = "0.3.0" dependencies = [ "azalea-buf-macros", "byteorder", @@ -166,7 +166,7 @@ dependencies = [ [[package]] name = "azalea-buf-macros" -version = "0.2.0" +version = "0.3.0" dependencies = [ "proc-macro2", "quote", @@ -175,7 +175,7 @@ dependencies = [ [[package]] name = "azalea-chat" -version = "0.2.0" +version = "0.3.0" dependencies = [ "azalea-buf", "azalea-language", @@ -186,7 +186,7 @@ dependencies = [ [[package]] name = "azalea-client" -version = "0.2.2" +version = "0.3.0" dependencies = [ "anyhow", "azalea-auth", @@ -206,7 +206,7 @@ dependencies = [ [[package]] name = "azalea-core" -version = "0.2.0" +version = "0.3.0" dependencies = [ "azalea-buf", "azalea-chat", @@ -216,7 +216,7 @@ dependencies = [ [[package]] name = "azalea-crypto" -version = "0.2.0" +version = "0.3.0" dependencies = [ "aes", "azalea-buf", @@ -231,7 +231,7 @@ dependencies = [ [[package]] name = "azalea-language" -version = "0.2.0" +version = "0.3.0" dependencies = [ "lazy_static", "serde", @@ -240,7 +240,7 @@ dependencies = [ [[package]] name = "azalea-nbt" -version = "0.2.0" +version = "0.3.0" dependencies = [ "ahash", "azalea-buf", @@ -269,7 +269,7 @@ dependencies = [ [[package]] name = "azalea-physics" -version = "0.2.0" +version = "0.3.0" dependencies = [ "azalea-block", "azalea-core", @@ -280,7 +280,7 @@ dependencies = [ [[package]] name = "azalea-protocol" -version = "0.2.0" +version = "0.3.0" dependencies = [ "async-compression", "async-recursion", @@ -312,7 +312,7 @@ dependencies = [ [[package]] name = "azalea-protocol-macros" -version = "0.2.0" +version = "0.3.0" dependencies = [ "proc-macro2", "quote", @@ -321,7 +321,7 @@ dependencies = [ [[package]] name = "azalea-registry" -version = "0.2.0" +version = "0.3.0" dependencies = [ "azalea-buf", "azalea-registry-macros", @@ -329,7 +329,7 @@ dependencies = [ [[package]] name = "azalea-registry-macros" -version = "0.2.0" +version = "0.3.0" dependencies = [ "proc-macro2", "quote", @@ -338,7 +338,7 @@ dependencies = [ [[package]] name = "azalea-world" -version = "0.2.0" +version = "0.3.0" dependencies = [ "azalea-block", "azalea-buf", diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 00000000..148b9d56 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 mat + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 0bd5b96a..92caf0fe 100755 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Azalea +[![docs.rs](https://img.shields.io/docsrs/azalea)](https://docs.rs/azalea) + A collection of Rust crates for making Minecraft bots, clients, and tools.

@@ -9,7 +11,7 @@ A collection of Rust crates for making Minecraft bots, clients, and tools. *Currently supported Minecraft version: `1.19.2`.* -## ⚠️ Azalea is still very unfinished, though some crates are in a somewhat useable state +## ⚠️ Azalea is still very unfinished, though most crates are in a somewhat useable state I named this Azalea because it sounds like a cool word and this is a cool library. diff --git a/azalea-auth/Cargo.toml b/azalea-auth/Cargo.toml index 4e26e6e4..da5460ab 100755 --- a/azalea-auth/Cargo.toml +++ b/azalea-auth/Cargo.toml @@ -3,23 +3,24 @@ description = "A port of Mojang's Authlib and launcher authentication." edition = "2021" license = "MIT" name = "azalea-auth" -version = "0.2.2" +repository = "https://github.com/mat-1/azalea/tree/main/azalea-auth" +version = "0.3.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -azalea-buf = { path = "../azalea-buf", version = "^0.2.0" } -azalea-crypto = { path = "../azalea-crypto", version = "^0.2.0" } -chrono = { version = "0.4.22", default-features = false } +azalea-buf = {path = "../azalea-buf", version = "^0.3.0" } +azalea-crypto = {path = "../azalea-crypto", version = "^0.3.0" } +chrono = {version = "0.4.22", default-features = false} log = "0.4.17" num-bigint = "0.4.3" -reqwest = { version = "0.11.12", features = ["json"] } -serde = { version = "1.0.145", features = ["derive"] } +reqwest = {version = "0.11.12", features = ["json"]} +serde = {version = "1.0.145", features = ["derive"]} serde_json = "1.0.86" thiserror = "1.0.37" -tokio = { version = "1.21.2", features = ["fs"] } +tokio = {version = "1.21.2", features = ["fs"]} uuid = "^1.1.2" [dev-dependencies] env_logger = "0.9.1" -tokio = { version = "1.21.2", features = ["full"] } +tokio = {version = "1.21.2", features = ["full"]} diff --git a/azalea-auth/src/auth.rs b/azalea-auth/src/auth.rs index 0b043baf..b7f834d4 100755 --- a/azalea-auth/src/auth.rs +++ b/azalea-auth/src/auth.rs @@ -444,10 +444,7 @@ async fn check_ownership( ) -> Result { let res = client .get("https://api.minecraftservices.com/entitlements/mcstore") - .header( - "Authorization", - format!("Bearer {minecraft_access_token}"), - ) + .header("Authorization", format!("Bearer {minecraft_access_token}")) .send() .await? .json::() @@ -472,10 +469,7 @@ async fn get_profile( ) -> Result { let res = client .get("https://api.minecraftservices.com/minecraft/profile") - .header( - "Authorization", - format!("Bearer {minecraft_access_token}"), - ) + .header("Authorization", format!("Bearer {minecraft_access_token}")) .send() .await? .json::() diff --git a/azalea-block/Cargo.toml b/azalea-block/Cargo.toml index f964713e..18faf275 100755 --- a/azalea-block/Cargo.toml +++ b/azalea-block/Cargo.toml @@ -3,12 +3,13 @@ description = "Representation of Minecraft block states." edition = "2021" license = "MIT" name = "azalea-block" -version = "0.2.0" +repository = "https://github.com/mat-1/azalea/tree/main/azalea-block" +version = "0.3.0" [lib] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -azalea-block-macros = {path = "./azalea-block-macros", version = "^0.2.0" } -azalea-buf = {path = "../azalea-buf", version = "^0.2.0" } +azalea-block-macros = {path = "./azalea-block-macros", version = "^0.3.0" } +azalea-buf = {path = "../azalea-buf", version = "^0.3.0" } diff --git a/azalea-block/azalea-block-macros/Cargo.toml b/azalea-block/azalea-block-macros/Cargo.toml index d208dc99..dc8b1f27 100755 --- a/azalea-block/azalea-block-macros/Cargo.toml +++ b/azalea-block/azalea-block-macros/Cargo.toml @@ -3,7 +3,8 @@ description = "Proc macros used by azalea-block." edition = "2021" license = "MIT" name = "azalea-block-macros" -version = "0.2.0" +repository = "https://github.com/mat-1/azalea/tree/main/azalea-block/azalea-block-macros" +version = "0.3.0" [lib] proc-macro = true diff --git a/azalea-brigadier/Cargo.toml b/azalea-brigadier/Cargo.toml index f078cbef..987f1867 100755 --- a/azalea-brigadier/Cargo.toml +++ b/azalea-brigadier/Cargo.toml @@ -3,7 +3,8 @@ description = "A port of Mojang's Brigadier command parsing and dispatching libr edition = "2021" license = "MIT" name = "azalea-brigadier" -version = "0.2.0" +repository = "https://github.com/mat-1/azalea/tree/main/azalea-brigadier" +version = "0.3.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/azalea-buf/Cargo.toml b/azalea-buf/Cargo.toml index 71b0eb83..d8be1a11 100755 --- a/azalea-buf/Cargo.toml +++ b/azalea-buf/Cargo.toml @@ -3,12 +3,13 @@ description = "Serialize and deserialize buffers from Minecraft." edition = "2021" license = "MIT" name = "azalea-buf" -version = "0.2.0" +repository = "https://github.com/mat-1/azalea/tree/main/azalea-buf" +version = "0.3.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -azalea-buf-macros = {path = "./azalea-buf-macros", version = "^0.2.0" } +azalea-buf-macros = {path = "./azalea-buf-macros", version = "^0.3.0" } byteorder = "^1.4.3" serde_json = {version = "^1.0", optional = true} thiserror = "^1.0.34" diff --git a/azalea-buf/azalea-buf-macros/Cargo.toml b/azalea-buf/azalea-buf-macros/Cargo.toml index 1ca72c57..155acc84 100755 --- a/azalea-buf/azalea-buf-macros/Cargo.toml +++ b/azalea-buf/azalea-buf-macros/Cargo.toml @@ -3,7 +3,8 @@ description = "#[derive(McBuf)]" edition = "2021" license = "MIT" name = "azalea-buf-macros" -version = "0.2.0" +repository = "https://github.com/mat-1/azalea/tree/main/azalea-buf" +version = "0.3.0" [lib] proc-macro = true diff --git a/azalea-chat/Cargo.toml b/azalea-chat/Cargo.toml index 8fd77e96..7710a4c2 100755 --- a/azalea-chat/Cargo.toml +++ b/azalea-chat/Cargo.toml @@ -3,13 +3,14 @@ description = "Parse Minecraft chat messages." edition = "2021" license = "MIT" name = "azalea-chat" -version = "0.2.0" +version = "0.3.0" +repository = "https://github.com/mat-1/azalea/tree/main/azalea-chat" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -azalea-buf = {path = "../azalea-buf", features = ["serde_json"], version = "^0.2.0" } -azalea-language = {path = "../azalea-language", version = "^0.2.0" } +azalea-buf = {path = "../azalea-buf", features = ["serde_json"], version = "^0.3.0" } +azalea-language = {path = "../azalea-language", version = "^0.3.0" } lazy_static = "^1.4.0" serde = "^1.0.130" serde_json = "^1.0.72" diff --git a/azalea-chat/src/base_component.rs b/azalea-chat/src/base_component.rs index fa39a11c..c2f3513d 100755 --- a/azalea-chat/src/base_component.rs +++ b/azalea-chat/src/base_component.rs @@ -1,4 +1,4 @@ -use crate::{component::Component, style::Style}; +use crate::{style::Style, Component}; #[derive(Clone, Debug)] pub struct BaseComponent { diff --git a/azalea-chat/src/component.rs b/azalea-chat/src/component.rs index 6dd11084..4df3796f 100755 --- a/azalea-chat/src/component.rs +++ b/azalea-chat/src/component.rs @@ -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); diff --git a/azalea-chat/src/lib.rs b/azalea-chat/src/lib.rs index b7035e13..01f718eb 100755 --- a/azalea-chat/src/lib.rs +++ b/azalea-chat/src/lib.rs @@ -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; diff --git a/azalea-chat/src/text_component.rs b/azalea-chat/src/text_component.rs index 96eef08e..46cb0951 100755 --- a/azalea-chat/src/text_component.rs +++ b/azalea-chat/src/text_component.rs @@ -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, diff --git a/azalea-chat/src/translatable_component.rs b/azalea-chat/src/translatable_component.rs index 7c01819b..d187adda 100755 --- a/azalea-chat/src/translatable_component.rs +++ b/azalea-chat/src/translatable_component.rs @@ -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, diff --git a/azalea-chat/tests/integration_test.rs b/azalea-chat/tests/integration_test.rs index c2be960e..cc976888 100755 --- a/azalea-chat/tests/integration_test.rs +++ b/azalea-chat/tests/integration_test.rs @@ -1,6 +1,6 @@ use azalea_chat::{ - component::Component, style::{Ansi, ChatFormatting, TextColor}, + Component, }; use serde::Deserialize; use serde_json::Value; diff --git a/azalea-client/Cargo.toml b/azalea-client/Cargo.toml index 84df872a..93559293 100755 --- a/azalea-client/Cargo.toml +++ b/azalea-client/Cargo.toml @@ -3,20 +3,21 @@ description = "A headless Minecraft client." edition = "2021" license = "MIT" name = "azalea-client" -version = "0.2.2" +version = "0.3.0" +repository = "https://github.com/mat-1/azalea/tree/main/azalea-client" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] anyhow = "1.0.59" -azalea-auth = { path = "../azalea-auth", version = "0.2.1" } -azalea-block = { path = "../azalea-block", version = "0.2.0" } -azalea-chat = { path = "../azalea-chat", version = "0.2.0" } -azalea-core = { path = "../azalea-core", version = "0.2.0" } -azalea-crypto = { path = "../azalea-crypto", version = "0.2.0" } -azalea-physics = { path = "../azalea-physics", version = "0.2.0" } -azalea-protocol = { path = "../azalea-protocol", version = "0.2.0" } -azalea-world = { path = "../azalea-world", version = "0.2.0" } +azalea-auth = { path = "../azalea-auth", version = "0.3.0" } +azalea-block = { path = "../azalea-block", version = "0.3.0" } +azalea-chat = { path = "../azalea-chat", version = "0.3.0" } +azalea-core = { path = "../azalea-core", version = "0.3.0" } +azalea-crypto = { path = "../azalea-crypto", version = "0.3.0" } +azalea-physics = { path = "../azalea-physics", version = "0.3.0" } +azalea-protocol = { path = "../azalea-protocol", version = "0.3.0" } +azalea-world = { path = "../azalea-world", version = "0.3.0" } log = "0.4.17" parking_lot = "0.12.1" thiserror = "^1.0.34" diff --git a/azalea-client/src/account.rs b/azalea-client/src/account.rs index f63d342e..42bfe6fc 100755 --- a/azalea-client/src/account.rs +++ b/azalea-client/src/account.rs @@ -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. @@ -34,7 +46,12 @@ impl Account { /// a key for the cache, but it's recommended to use the real email to /// avoid confusion. pub async fn microsoft(email: &str) -> Result { - let minecraft_dir = get_mc_dir::minecraft_dir().unwrap(); + let minecraft_dir = get_mc_dir::minecraft_dir().unwrap_or_else(|| { + panic!( + "No {} environment variable found", + get_mc_dir::home_env_var() + ) + }); let auth_result = azalea_auth::auth( email, azalea_auth::AuthOpts { diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs index 17919d25..97eb4ac6 100755 --- a/azalea-client/src/client.rs +++ b/azalea-client/src/client.rs @@ -1,6 +1,6 @@ use crate::{movement::WalkDirection, 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}, @@ -17,6 +17,7 @@ use azalea_protocol::{ }, handshake::client_intention_packet::ClientIntentionPacket, login::{ + serverbound_custom_query_packet::ServerboundCustomQueryPacket, serverbound_hello_packet::ServerboundHelloPacket, serverbound_key_packet::{NonceOrSaltSignature, ServerboundKeyPacket}, ClientboundLoginPacket, @@ -62,6 +63,7 @@ pub enum Event { Packet(Box), } +/// A chat packet, either a system message or a chat message. #[derive(Debug, Clone)] pub enum ChatPacket { System(ClientboundSystemChatPacket), @@ -69,6 +71,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(), @@ -182,55 +185,56 @@ impl Client { .await?; let (conn, game_profile) = loop { - let packet_result = conn.read().await; - match packet_result { - Ok(packet) => match packet { - ClientboundLoginPacket::Hello(p) => { - debug!("Got encryption request"); - let e = azalea_crypto::encrypt(&p.public_key, &p.nonce).unwrap(); + let packet = conn.read().await?; + match packet { + ClientboundLoginPacket::Hello(p) => { + debug!("Got encryption request"); + let e = azalea_crypto::encrypt(&p.public_key, &p.nonce).unwrap(); - if let Some(access_token) = &account.access_token { - conn.authenticate( - access_token, - &account - .uuid - .expect("Uuid must be present if access token is present."), - e.secret_key, - p, - ) - .await?; - } - - conn.write( - ServerboundKeyPacket { - nonce_or_salt_signature: NonceOrSaltSignature::Nonce( - e.encrypted_nonce, - ), - key_bytes: e.encrypted_public_key, - } - .get(), + if let Some(access_token) = &account.access_token { + conn.authenticate( + access_token, + &account + .uuid + .expect("Uuid must be present if access token is present."), + e.secret_key, + p, ) .await?; + } - conn.set_encryption_key(e.secret_key); - } - ClientboundLoginPacket::LoginCompression(p) => { - debug!("Got compression request {:?}", p.compression_threshold); - conn.set_compression_threshold(p.compression_threshold); - } - ClientboundLoginPacket::GameProfile(p) => { - debug!("Got profile {:?}", p.game_profile); - break (conn.game(), p.game_profile); - } - ClientboundLoginPacket::LoginDisconnect(p) => { - debug!("Got disconnect {:?}", p); - } - ClientboundLoginPacket::CustomQuery(p) => { - debug!("Got custom query {:?}", p); - } - }, - Err(e) => { - panic!("Error: {e:?}"); + conn.write( + ServerboundKeyPacket { + nonce_or_salt_signature: NonceOrSaltSignature::Nonce(e.encrypted_nonce), + key_bytes: e.encrypted_public_key, + } + .get(), + ) + .await?; + + conn.set_encryption_key(e.secret_key); + } + ClientboundLoginPacket::LoginCompression(p) => { + debug!("Got compression request {:?}", p.compression_threshold); + conn.set_compression_threshold(p.compression_threshold); + } + ClientboundLoginPacket::GameProfile(p) => { + debug!("Got profile {:?}", p.game_profile); + break (conn.game(), p.game_profile); + } + ClientboundLoginPacket::LoginDisconnect(p) => { + debug!("Got disconnect {:?}", p); + } + ClientboundLoginPacket::CustomQuery(p) => { + debug!("Got custom query {:?}", p); + conn.write( + ServerboundCustomQueryPacket { + transaction_id: p.transaction_id, + data: None, + } + .get(), + ) + .await?; } } }; @@ -758,6 +762,7 @@ impl Client { ClientboundGamePacket::TabList(_) => {} ClientboundGamePacket::TagQuery(_) => {} ClientboundGamePacket::TakeItemEntity(_) => {} + ClientboundGamePacket::ContainerClose(_) => {} } Ok(()) diff --git a/azalea-client/src/get_mc_dir.rs b/azalea-client/src/get_mc_dir.rs index abc5b3c8..440550a7 100755 --- a/azalea-client/src/get_mc_dir.rs +++ b/azalea-client/src/get_mc_dir.rs @@ -10,25 +10,52 @@ use std::path::PathBuf; /// Mac: `$HOME/Library/Application Support/minecraft`\ /// Linux: `$HOME/.minecraft` /// -/// Anywhere else it'll return None. +/// If the environment variable is not set, this will return `None`. pub fn minecraft_dir() -> Option { + let env_var = home_env_var(); + let home = std::env::var(env_var).ok()?; + let path = PathBuf::from(home).join(minecraft_dir_relative()); + Some(path) +} + +/// Return the name of the environment variable that's used for the home folder +/// on the user's operating system. +pub fn home_env_var() -> &'static str { #[cfg(target_os = "windows")] { - let appdata = std::env::var("APPDATA").ok()?; - Some(PathBuf::from(appdata).join(".minecraft")) + "USERPROFILE" } #[cfg(target_os = "macos")] { - let home = std::env::var("HOME").ok()?; - Some(PathBuf::from(home).join("Library/Application Support/minecraft")) + "HOME" } #[cfg(target_os = "linux")] { - let home = std::env::var("HOME").ok()?; - Some(PathBuf::from(home).join(".minecraft")) + "HOME" } #[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))] { - None + "HOME" + } +} + +/// Return the path relative to the home folder where we expect to find the +/// .minecraft directory. +pub fn minecraft_dir_relative() -> &'static str { + #[cfg(target_os = "windows")] + { + ".minecraft" + } + #[cfg(target_os = "macos")] + { + "Library/Application Support/minecraft" + } + #[cfg(target_os = "linux")] + { + ".minecraft" + } + #[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))] + { + ".minecraft" } } diff --git a/azalea-client/src/lib.rs b/azalea-client/src/lib.rs index ac99695b..ce482041 100755 --- a/azalea-client/src/lib.rs +++ b/azalea-client/src/lib.rs @@ -14,7 +14,7 @@ pub mod ping; mod player; pub use account::Account; -pub use client::{Client, ClientInformation, Event}; +pub use client::{ChatPacket, Client, ClientInformation, Event, JoinError}; pub use movement::WalkDirection; pub use player::Player; diff --git a/azalea-core/Cargo.toml b/azalea-core/Cargo.toml index dec1e61e..6d0174ba 100755 --- a/azalea-core/Cargo.toml +++ b/azalea-core/Cargo.toml @@ -3,12 +3,13 @@ description = "Miscellaneous things in Azalea." edition = "2021" license = "MIT" name = "azalea-core" -version = "0.2.0" +version = "0.3.0" +repository = "https://github.com/mat-1/azalea/tree/main/azalea-core" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -azalea-buf = {path = "../azalea-buf", version = "^0.2.0" } -azalea-chat = {path = "../azalea-chat", version = "^0.2.0" } -azalea-nbt = {path = "../azalea-nbt", version = "^0.2.0" } +azalea-buf = {path = "../azalea-buf", version = "^0.3.0" } +azalea-chat = {path = "../azalea-chat", version = "^0.3.0" } +azalea-nbt = {path = "../azalea-nbt", version = "^0.3.0" } uuid = "^1.1.2" diff --git a/azalea-crypto/Cargo.toml b/azalea-crypto/Cargo.toml index 50ea7358..82057ec2 100755 --- a/azalea-crypto/Cargo.toml +++ b/azalea-crypto/Cargo.toml @@ -3,13 +3,14 @@ description = "Cryptography features used in Minecraft." edition = "2021" license = "MIT" name = "azalea-crypto" -version = "0.2.0" +version = "0.3.0" +repository = "https://github.com/mat-1/azalea/tree/main/azalea-crypto" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] aes = "0.8.1" -azalea-buf = {path = "../azalea-buf", version = "^0.2.0" } +azalea-buf = {path = "../azalea-buf", version = "^0.3.0" } cfb8 = "0.8.1" num-bigint = "^0.4.3" rand = {version = "^0.8.4", features = ["getrandom"]} diff --git a/azalea-language/Cargo.toml b/azalea-language/Cargo.toml index f1902c05..4793092a 100755 --- a/azalea-language/Cargo.toml +++ b/azalea-language/Cargo.toml @@ -3,7 +3,8 @@ description = "Translate Minecraft strings from their id." edition = "2021" license = "MIT" name = "azalea-language" -version = "0.2.0" +version = "0.3.0" +repository = "https://github.com/mat-1/azalea/tree/main/azalea-language" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/azalea-nbt/Cargo.toml b/azalea-nbt/Cargo.toml index 5ad2b943..5e776dbe 100755 --- a/azalea-nbt/Cargo.toml +++ b/azalea-nbt/Cargo.toml @@ -3,13 +3,14 @@ description = "A fast NBT serializer and deserializer." edition = "2021" license = "MIT" name = "azalea-nbt" -version = "0.2.0" +version = "0.3.0" +repository = "https://github.com/mat-1/azalea/tree/main/azalea-nbt" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] ahash = "^0.8.0" -azalea-buf = {path = "../azalea-buf", version = "^0.2.0" } +azalea-buf = {path = "../azalea-buf", version = "^0.3.0" } byteorder = "^1.4.3" flate2 = "^1.0.23" num-derive = "^0.3.3" diff --git a/azalea-pathfinder/Cargo.toml b/azalea-pathfinder/Cargo.toml index 62140ffb..1293eee7 100755 --- a/azalea-pathfinder/Cargo.toml +++ b/azalea-pathfinder/Cargo.toml @@ -8,11 +8,11 @@ version = "0.1.0" [dependencies] anyhow = "1.0.65" async-trait = "0.1.57" -azalea = {version = "0.2.4", path = "../azalea"} -azalea-block = {version = "0.2.0", path = "../azalea-block"} -azalea-client = {version = "0.2.2", path = "../azalea-client"} -azalea-core = {version = "0.2.0", path = "../azalea-core"} -azalea-physics = {version = "0.2.0", path = "../azalea-physics"} -azalea-world = {version = "0.2.0", path = "../azalea-world"} +azalea = { version = "0.3.0", path = "../azalea" } +azalea-block = { version = "0.3.0", path = "../azalea-block" } +azalea-client = { version = "0.3.0", path = "../azalea-client" } +azalea-core = { version = "0.3.0", path = "../azalea-core" } +azalea-physics = { version = "0.3.0", path = "../azalea-physics" } +azalea-world = { version = "0.3.0", path = "../azalea-world" } num-traits = "0.2.15" priority-queue = "1.2.3" diff --git a/azalea-physics/Cargo.toml b/azalea-physics/Cargo.toml index d40fe3e7..8012a674 100755 --- a/azalea-physics/Cargo.toml +++ b/azalea-physics/Cargo.toml @@ -3,14 +3,15 @@ description = "Physics for Minecraft entities." edition = "2021" license = "MIT" name = "azalea-physics" -version = "0.2.0" +version = "0.3.0" +repository = "https://github.com/mat-1/azalea/tree/main/azalea-physics" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -azalea-block = { path = "../azalea-block", version = "^0.2.0" } -azalea-core = { path = "../azalea-core", version = "^0.2.0" } -azalea-world = { path = "../azalea-world", version = "^0.2.0" } +azalea-block = { path = "../azalea-block", version = "^0.3.0" } +azalea-core = { path = "../azalea-core", version = "^0.3.0" } +azalea-world = { path = "../azalea-world", version = "^0.3.0" } lazy_static = "1.4.0" [dev-dependencies] diff --git a/azalea-protocol/Cargo.toml b/azalea-protocol/Cargo.toml index 009c1344..f08282d0 100755 --- a/azalea-protocol/Cargo.toml +++ b/azalea-protocol/Cargo.toml @@ -3,24 +3,25 @@ description = "Send and receive Minecraft packets." edition = "2021" license = "MIT" name = "azalea-protocol" -version = "0.2.0" +version = "0.3.0" +repository = "https://github.com/mat-1/azalea/tree/main/azalea-protocol" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] async-compression = {version = "^0.3.8", features = ["tokio", "zlib"], optional = true} async-recursion = "1.0.0" -azalea-auth = {path = "../azalea-auth", version = "^0.2.1" } -azalea-block = {path = "../azalea-block", default-features = false, version = "^0.2.0" } -azalea-brigadier = {path = "../azalea-brigadier", version = "^0.2.0" } -azalea-buf = {path = "../azalea-buf", version = "^0.2.0" } -azalea-chat = {path = "../azalea-chat", version = "^0.2.0" } -azalea-core = {path = "../azalea-core", optional = true, version = "^0.2.0" } -azalea-crypto = {path = "../azalea-crypto", version = "^0.2.0" } -azalea-nbt = {path = "../azalea-nbt", version = "^0.2.0" } -azalea-protocol-macros = {path = "./azalea-protocol-macros", version = "^0.2.0" } -azalea-registry = {path = "../azalea-registry", version = "^0.2.0" } -azalea-world = {path = "../azalea-world", version = "^0.2.0" } +azalea-auth = {path = "../azalea-auth", version = "^0.3.0" } +azalea-block = {path = "../azalea-block", default-features = false, version = "^0.3.0" } +azalea-brigadier = {path = "../azalea-brigadier", version = "^0.3.0" } +azalea-buf = {path = "../azalea-buf", version = "^0.3.0" } +azalea-chat = {path = "../azalea-chat", version = "^0.3.0" } +azalea-core = {path = "../azalea-core", optional = true, version = "^0.3.0" } +azalea-crypto = {path = "../azalea-crypto", version = "^0.3.0" } +azalea-nbt = {path = "../azalea-nbt", version = "^0.3.0" } +azalea-protocol-macros = {path = "./azalea-protocol-macros", version = "^0.3.0" } +azalea-registry = {path = "../azalea-registry", version = "^0.3.0" } +azalea-world = {path = "../azalea-world", version = "^0.3.0" } byteorder = "^1.4.3" bytes = "^1.1.0" flate2 = "1.0.23" diff --git a/azalea-protocol/azalea-protocol-macros/Cargo.toml b/azalea-protocol/azalea-protocol-macros/Cargo.toml index 7b1e200f..b3a16b16 100755 --- a/azalea-protocol/azalea-protocol-macros/Cargo.toml +++ b/azalea-protocol/azalea-protocol-macros/Cargo.toml @@ -3,7 +3,8 @@ description = "Macros internally used in azalea-protocol." edition = "2021" license = "MIT" name = "azalea-protocol-macros" -version = "0.2.0" +version = "0.3.0" +repository = "https://github.com/mat-1/azalea/tree/main/azalea-protocol/azalea-protocol-macros" [lib] proc-macro = true diff --git a/azalea-protocol/src/connect.rs b/azalea-protocol/src/connect.rs index 06aedef9..c0c1a622 100755 --- a/azalea-protocol/src/connect.rs +++ b/azalea-protocol/src/connect.rs @@ -55,26 +55,24 @@ pub struct WriteConnection { /// hostname: address.host.to_string(), /// port: address.port, /// intention: ConnectionProtocol::Login, -/// } -/// .get(), -/// ) -/// .await?; -/// let mut conn = conn.login(); +/// }.get()); /// -/// // login -/// conn.write( -/// ServerboundHelloPacket { -/// username, -/// public_key: None, -/// profile_id: None, -/// } -/// .get(), -/// ) -/// .await?; +/// .await?; +/// let mut conn = conn.login(); /// -/// let (conn, game_profile) = loop { -/// let packet_result = conn.read().await; -/// match packet_result { +/// // login +/// conn.write( +/// ServerboundHelloPacket { +/// username, +/// public_key: None, +/// profile_id: None, +/// } +/// .get(), +/// ) +/// .await?; +/// +/// let (conn, game_profile) = loop { +/// let packet_result = conn.read().await?; /// Ok(packet) => match packet { /// ClientboundLoginPacket::Hello(p) => { /// let e = azalea_crypto::encrypt(&p.public_key, &p.nonce).unwrap(); @@ -87,7 +85,8 @@ pub struct WriteConnection { /// .get(), /// ) /// .await?; -/// conn.set_encryption_key(e.secret_key); } +/// conn.set_encryption_key(e.secret_key); +/// } /// ClientboundLoginPacket::LoginCompression(p) => { /// conn.set_compression_threshold(p.compression_threshold); /// } diff --git a/azalea-protocol/src/lib.rs b/azalea-protocol/src/lib.rs index ab447210..84306142 100755 --- a/azalea-protocol/src/lib.rs +++ b/azalea-protocol/src/lib.rs @@ -3,6 +3,9 @@ //! You should probably use [`azalea`] or [`azalea_client`] instead, as //! azalea_protocol delegates much of the work, such as auth, to the user of //! the crate. +//! +//! [`azalea`]: https://crates.io/crates/azalea +//! [`azalea_client`]: https://crates.io/crates/azalea-client // these two are necessary for thiserror backtraces #![feature(error_generic_member_access)] diff --git a/azalea-protocol/src/packets/game/clientbound_boss_event_packet.rs b/azalea-protocol/src/packets/game/clientbound_boss_event_packet.rs index 3bcf10d2..59378d3e 100755 --- a/azalea-protocol/src/packets/game/clientbound_boss_event_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_boss_event_packet.rs @@ -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; diff --git a/azalea-protocol/src/packets/game/clientbound_chat_preview_packet.rs b/azalea-protocol/src/packets/game/clientbound_chat_preview_packet.rs index f6343f73..5a72ae33 100755 --- a/azalea-protocol/src/packets/game/clientbound_chat_preview_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_chat_preview_packet.rs @@ -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)] diff --git a/azalea-protocol/src/packets/game/clientbound_container_close_packet.rs b/azalea-protocol/src/packets/game/clientbound_container_close_packet.rs new file mode 100644 index 00000000..a59da450 --- /dev/null +++ b/azalea-protocol/src/packets/game/clientbound_container_close_packet.rs @@ -0,0 +1,7 @@ +use azalea_buf::McBuf; +use azalea_protocol_macros::ClientboundGamePacket; + +#[derive(Clone, Debug, McBuf, ClientboundGamePacket)] +pub struct ClientboundContainerClosePacket { + pub container_id: u8, +} diff --git a/azalea-protocol/src/packets/game/clientbound_disconnect_packet.rs b/azalea-protocol/src/packets/game/clientbound_disconnect_packet.rs index bc4b83cb..ecff0278 100755 --- a/azalea-protocol/src/packets/game/clientbound_disconnect_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_disconnect_packet.rs @@ -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)] diff --git a/azalea-protocol/src/packets/game/clientbound_map_item_data_packet.rs b/azalea-protocol/src/packets/game/clientbound_map_item_data_packet.rs index 4ce71a12..07e49687 100755 --- a/azalea-protocol/src/packets/game/clientbound_map_item_data_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_map_item_data_packet.rs @@ -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}; diff --git a/azalea-protocol/src/packets/game/clientbound_open_screen_packet.rs b/azalea-protocol/src/packets/game/clientbound_open_screen_packet.rs index 521975af..f127f587 100755 --- a/azalea-protocol/src/packets/game/clientbound_open_screen_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_open_screen_packet.rs @@ -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)] diff --git a/azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs b/azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs index 3f75e74b..fedc81df 100755 --- a/azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs @@ -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}; diff --git a/azalea-protocol/src/packets/game/clientbound_player_combat_end_packet.rs b/azalea-protocol/src/packets/game/clientbound_player_combat_end_packet.rs index 0276d379..67d29e93 100755 --- a/azalea-protocol/src/packets/game/clientbound_player_combat_end_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_player_combat_end_packet.rs @@ -1,6 +1,7 @@ use azalea_buf::McBuf; use azalea_protocol_macros::ClientboundGamePacket; +/// Unused in vanilla. #[derive(Clone, Debug, McBuf, ClientboundGamePacket)] pub struct ClientboundPlayerCombatEndPacket { #[var] diff --git a/azalea-protocol/src/packets/game/clientbound_player_combat_enter_packet.rs b/azalea-protocol/src/packets/game/clientbound_player_combat_enter_packet.rs index 8e7ef8a2..42ee1838 100755 --- a/azalea-protocol/src/packets/game/clientbound_player_combat_enter_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_player_combat_enter_packet.rs @@ -1,5 +1,6 @@ use azalea_buf::McBuf; use azalea_protocol_macros::ClientboundGamePacket; +/// Unused in vanilla. #[derive(Clone, Debug, McBuf, ClientboundGamePacket)] pub struct ClientboundPlayerCombatEnterPacket {} diff --git a/azalea-protocol/src/packets/game/clientbound_player_combat_kill_packet.rs b/azalea-protocol/src/packets/game/clientbound_player_combat_kill_packet.rs index 0492d16a..fa547af1 100755 --- a/azalea-protocol/src/packets/game/clientbound_player_combat_kill_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_player_combat_kill_packet.rs @@ -1,7 +1,8 @@ use azalea_buf::McBuf; -use azalea_chat::component::Component; +use azalea_chat::Component; use azalea_protocol_macros::ClientboundGamePacket; +/// Used to send a respawn screen. #[derive(Clone, Debug, McBuf, ClientboundGamePacket)] pub struct ClientboundPlayerCombatKillPacket { #[var] diff --git a/azalea-protocol/src/packets/game/clientbound_player_info_packet.rs b/azalea-protocol/src/packets/game/clientbound_player_info_packet.rs index 885148a5..84218842 100755 --- a/azalea-protocol/src/packets/game/clientbound_player_info_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_player_info_packet.rs @@ -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; diff --git a/azalea-protocol/src/packets/game/clientbound_resource_pack_packet.rs b/azalea-protocol/src/packets/game/clientbound_resource_pack_packet.rs index e31ebaa4..73ade728 100755 --- a/azalea-protocol/src/packets/game/clientbound_resource_pack_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_resource_pack_packet.rs @@ -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)] diff --git a/azalea-protocol/src/packets/game/clientbound_server_data_packet.rs b/azalea-protocol/src/packets/game/clientbound_server_data_packet.rs index b1147305..2305cf32 100755 --- a/azalea-protocol/src/packets/game/clientbound_server_data_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_server_data_packet.rs @@ -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)] diff --git a/azalea-protocol/src/packets/game/clientbound_set_action_bar_text_packet.rs b/azalea-protocol/src/packets/game/clientbound_set_action_bar_text_packet.rs index aefe072f..e279e33c 100755 --- a/azalea-protocol/src/packets/game/clientbound_set_action_bar_text_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_set_action_bar_text_packet.rs @@ -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)] diff --git a/azalea-protocol/src/packets/game/clientbound_set_objective_packet.rs b/azalea-protocol/src/packets/game/clientbound_set_objective_packet.rs index 0e7e334d..ad75a1c3 100755 --- a/azalea-protocol/src/packets/game/clientbound_set_objective_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_set_objective_packet.rs @@ -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}; diff --git a/azalea-protocol/src/packets/game/clientbound_set_player_team_packet.rs b/azalea-protocol/src/packets/game/clientbound_set_player_team_packet.rs index a0754ddd..2550a98c 100755 --- a/azalea-protocol/src/packets/game/clientbound_set_player_team_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_set_player_team_packet.rs @@ -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}; diff --git a/azalea-protocol/src/packets/game/clientbound_set_subtitle_text_packet.rs b/azalea-protocol/src/packets/game/clientbound_set_subtitle_text_packet.rs index d1a3b281..b7d1e7a4 100755 --- a/azalea-protocol/src/packets/game/clientbound_set_subtitle_text_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_set_subtitle_text_packet.rs @@ -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)] diff --git a/azalea-protocol/src/packets/game/clientbound_set_title_text_packet.rs b/azalea-protocol/src/packets/game/clientbound_set_title_text_packet.rs index c6e5f0e8..a9185e1a 100755 --- a/azalea-protocol/src/packets/game/clientbound_set_title_text_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_set_title_text_packet.rs @@ -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)] diff --git a/azalea-protocol/src/packets/game/clientbound_system_chat_packet.rs b/azalea-protocol/src/packets/game/clientbound_system_chat_packet.rs index 4e5222b7..a3319721 100755 --- a/azalea-protocol/src/packets/game/clientbound_system_chat_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_system_chat_packet.rs @@ -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)] diff --git a/azalea-protocol/src/packets/game/clientbound_tab_list_packet.rs b/azalea-protocol/src/packets/game/clientbound_tab_list_packet.rs index 49f357b2..94f23241 100755 --- a/azalea-protocol/src/packets/game/clientbound_tab_list_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_tab_list_packet.rs @@ -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)] diff --git a/azalea-protocol/src/packets/game/clientbound_update_advancements_packet.rs b/azalea-protocol/src/packets/game/clientbound_update_advancements_packet.rs index eb52e133..5f63dd1a 100755 --- a/azalea-protocol/src/packets/game/clientbound_update_advancements_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_update_advancements_packet.rs @@ -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; diff --git a/azalea-protocol/src/packets/game/mod.rs b/azalea-protocol/src/packets/game/mod.rs index c23e426e..54247202 100755 --- a/azalea-protocol/src/packets/game/mod.rs +++ b/azalea-protocol/src/packets/game/mod.rs @@ -13,6 +13,7 @@ pub mod clientbound_change_difficulty_packet; pub mod clientbound_chat_preview_packet; pub mod clientbound_command_suggestions_packet; pub mod clientbound_commands_packet; +pub mod clientbound_container_close_packet; pub mod clientbound_container_set_content_packet; pub mod clientbound_container_set_data_packet; pub mod clientbound_container_set_slot_packet; @@ -229,6 +230,7 @@ declare_state_packets!( 0x0c: clientbound_chat_preview_packet::ClientboundChatPreviewPacket, 0x0e: clientbound_command_suggestions_packet::ClientboundCommandSuggestionsPacket, 0x0f: clientbound_commands_packet::ClientboundCommandsPacket, + 0x10: clientbound_container_close_packet::ClientboundContainerClosePacket, 0x11: clientbound_container_set_content_packet::ClientboundContainerSetContentPacket, 0x12: clientbound_container_set_data_packet::ClientboundContainerSetDataPacket, 0x13: clientbound_container_set_slot_packet::ClientboundContainerSetSlotPacket, diff --git a/azalea-protocol/src/packets/login/clientbound_login_disconnect_packet.rs b/azalea-protocol/src/packets/login/clientbound_login_disconnect_packet.rs index 2b8144ef..983dc31b 100755 --- a/azalea-protocol/src/packets/login/clientbound_login_disconnect_packet.rs +++ b/azalea-protocol/src/packets/login/clientbound_login_disconnect_packet.rs @@ -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)] diff --git a/azalea-protocol/src/packets/status/clientbound_status_response_packet.rs b/azalea-protocol/src/packets/status/clientbound_status_response_packet.rs index f8b46b8d..64ea14f9 100755 --- a/azalea-protocol/src/packets/status/clientbound_status_response_packet.rs +++ b/azalea-protocol/src/packets/status/clientbound_status_response_packet.rs @@ -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; diff --git a/azalea-registry/Cargo.toml b/azalea-registry/Cargo.toml index 82be0bb2..6c742c0a 100755 --- a/azalea-registry/Cargo.toml +++ b/azalea-registry/Cargo.toml @@ -3,10 +3,11 @@ description = "Use Minecraft's registries." edition = "2021" license = "MIT" name = "azalea-registry" -version = "0.2.0" +version = "0.3.0" +repository = "https://github.com/mat-1/azalea/tree/main/azalea-registry" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -azalea-buf = {path = "../azalea-buf", version = "^0.2.0" } -azalea-registry-macros = {path = "./azalea-registry-macros", version = "^0.2.0" } +azalea-buf = {path = "../azalea-buf", version = "^0.3.0" } +azalea-registry-macros = {path = "./azalea-registry-macros", version = "^0.3.0" } diff --git a/azalea-registry/azalea-registry-macros/Cargo.toml b/azalea-registry/azalea-registry-macros/Cargo.toml index a068158f..353183f0 100755 --- a/azalea-registry/azalea-registry-macros/Cargo.toml +++ b/azalea-registry/azalea-registry-macros/Cargo.toml @@ -3,7 +3,8 @@ description = "Macros internally used in azalea-registry." edition = "2021" license = "MIT" name = "azalea-registry-macros" -version = "0.2.0" +repository = "https://github.com/mat-1/azalea/tree/main/azalea-registry/azalea-registry-macros" +version = "0.3.0" [lib] proc-macro = true diff --git a/azalea-world/Cargo.toml b/azalea-world/Cargo.toml index fd42e621..058feca1 100755 --- a/azalea-world/Cargo.toml +++ b/azalea-world/Cargo.toml @@ -3,17 +3,18 @@ description = "The Minecraft world representation used in Azalea." edition = "2021" license = "MIT" name = "azalea-world" -version = "0.2.0" +repository = "https://github.com/mat-1/azalea/tree/main/azalea-world" +version = "0.3.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -azalea-block = {path = "../azalea-block", default-features = false, version = "^0.2.0" } -azalea-buf = {path = "../azalea-buf", version = "^0.2.0" } -azalea-chat = {path = "../azalea-chat", version = "^0.2.0" } -azalea-core = {path = "../azalea-core", version = "^0.2.0" } -azalea-nbt = {path = "../azalea-nbt", version = "^0.2.0" } -azalea-registry = {path = "../azalea-registry", version = "^0.2.0" } +azalea-block = {path = "../azalea-block", default-features = false, version = "^0.3.0" } +azalea-buf = {path = "../azalea-buf", version = "^0.3.0" } +azalea-chat = {path = "../azalea-chat", version = "^0.3.0" } +azalea-core = {path = "../azalea-core", version = "^0.3.0" } +azalea-nbt = {path = "../azalea-nbt", version = "^0.3.0" } +azalea-registry = {path = "../azalea-registry", version = "^0.3.0" } log = "0.4.17" nohash-hasher = "0.2.0" thiserror = "1.0.34" diff --git a/azalea-world/src/entity/data.rs b/azalea-world/src/entity/data.rs index 0f90c790..c73a84d6 100755 --- a/azalea-world/src/entity/data.rs +++ b/azalea-world/src/entity/data.rs @@ -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; diff --git a/azalea/Cargo.toml b/azalea/Cargo.toml index f45f283d..9b65daff 100755 --- a/azalea/Cargo.toml +++ b/azalea/Cargo.toml @@ -3,16 +3,17 @@ description = "A framework for creating Minecraft bots." edition = "2021" license = "MIT" name = "azalea" -version = "0.2.4" +repository = "https://github.com/mat-1/azalea/tree/main/azalea" +version = "0.3.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] anyhow = "^1.0.65" async-trait = "^0.1.57" -azalea-client = { version = "0.2.2", path = "../azalea-client" } -azalea-protocol = { version = "0.2.0", path = "../azalea-protocol" } -azalea-core = { version = "0.2.0", path = "../azalea-core" } +azalea-client = { version = "0.3.0", path = "../azalea-client" } +azalea-protocol = { version = "0.3.0", path = "../azalea-protocol" } +azalea-core = { version = "0.3.0", path = "../azalea-core" } parking_lot = "^0.12.1" thiserror = "^1.0.37" tokio = "^1.21.1" diff --git a/azalea/src/lib.rs b/azalea/src/lib.rs index a7d0791a..4a042b79 100755 --- a/azalea/src/lib.rs +++ b/azalea/src/lib.rs @@ -5,6 +5,17 @@ //! refer to `azalea_client`. You can just replace these with `azalea` in your //! code, since everything from azalea_client is re-exported in azalea. //! +//! # Installation +//! +//! First, install Rust nightly with `rustup install nightly` and `rustup +//! default nightly`. +//! +//! Then, add one of the following lines to your Cargo.toml.\ +//! Latest bleeding-edge version: +//! `azalea = { git="https://github.com/mat-1/Cargo.toml" }` +//! Latest "stable" release: +//! `azalea = "0.3"` +//! //! # Examples //! //! ```rust,no_run @@ -94,8 +105,10 @@ where /// The address of the server that we're connecting to. This can be a /// `&str`, [`ServerAddress`], or anything that implements /// `TryInto`. + /// + /// [`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 +129,16 @@ where /// ``` pub state: S, /// The function that's called whenever we get an event. + /// + /// # Examples + /// + /// ```rust + /// use azalea::prelude::*; + /// + /// async fn handle(bot: Client, event: Event, state: State) -> anyhow::Result<()> { + /// Ok(()) + /// } + /// ``` pub handle: HandleFn, } @@ -123,6 +146,8 @@ where pub enum Error { #[error("Invalid address")] InvalidAddress, + #[error("Join error: {0}")] + Join(#[from] azalea_client::JoinError), } /// Join a server and start handling events. This function will run forever until @@ -151,7 +176,7 @@ pub async fn start< Err(_) => return Err(Error::InvalidAddress), }; - let (bot, mut rx) = Client::join(&options.account, address).await.unwrap(); + let (bot, mut rx) = Client::join(&options.account, address).await?; let state = options.state; let bot_plugin = bot::Plugin::default(); diff --git a/codegen/lib/code/utils.py b/codegen/lib/code/utils.py index 635dff0b..66b18eed 100755 --- a/codegen/lib/code/utils.py +++ b/codegen/lib/code/utils.py @@ -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')