aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-06-18 16:54:49 -0500
committermat <github@matdoes.dev>2022-06-18 16:54:49 -0500
commitfc3151f89db1cf018bfebebb8f102e20911e64d3 (patch)
treee04047dbcbfd9d9e8c6b7a98658ccdb4802eeabd
parente32b8fabb78a86e073c7bb3270b1bc89a532350a (diff)
downloadazalea-drasl-fc3151f89db1cf018bfebebb8f102e20911e64d3.tar.xz
account.rs and client.rs
-rw-r--r--azalea-client/src/account.rs27
-rw-r--r--[-rwxr-xr-x]azalea-client/src/client.rs (renamed from azalea-client/src/connect.rs)48
-rwxr-xr-xazalea-client/src/lib.rs6
-rw-r--r--azalea-world/src/entity.rs1
-rw-r--r--bot/src/main.rs5
5 files changed, 49 insertions, 38 deletions
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, String> {
+ Client::join(self, address).await
+ }
+}
diff --git a/azalea-client/src/connect.rs b/azalea-client/src/client.rs
index dd3162eb..ff8729cb 100755..100644
--- 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<World>,
}
-/// A player that you can control that is currently in a Minecraft server.
-pub struct Client {
- event_receiver: UnboundedReceiver<Event>,
- pub conn: Arc<Mutex<GameConnection>>,
- pub state: Arc<Mutex<ClientState>>,
- // 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<Event>,
+ pub conn: Arc<Mutex<GameConnection>>,
+ pub state: Arc<Mutex<ClientState>>,
+ // 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<Self, String> {
+ /// Connect to a Minecraft server with an account.
+ pub async fn join(account: &Account, address: &ServerAddress) -> Result<Self, String> {
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, String> {
- 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<u32, Entity>,
// 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) == "<py5> ok" {