diff --git a/azalea-client/src/connect.rs b/azalea-client/src/connect.rs index c8d2b158..7049ab81 100755 --- a/azalea-client/src/connect.rs +++ b/azalea-client/src/connect.rs @@ -15,6 +15,8 @@ use std::sync::Arc; use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender}; use tokio::sync::Mutex; +use crate::Player; + ///! Connect to Minecraft servers. /// Something that can join Minecraft servers. @@ -22,9 +24,10 @@ pub struct Account { username: String, } +#[derive(Default)] pub struct ClientState { // placeholder - pub health: u16, + pub player: Player, } /// A player that you can control that is currently in a Minecraft server. @@ -121,7 +124,7 @@ impl Client { let client = Client { event_receiver: rx, 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 weak_client = Arc::<_>::downgrade(&client); @@ -161,6 +164,9 @@ impl Client { match packet { GamePacket::ClientboundLoginPacket(p) => { println!("Got login packet {:?}", p); + + state.lock().await.player.entity.id = p.player_id; + tx.send(Event::Login).unwrap(); } GamePacket::ClientboundUpdateViewDistancePacket(p) => { @@ -212,8 +218,8 @@ impl Client { GamePacket::ClientboundLightUpdatePacket(p) => { println!("Got light update packet {:?}", p); } - GamePacket::ClientboundAddEntityPacket(p) => { - println!("Got add entity packet {:?}", p); + GamePacket::ClientboundAddMobPacket(p) => { + println!("Got add mob packet {:?}", p); } } println!(); diff --git a/azalea-client/src/entity.rs b/azalea-client/src/entity.rs new file mode 100644 index 00000000..ed8aa68d --- /dev/null +++ b/azalea-client/src/entity.rs @@ -0,0 +1,5 @@ +#[derive(Default)] +pub struct Entity { + /// The incremental numerical id of the entity. + pub id: u32, +} diff --git a/azalea-client/src/lib.rs b/azalea-client/src/lib.rs index c11d3517..5814687a 100755 --- a/azalea-client/src/lib.rs +++ b/azalea-client/src/lib.rs @@ -1,9 +1,13 @@ //! Significantly abstract azalea-protocol so it's actually useable for bots. mod connect; +mod entity; pub mod ping; +mod player; pub use connect::{Account, Client, Event}; +pub use entity::Entity; +pub use player::Player; #[cfg(test)] mod tests { diff --git a/azalea-client/src/player.rs b/azalea-client/src/player.rs new file mode 100644 index 00000000..fc54ff93 --- /dev/null +++ b/azalea-client/src/player.rs @@ -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, +} diff --git a/azalea-protocol/src/packets/game/clientbound_login_packet.rs b/azalea-protocol/src/packets/game/clientbound_login_packet.rs index 57869202..929b11cd 100755 --- a/azalea-protocol/src/packets/game/clientbound_login_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_login_packet.rs @@ -3,7 +3,7 @@ use packet_macros::GamePacket; #[derive(Clone, Debug, GamePacket)] pub struct ClientboundLoginPacket { - pub player_id: i32, + pub player_id: u32, pub hardcore: bool, pub game_type: GameType, pub previous_game_type: Option,