diff --git a/azalea-client/src/account.rs b/azalea-client/src/account.rs new file mode 100644 index 00000000..00a5d0f6 --- /dev/null +++ b/azalea-client/src/account.rs @@ -0,0 +1,27 @@ +use crate::Client; +use azalea_protocol::{ + packets::game::{ + clientbound_player_chat_packet::ClientboundPlayerChatPacket, + clientbound_system_chat_packet::ClientboundSystemChatPacket, + }, + ServerAddress, +}; +use std::fmt::Debug; + +///! Connect to Minecraft servers. + +/// Something that can join Minecraft servers. +pub struct Account { + pub username: String, +} +impl Account { + pub fn offline(username: &str) -> Self { + Self { + username: username.to_string(), + } + } + + pub async fn join(&self, address: &ServerAddress) -> Result { + Client::join(self, address).await + } +} diff --git a/azalea-client/src/connect.rs b/azalea-client/src/client.rs old mode 100755 new mode 100644 similarity index 96% rename from azalea-client/src/connect.rs rename to azalea-client/src/client.rs index dd3162eb..ff8729cb --- a/azalea-client/src/connect.rs +++ b/azalea-client/src/client.rs @@ -1,5 +1,5 @@ -use crate::Player; -use azalea_core::{resource_location::ResourceLocation, ChunkPos, EntityPos}; +use crate::{Account, Player}; +use azalea_core::{resource_location::ResourceLocation, ChunkPos}; use azalea_entity::Entity; use azalea_protocol::{ connect::{GameConnection, HandshakeConnection}, @@ -25,25 +25,16 @@ use std::{fmt::Debug, sync::Arc}; use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender}; use tokio::sync::Mutex; -///! Connect to Minecraft servers. - -/// Something that can join Minecraft servers. -pub struct Account { - username: String, -} - #[derive(Default)] pub struct ClientState { pub player: Player, pub world: Option, } -/// A player that you can control that is currently in a Minecraft server. -pub struct Client { - event_receiver: UnboundedReceiver, - pub conn: Arc>, - pub state: Arc>, - // game_loop +#[derive(Debug, Clone)] +pub enum Event { + Login, + Chat(ChatPacket), } #[derive(Debug, Clone)] @@ -61,17 +52,20 @@ pub enum ChatPacket { // } // } -#[derive(Debug, Clone)] -pub enum Event { - Login, - Chat(ChatPacket), +/// A player that you can control that is currently in a Minecraft server. +pub struct Client { + event_receiver: UnboundedReceiver, + pub conn: Arc>, + pub state: Arc>, + // game_loop } /// Whether we should ignore errors when decoding packets. -const IGNORE_ERRORS: bool = false; +const IGNORE_ERRORS: bool = !cfg!(debug_assertions); impl Client { - async fn join(account: &Account, address: &ServerAddress) -> Result { + /// Connect to a Minecraft server with an account. + pub async fn join(account: &Account, address: &ServerAddress) -> Result { let resolved_address = resolver::resolve_address(address).await?; let mut conn = HandshakeConnection::new(&resolved_address).await?; @@ -469,15 +463,3 @@ impl Client { self.event_receiver.recv().await } } - -impl Account { - pub fn offline(username: &str) -> Self { - Self { - username: username.to_string(), - } - } - - pub async fn join(&self, address: &ServerAddress) -> Result { - Client::join(self, address).await - } -} diff --git a/azalea-client/src/lib.rs b/azalea-client/src/lib.rs index db935897..867f05a1 100755 --- a/azalea-client/src/lib.rs +++ b/azalea-client/src/lib.rs @@ -1,10 +1,12 @@ //! Significantly abstract azalea-protocol so it's actually useable for bots. -mod connect; +mod account; +mod client; pub mod ping; mod player; -pub use connect::{Account, Client, Event}; +pub use account::Account; +pub use client::{Client, Event}; pub use player::Player; #[cfg(test)] diff --git a/azalea-world/src/entity.rs b/azalea-world/src/entity.rs index a25b1f40..49e1ae73 100644 --- a/azalea-world/src/entity.rs +++ b/azalea-world/src/entity.rs @@ -4,6 +4,7 @@ use azalea_core::ChunkPos; use azalea_entity::Entity; use nohash_hasher::IntMap; +#[derive(Debug)] pub struct EntityStorage { by_id: IntMap, // TODO: this doesn't work yet (should be updated in the set_pos method in azalea-entity) diff --git a/bot/src/main.rs b/bot/src/main.rs index 0b9da787..bfcba7f5 100644 --- a/bot/src/main.rs +++ b/bot/src/main.rs @@ -1,5 +1,4 @@ use azalea_client::{Account, Event}; -use azalea_core::BlockPos; #[tokio::main] async fn main() { @@ -20,10 +19,10 @@ async fn main() { match e { // TODO: have a "loaded" or "ready" event that fires when all chunks are loaded Event::Login => {} - Event::Chat(p) => { + Event::Chat(_p) => { let state = client.state.lock().await; let world = state.world.as_ref().unwrap(); - println!("{:?}", state.world.entities.get_player(player)); + println!("{:?}", world.entities); // world.get_block_state(state.player.entity.pos); // println!("{}", p.message.to_ansi(None)); // if p.message.to_ansi(None) == " ok" {