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 | |
| parent | 713dae7110ad4119469323b87fd95a7f2a544ed0 (diff) | |
| download | azalea-drasl-fd9bf168716f195e7e6225b93dfb099aa01b1fde.tar.xz | |
implement EntityHitResult
Diffstat (limited to 'azalea')
| -rw-r--r-- | azalea/examples/testbot/commands/debug.rs | 31 | ||||
| -rw-r--r-- | azalea/src/pathfinder/goals.rs | 2 | ||||
| -rw-r--r-- | azalea/src/pathfinder/simulation.rs | 8 |
3 files changed, 24 insertions, 17 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 })); diff --git a/azalea/src/pathfinder/goals.rs b/azalea/src/pathfinder/goals.rs index 95786561..7a830973 100644 --- a/azalea/src/pathfinder/goals.rs +++ b/azalea/src/pathfinder/goals.rs @@ -237,7 +237,7 @@ impl Goal for ReachBlockPosGoal { let eye_position = n.center_bottom().up(1.62); let look_direction = crate::direction_looking_at(eye_position, self.pos.center()); - let block_hit_result = azalea_client::interact::pick_block( + let block_hit_result = azalea_client::interact::pick::pick_block( look_direction, eye_position, &self.chunk_storage, diff --git a/azalea/src/pathfinder/simulation.rs b/azalea/src/pathfinder/simulation.rs index 5c548aa2..7f93a671 100644 --- a/azalea/src/pathfinder/simulation.rs +++ b/azalea/src/pathfinder/simulation.rs @@ -10,7 +10,7 @@ use azalea_core::{ game_type::GameMode, position::Vec3, resource_location::ResourceLocation, tick::GameTick, }; use azalea_entity::{ - Attributes, EntityDimensions, LookDirection, Physics, Position, attributes::AttributeInstance, + Attributes, EntityDimensions, LookDirection, Physics, Position, default_attributes, }; use azalea_registry::EntityKind; use azalea_world::{ChunkStorage, Instance, InstanceContainer, MinecraftEntityId, PartialInstance}; @@ -38,11 +38,7 @@ impl SimulatedPlayerBundle { physics: Physics::new(dimensions, position), physics_state: PhysicsState::default(), look_direction: LookDirection::default(), - attributes: Attributes { - speed: AttributeInstance::new(0.1), - attack_speed: AttributeInstance::new(4.0), - water_movement_efficiency: AttributeInstance::new(0.0), - }, + attributes: default_attributes(EntityKind::Player), inventory: Inventory::default(), } } |
