diff options
| author | mat <git@matdoes.dev> | 2024-01-07 21:50:38 -0600 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2024-01-07 21:50:38 -0600 |
| commit | 0aa439d5caa8028b6d310de45258cbcef16ca2eb (patch) | |
| tree | 7c8c201935eb62196c2d57718965861724d22fe8 /azalea/examples/testbot/killaura.rs | |
| parent | 5ea127114582e3320381d09e880f6a433ccb8710 (diff) | |
| download | azalea-drasl-0aa439d5caa8028b6d310de45258cbcef16ca2eb.tar.xz | |
rewrite testbot to use brigadier
Diffstat (limited to 'azalea/examples/testbot/killaura.rs')
| -rw-r--r-- | azalea/examples/testbot/killaura.rs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/azalea/examples/testbot/killaura.rs b/azalea/examples/testbot/killaura.rs new file mode 100644 index 00000000..d86356fe --- /dev/null +++ b/azalea/examples/testbot/killaura.rs @@ -0,0 +1,48 @@ +use azalea::{ + ecs::prelude::*, + entity::{metadata::AbstractMonster, Dead, LocalEntity, Position}, + prelude::*, + world::{InstanceName, MinecraftEntityId}, +}; + +use crate::State; + +pub fn tick(mut bot: Client, state: State) -> anyhow::Result<()> { + if !state.killaura { + return Ok(()); + } + if bot.has_attack_cooldown() { + return Ok(()); + } + let mut nearest_entity = None; + let mut nearest_distance = f64::INFINITY; + let bot_position = bot.eye_position(); + let bot_instance_name = bot.component::<InstanceName>(); + { + let mut ecs = bot.ecs.lock(); + let mut query = ecs + .query_filtered::<(&MinecraftEntityId, &Position, &InstanceName), ( + With<AbstractMonster>, + Without<LocalEntity>, + Without<Dead>, + )>(); + for (&entity_id, position, instance_name) in query.iter(&ecs) { + if instance_name != &bot_instance_name { + continue; + } + + let distance = bot_position.distance_to(position); + if distance < 4. && distance < nearest_distance { + nearest_entity = Some(entity_id); + nearest_distance = distance; + } + } + } + if let Some(nearest_entity) = nearest_entity { + println!("attacking {:?}", nearest_entity); + println!("distance {:?}", nearest_distance); + bot.attack(nearest_entity); + } + + Ok(()) +} |
