diff options
| author | mat <git@matdoes.dev> | 2025-12-28 09:06:47 -0330 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-12-28 09:06:47 -0330 |
| commit | 839d536e8020b291bc1d213a5e8e823dc513a940 (patch) | |
| tree | 60cab8b908ad53af0126e2cb1dec670d073936a3 /azalea/examples | |
| parent | 5b1a78baf757897532be8c308a37c99fb2ca3352 (diff) | |
| download | azalea-drasl-839d536e8020b291bc1d213a5e8e823dc513a940.tar.xz | |
add a few more functions for getting common components to Client
Diffstat (limited to 'azalea/examples')
| -rw-r--r-- | azalea/examples/steal.rs | 4 | ||||
| -rw-r--r-- | azalea/examples/testbot/commands/debug.rs | 8 | ||||
| -rw-r--r-- | azalea/examples/testbot/killaura.rs | 33 | ||||
| -rw-r--r-- | azalea/examples/todo/craft_dig_straight_down.rs | 5 |
4 files changed, 16 insertions, 34 deletions
diff --git a/azalea/examples/steal.rs b/azalea/examples/steal.rs index 4e8c078c..b5a26423 100644 --- a/azalea/examples/steal.rs +++ b/azalea/examples/steal.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use azalea::{BlockPos, pathfinder::goals::RadiusGoal, prelude::*}; -use azalea_inventory::{ItemStack, operations::QuickMoveClick}; +use azalea_inventory::ItemStack; use azalea_registry::builtin::{BlockKind, ItemKind}; use parking_lot::Mutex; @@ -81,7 +81,7 @@ async fn steal(bot: Client, state: State) -> anyhow::Result<()> { }; if item.kind == ItemKind::Diamond { println!("clicking slot ^"); - chest.click(QuickMoveClick::Left { slot: index as u16 }); + chest.left_click(index); } } } diff --git a/azalea/examples/testbot/commands/debug.rs b/azalea/examples/testbot/commands/debug.rs index 711c3260..d75b4c0a 100644 --- a/azalea/examples/testbot/commands/debug.rs +++ b/azalea/examples/testbot/commands/debug.rs @@ -88,7 +88,7 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) { commands.register(literal("getdirection").executes(|ctx: &Ctx| { let source = ctx.source.lock(); - let direction = source.bot.component::<LookDirection>(); + let direction = source.bot.direction(); source.reply(format!( "I'm looking at {}, {}", direction.y_rot(), @@ -108,9 +108,9 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) { commands.register(literal("lookingat").executes(|ctx: &Ctx| { let source = ctx.source.lock(); - let hit_result = source.bot.component::<HitResultComponent>(); + let hit_result = source.bot.hit_result(); - match &**hit_result { + match &hit_result { HitResult::Block(r) => { if r.miss { source.reply("I'm not looking at anything"); @@ -242,7 +242,7 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) { commands.register(literal("attributes").executes(|ctx: &Ctx| { let source = ctx.source.lock(); - let attributes = source.bot.component::<Attributes>(); + let attributes = source.bot.attributes(); println!("attributes: {attributes:?}"); 1 })); diff --git a/azalea/examples/testbot/killaura.rs b/azalea/examples/testbot/killaura.rs index e3d9091c..e6eb40ba 100644 --- a/azalea/examples/testbot/killaura.rs +++ b/azalea/examples/testbot/killaura.rs @@ -2,7 +2,6 @@ use azalea::{ ecs::prelude::*, entity::{Dead, LocalEntity, Position, metadata::AbstractMonster}, prelude::*, - world::InstanceName, }; use crate::State; @@ -14,33 +13,19 @@ pub fn tick(bot: Client, state: State) -> anyhow::Result<()> { 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>().clone(); - { - let mut ecs = bot.ecs.write(); - let mut query = ecs - .query_filtered::<(Entity, &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; - } - } - } + let nearest_entity = bot.nearest_entity_by::<&Position, ( + With<AbstractMonster>, + Without<LocalEntity>, + Without<Dead>, + )>(|position: &Position| { + let distance = bot_position.distance_to(**position); + distance < 4. + }); + if let Some(nearest_entity) = nearest_entity { println!("attacking {nearest_entity:?}"); - println!("distance {nearest_distance:?}"); bot.attack(nearest_entity); } diff --git a/azalea/examples/todo/craft_dig_straight_down.rs b/azalea/examples/todo/craft_dig_straight_down.rs index 153af299..d8254aa3 100644 --- a/azalea/examples/todo/craft_dig_straight_down.rs +++ b/azalea/examples/todo/craft_dig_straight_down.rs @@ -58,10 +58,7 @@ async fn handle(bot: Client, event: Event, state: State) -> anyhow::Result<()> { bot.hold(&pickaxe); loop { - if let Err(e) = bot - .dig(azalea::entity::feet_pos(bot.entity()).down(1)) - .await - { + if let Err(e) = bot.dig(bot.entity().feet_pos().down(1)).await { println!("{e:?}"); break; } |
