diff options
| author | mat <git@matdoes.dev> | 2025-09-27 18:41:36 -1030 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-09-27 20:26:41 -0845 |
| commit | 74dcb7b37d953ec4d45dd6aac4c8e598c87def7d (patch) | |
| tree | 22e6ab1849ee01d40f3d484ea0c8db52aa6649b5 /azalea-client | |
| parent | 63bef6486dc1f3c9ef4b4f0d71e139d7035b6432 (diff) | |
| download | azalea-drasl-74dcb7b37d953ec4d45dd6aac4c8e598c87def7d.tar.xz | |
allow picking other bots in hit results
Diffstat (limited to 'azalea-client')
| -rw-r--r-- | azalea-client/src/plugins/interact/mod.rs | 8 | ||||
| -rw-r--r-- | azalea-client/src/plugins/interact/pick.rs | 25 | ||||
| -rw-r--r-- | azalea-client/src/plugins/movement.rs | 17 |
3 files changed, 29 insertions, 21 deletions
diff --git a/azalea-client/src/plugins/interact/mod.rs b/azalea-client/src/plugins/interact/mod.rs index 547d58ff..dc60ef66 100644 --- a/azalea-client/src/plugins/interact/mod.rs +++ b/azalea-client/src/plugins/interact/mod.rs @@ -18,7 +18,9 @@ use azalea_entity::{ clamp_look_direction, }; use azalea_inventory::{ItemStack, ItemStackData, components}; -use azalea_physics::{PhysicsSet, local_player::PhysicsState}; +use azalea_physics::{ + PhysicsSet, collision::entity_collisions::update_last_bounding_box, local_player::PhysicsState, +}; use azalea_protocol::packets::game::{ ServerboundInteract, ServerboundUseItem, s_interact::{self, InteractionHand}, @@ -58,7 +60,9 @@ impl Plugin for InteractPlugin { .in_set(UpdateAttributesSet) .chain(), handle_start_use_item_event, - update_hit_result_component.after(clamp_look_direction), + update_hit_result_component + .after(clamp_look_direction) + .after(update_last_bounding_box), handle_swing_arm_event, ) .after(InventorySet) diff --git a/azalea-client/src/plugins/interact/pick.rs b/azalea-client/src/plugins/interact/pick.rs index ae6c9502..580bb50c 100644 --- a/azalea-client/src/plugins/interact/pick.rs +++ b/azalea-client/src/plugins/interact/pick.rs @@ -1,5 +1,5 @@ use azalea_core::{ - aabb::AABB, + aabb::Aabb, direction::Direction, hit_result::{BlockHitResult, EntityHitResult, HitResult}, position::Vec3, @@ -15,7 +15,7 @@ use azalea_entity::{ }; use azalea_physics::{ clip::{BlockShapeType, ClipContext, FluidPickType}, - collision::entity_collisions::{PhysicsQuery, get_entities}, + collision::entity_collisions::{AabbQuery, get_entities}, }; use azalea_world::{Instance, InstanceContainer, InstanceName}; use bevy_ecs::prelude::*; @@ -44,7 +44,7 @@ pub fn update_hit_result_component( With<LocalEntity>, >, instance_container: Res<InstanceContainer>, - physics_query: PhysicsQuery, + aabb_query: AabbQuery, pickable_query: MaybePickableEntityQuery, ) { for ( @@ -76,7 +76,7 @@ pub fn update_hit_result_component( world: &world, entity_pick_range, block_pick_range, - physics_query: &physics_query, + aabb_query: &aabb_query, pickable_query: &pickable_query, }); if let Some(mut hit_result_ref) = hit_result_ref { @@ -109,7 +109,6 @@ pub type MaybePickableEntityQuery<'world, 'state, 'a> = Query< (With<AbstractLiving>, Without<Dead>), With<AbstractArrow>, )>, - Without<LocalEntity>, ), >; @@ -117,11 +116,11 @@ pub struct PickOpts<'world, 'state, 'a, 'b, 'c> { source_entity: Entity, look_direction: LookDirection, eye_position: Vec3, - aabb: &'a AABB, + aabb: &'a Aabb, world: &'a Instance, entity_pick_range: f64, block_pick_range: f64, - physics_query: &'a PhysicsQuery<'world, 'state, 'b>, + aabb_query: &'a AabbQuery<'world, 'state, 'b>, pickable_query: &'a MaybePickableEntityQuery<'world, 'state, 'c>, } @@ -163,6 +162,10 @@ pub fn pick(opts: PickOpts<'_, '_, '_, '_, '_>) -> HitResult { .inflate_all(inflate_by); let is_pickable = |entity: Entity| { + if entity == opts.source_entity { + return false; + } + // TODO: ender dragon has extra logic here. also, we shouldn't be able to pick // spectators. if let Ok((armor_stand_marker, arrow_in_ground)) = opts.pickable_query.get(entity) { @@ -180,7 +183,7 @@ pub fn pick(opts: PickOpts<'_, '_, '_, '_, '_>) -> HitResult { pick_range_squared: max_range_squared, predicate: &is_pickable, aabb: &pick_aabb, - physics_query: opts.physics_query, + aabb_query: opts.aabb_query, }); if let Some(entity_hit_result) = entity_hit_result @@ -246,8 +249,8 @@ struct PickEntityOpts<'world, 'state, 'a, 'b> { world: &'a azalea_world::Instance, pick_range_squared: f64, predicate: &'a dyn Fn(Entity) -> bool, - aabb: &'a AABB, - physics_query: &'a PhysicsQuery<'world, 'state, 'b>, + aabb: &'a Aabb, + aabb_query: &'a AabbQuery<'world, 'state, 'b>, } // port of getEntityHitResult @@ -260,7 +263,7 @@ fn pick_entity(opts: PickEntityOpts) -> Option<EntityHitResult> { Some(opts.source_entity), opts.aabb, opts.predicate, - opts.physics_query, + opts.aabb_query, ) { // TODO: if the entity is "REDIRECTABLE_PROJECTILE" then this should be 1.0. // azalea needs support for entity tags first for this to be possible. see diff --git a/azalea-client/src/plugins/movement.rs b/azalea-client/src/plugins/movement.rs index ad6779fa..48e7ecea 100644 --- a/azalea-client/src/plugins/movement.rs +++ b/azalea-client/src/plugins/movement.rs @@ -14,7 +14,7 @@ use azalea_entity::{ }; use azalea_physics::{ PhysicsSet, ai_step, - collision::entity_collisions::{CollidableEntityQuery, PhysicsQuery}, + collision::entity_collisions::{AabbQuery, CollidableEntityQuery, update_last_bounding_box}, local_player::{PhysicsState, SprintDirection, WalkDirection}, travel::{no_collision, travel}, }; @@ -73,7 +73,8 @@ impl Plugin for MovementPlugin { (handle_sprint, handle_walk, handle_knockback) .chain() .in_set(MoveEventsSet) - .after(update_bounding_box), + .after(update_bounding_box) + .after(update_last_bounding_box), ) .add_systems( GameTick, @@ -378,7 +379,7 @@ pub fn local_player_ai_step( ), (With<HasClientLoaded>, With<LocalEntity>), >, - physics_query: PhysicsQuery, + aabb_query: AabbQuery, collidable_entity_query: CollidableEntityQuery, ) { for ( @@ -409,7 +410,7 @@ pub fn local_player_ai_step( world: &world, entity, position: *position, - physics_query: &physics_query, + aabb_query: &aabb_query, collidable_entity_query: &collidable_entity_query, physics: &physics, }; @@ -708,7 +709,7 @@ pub fn update_pose( &InstanceHolder, &Position, )>, - physics_query: PhysicsQuery, + aabb_query: AabbQuery, collidable_entity_query: CollidableEntityQuery, ) { for (entity, mut pose, physics, physics_state, game_mode, instance_holder, position) in @@ -720,7 +721,7 @@ pub fn update_pose( world, entity, position: *position, - physics_query: &physics_query, + aabb_query: &aabb_query, collidable_entity_query: &collidable_entity_query, physics, }; @@ -763,7 +764,7 @@ struct CanPlayerFitCtx<'world, 'state, 'a, 'b> { world: &'a Instance, entity: Entity, position: Position, - physics_query: &'a PhysicsQuery<'world, 'state, 'b>, + aabb_query: &'a AabbQuery<'world, 'state, 'b>, collidable_entity_query: &'a CollidableEntityQuery<'world, 'state>, physics: &'a Physics, } @@ -773,7 +774,7 @@ fn can_player_fit_within_blocks_and_entities_when(ctx: &CanPlayerFitCtx, pose: P no_collision( ctx.world, Some(ctx.entity), - ctx.physics_query, + ctx.aabb_query, ctx.collidable_entity_query, ctx.physics, &calculate_dimensions(EntityKind::Player, pose).make_bounding_box(*ctx.position), |
