1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 14:26:04 +00:00

put something useful in state

This commit is contained in:
mat 2022-04-30 22:30:50 -05:00
parent 3c3deb625d
commit 0dc6decf7f
5 changed files with 27 additions and 5 deletions

View file

@ -15,6 +15,8 @@ use std::sync::Arc;
use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender}; use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender};
use tokio::sync::Mutex; use tokio::sync::Mutex;
use crate::Player;
///! Connect to Minecraft servers. ///! Connect to Minecraft servers.
/// Something that can join Minecraft servers. /// Something that can join Minecraft servers.
@ -22,9 +24,10 @@ pub struct Account {
username: String, username: String,
} }
#[derive(Default)]
pub struct ClientState { pub struct ClientState {
// placeholder // placeholder
pub health: u16, pub player: Player,
} }
/// A player that you can control that is currently in a Minecraft server. /// A player that you can control that is currently in a Minecraft server.
@ -121,7 +124,7 @@ impl Client {
let client = Client { let client = Client {
event_receiver: rx, event_receiver: rx,
conn: conn.clone(), conn: conn.clone(),
state: Arc::new(Mutex::new(ClientState { health: 20 })), state: Arc::new(Mutex::new(ClientState::default())),
}; };
// let client = Arc::new(Mutex::new(client)); // let client = Arc::new(Mutex::new(client));
// let weak_client = Arc::<_>::downgrade(&client); // let weak_client = Arc::<_>::downgrade(&client);
@ -161,6 +164,9 @@ impl Client {
match packet { match packet {
GamePacket::ClientboundLoginPacket(p) => { GamePacket::ClientboundLoginPacket(p) => {
println!("Got login packet {:?}", p); println!("Got login packet {:?}", p);
state.lock().await.player.entity.id = p.player_id;
tx.send(Event::Login).unwrap(); tx.send(Event::Login).unwrap();
} }
GamePacket::ClientboundUpdateViewDistancePacket(p) => { GamePacket::ClientboundUpdateViewDistancePacket(p) => {
@ -212,8 +218,8 @@ impl Client {
GamePacket::ClientboundLightUpdatePacket(p) => { GamePacket::ClientboundLightUpdatePacket(p) => {
println!("Got light update packet {:?}", p); println!("Got light update packet {:?}", p);
} }
GamePacket::ClientboundAddEntityPacket(p) => { GamePacket::ClientboundAddMobPacket(p) => {
println!("Got add entity packet {:?}", p); println!("Got add mob packet {:?}", p);
} }
} }
println!(); println!();

View file

@ -0,0 +1,5 @@
#[derive(Default)]
pub struct Entity {
/// The incremental numerical id of the entity.
pub id: u32,
}

View file

@ -1,9 +1,13 @@
//! Significantly abstract azalea-protocol so it's actually useable for bots. //! Significantly abstract azalea-protocol so it's actually useable for bots.
mod connect; mod connect;
mod entity;
pub mod ping; pub mod ping;
mod player;
pub use connect::{Account, Client, Event}; pub use connect::{Account, Client, Event};
pub use entity::Entity;
pub use player::Player;
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {

View file

@ -0,0 +1,7 @@
use crate::Entity;
#[derive(Default)]
pub struct Player {
/// The entity attached to the player. There's some useful fields here.
pub entity: Entity,
}

View file

@ -3,7 +3,7 @@ use packet_macros::GamePacket;
#[derive(Clone, Debug, GamePacket)] #[derive(Clone, Debug, GamePacket)]
pub struct ClientboundLoginPacket { pub struct ClientboundLoginPacket {
pub player_id: i32, pub player_id: u32,
pub hardcore: bool, pub hardcore: bool,
pub game_type: GameType, pub game_type: GameType,
pub previous_game_type: Option<GameType>, pub previous_game_type: Option<GameType>,