mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
simple example for azalea-client
This commit is contained in:
parent
45fd8a0e98
commit
c0829e6d0e
5 changed files with 35 additions and 11 deletions
25
azalea-client/examples/echo.rs
Normal file
25
azalea-client/examples/echo.rs
Normal file
|
@ -0,0 +1,25 @@
|
|||
//! A simple bot that repeats chat messages sent by other players.
|
||||
|
||||
use azalea_client::{Account, Client, Event};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let account = Account::offline("bot");
|
||||
// or let account = Account::microsoft("email").await;
|
||||
|
||||
let (client, mut rx) = Client::join(&account, "localhost").await.unwrap();
|
||||
|
||||
while let Some(event) = rx.recv().await {
|
||||
match &event {
|
||||
Event::Chat(m) => {
|
||||
if let (Some(sender), content) = m.split_sender_and_content() {
|
||||
if sender == client.profile.name {
|
||||
continue; // ignore our own messages
|
||||
}
|
||||
client.chat(&content).await;
|
||||
};
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -79,6 +79,12 @@ pub enum Event {
|
|||
/// Client has the things that a user interacting with the library will want.
|
||||
/// Things that a player in the world will want to know are in [`LocalPlayer`].
|
||||
pub struct Client {
|
||||
/// The [`GameProfile`] for our client. This contains your username, UUID,
|
||||
/// and skin data.
|
||||
///
|
||||
/// This is immutable; the server cannot change it. To get the username and
|
||||
/// skin the server chose for you, get your player from
|
||||
/// [`Self::players`].
|
||||
pub profile: GameProfile,
|
||||
/// The entity for this client in the ECS.
|
||||
pub entity: Entity,
|
||||
|
|
|
@ -22,16 +22,7 @@ mod player;
|
|||
mod plugins;
|
||||
|
||||
pub use account::Account;
|
||||
pub use client::{ChatPacket, ClientInformation, Event, JoinError};
|
||||
pub use client::{ChatPacket, Client, ClientInformation, Event, JoinError};
|
||||
pub use movement::{SprintDirection, WalkDirection};
|
||||
pub use player::PlayerInfo;
|
||||
pub use plugins::{Plugin, PluginState, PluginStates, Plugins};
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn it_works() {
|
||||
let result = 2 + 2;
|
||||
assert_eq!(result, 4);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,12 +54,14 @@ pub struct PacketReceiver {
|
|||
|
||||
fn handle_packets(
|
||||
mut commands: Commands,
|
||||
|
||||
query: Query<(Entity, &PacketReceiver), Changed<PacketReceiver>>,
|
||||
local_player_query: Query<&LocalPlayer>,
|
||||
entity_kind_query: Query<&EntityKind>,
|
||||
mut mut_local_player_query: Query<&mut LocalPlayer>,
|
||||
mut mut_health_query: Query<&mut Health>,
|
||||
mut mut_position_query: Query<&mut Position>,
|
||||
|
||||
combat_kill_query: Query<(&MinecraftEntityId, Option<&Dead>)>,
|
||||
mut position_query: Query<(
|
||||
&mut LocalPlayer,
|
||||
|
@ -67,6 +69,7 @@ fn handle_packets(
|
|||
&mut Position,
|
||||
&mut LastSentPosition,
|
||||
)>,
|
||||
|
||||
mut world_container: ResMut<WorldContainer>,
|
||||
mut entity_infos: ResMut<EntityInfos>,
|
||||
) {
|
||||
|
|
|
@ -5,7 +5,6 @@ use crate::{prelude::*, SprintDirection, WalkDirection};
|
|||
use crate::{Client, Event};
|
||||
use async_trait::async_trait;
|
||||
use azalea_core::{BlockPos, CardinalDirection};
|
||||
use azalea_world::entity::EntityData;
|
||||
use log::{debug, error};
|
||||
use mtdstarlite::Edge;
|
||||
pub use mtdstarlite::MTDStarLite;
|
||||
|
|
Loading…
Add table
Reference in a new issue