From 061f2c4e260c641ba7917cb952dd9b93e2b19013 Mon Sep 17 00:00:00 2001 From: Lizzy Fleckenstein Date: Mon, 18 May 2026 22:57:43 +0200 Subject: add autoclick --- src/main.rs | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 6dfc127..bd9a39f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,10 @@ -use azalea::{account::yggdrasil::Backend, prelude::*}; +use azalea::{ + account::yggdrasil::Backend, + ecs::prelude::{With, Without}, + entity::{Dead, LocalEntity, Position, metadata::AbstractMonster}, + error::MissingComponentError, + prelude::*, +}; use clap::Parser; #[derive(Parser, Debug)] @@ -23,6 +29,15 @@ struct Args { /// Disable requesting signing certificates #[arg(short, long, default_value_t = false)] no_certs: bool, + + /// Enable attacking closest entity + #[arg(short, long, default_value_t = false)] + autoclick: bool, +} + +#[derive(Default, Clone, Component)] +struct State { + autoclick: bool, } #[tokio::main] @@ -46,18 +61,41 @@ async fn main() -> AppExit { ClientBuilder::new() .set_handler(handle) + .set_state(State { + autoclick: args.autoclick, + }) .start(account, args.server.as_str()) .await } -#[derive(Default, Clone, Component)] -pub struct State {} +fn autoclick(bot: Client) -> Result<(), MissingComponentError> { + let bot_position = bot.eye_position()?; + let nearest_entity = bot.nearest_entity_by::<&Position, ( + With, + Without, + Without, + )>(|position: &Position| { + let distance = bot_position.distance_to(**position); + distance < 4. + })?; -async fn handle(_bot: Client, event: Event, _state: State) -> Result<(), ()> { + if let Some(nearest_entity) = nearest_entity { + nearest_entity.attack(); + } + + Ok(()) +} + +async fn handle(bot: Client, event: Event, state: State) -> Result<(), ()> { match event { Event::Chat(m) => { println!("{}", m.message().to_ansi()); } + Event::Tick => { + if state.autoclick && !bot.has_attack_cooldown() { + autoclick(bot).ok(); + } + } _ => {} } -- cgit v1.2.3