diff options
| author | mat <git@matdoes.dev> | 2025-06-17 09:30:09 +1200 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-06-16 21:31:04 +0000 |
| commit | fd9bf168716f195e7e6225b93dfb099aa01b1fde (patch) | |
| tree | e617f464e2df32cbc8678b56c5c1df8cae1c4dcb /azalea/examples/testbot | |
| parent | 713dae7110ad4119469323b87fd95a7f2a544ed0 (diff) | |
| download | azalea-drasl-fd9bf168716f195e7e6225b93dfb099aa01b1fde.tar.xz | |
implement EntityHitResult
Diffstat (limited to 'azalea/examples/testbot')
| -rw-r--r-- | azalea/examples/testbot/commands/debug.rs | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/azalea/examples/testbot/commands/debug.rs b/azalea/examples/testbot/commands/debug.rs index ea5dbe6f..d721fddc 100644 --- a/azalea/examples/testbot/commands/debug.rs +++ b/azalea/examples/testbot/commands/debug.rs @@ -7,11 +7,13 @@ use azalea::{ brigadier::prelude::*, chunks::ReceiveChunkEvent, entity::{LookDirection, Position}, - interact::HitResultComponent, + interact::pick::HitResultComponent, packet::game, pathfinder::{ExecutingPath, Pathfinder}, world::MinecraftEntityId, }; +use azalea_core::hit_result::HitResult; +use azalea_entity::EntityKindComponent; use azalea_world::InstanceContainer; use bevy_ecs::event::Events; use parking_lot::Mutex; @@ -104,15 +106,24 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) { let hit_result = source.bot.component::<HitResultComponent>(); - let Some(hit_result) = hit_result.as_block_hit_result_if_not_miss() else { - source.reply("I'm not looking at anything"); - return 1; - }; - - let block_pos = hit_result.block_pos; - let block = source.bot.world().read().get_block_state(block_pos); - - source.reply(&format!("I'm looking at {block:?} at {block_pos:?}")); + match &*hit_result { + HitResult::Block(r) => { + if r.miss { + source.reply("I'm not looking at anything"); + return 0; + } + let block_pos = r.block_pos; + let block = source.bot.world().read().get_block_state(block_pos); + source.reply(&format!("I'm looking at {block:?} at {block_pos:?}")); + } + HitResult::Entity(r) => { + let entity_kind = *source.bot.entity_component::<EntityKindComponent>(r.entity); + source.reply(&format!( + "I'm looking at {entity_kind} ({:?}) at {}", + r.entity, r.location + )); + } + } 1 })); |
