diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2025-08-14 20:40:13 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-14 20:40:13 -0500 |
| commit | e74ed047dbaf3877db4a89a2d589e992abd0bb11 (patch) | |
| tree | 0a728c8be167a1d59a5492ed9df666f41cf12e57 /azalea | |
| parent | 6695132ddb31780786c67b8b9ff5df8ab3891438 (diff) | |
| download | azalea-drasl-e74ed047dbaf3877db4a89a2d589e992abd0bb11.tar.xz | |
Sneaking (#237)
* start implementing sneaking
* fix horizontal_collision being inverted and cleanup
* clippy
* change dimensions and eye height based on pose
* proper support for automatically crouching in certain cases
* fix anticheat issues
* add line to changelog and update a comment
Diffstat (limited to 'azalea')
| -rw-r--r-- | azalea/examples/nearest_entity.rs | 11 | ||||
| -rw-r--r-- | azalea/examples/testbot/commands/debug.rs | 7 | ||||
| -rw-r--r-- | azalea/examples/testbot/commands/movement.rs | 24 | ||||
| -rw-r--r-- | azalea/src/bot.rs | 14 | ||||
| -rw-r--r-- | azalea/src/pathfinder/simulation.rs | 6 |
5 files changed, 44 insertions, 18 deletions
diff --git a/azalea/examples/nearest_entity.rs b/azalea/examples/nearest_entity.rs index 8774829e..e859751e 100644 --- a/azalea/examples/nearest_entity.rs +++ b/azalea/examples/nearest_entity.rs @@ -2,7 +2,8 @@ use azalea::{Bot, ClientBuilder, LookAtEvent, nearest_entity::EntityFinder}; use azalea_client::Account; use azalea_core::tick::GameTick; use azalea_entity::{ - EyeHeight, LocalEntity, Position, + LocalEntity, Position, + dimensions::EntityDimensions, metadata::{ItemItem, Player}, }; use bevy_app::Plugin; @@ -33,7 +34,7 @@ impl Plugin for LookAtStuffPlugin { fn look_at_everything( bots: Query<Entity, (With<LocalEntity>, With<Player>)>, entities: EntityFinder, - entity_positions: Query<(&Position, Option<&EyeHeight>)>, + entity_positions: Query<(&Position, Option<&EntityDimensions>)>, mut look_at_event: EventWriter<LookAtEvent>, ) { for bot_id in bots.iter() { @@ -41,11 +42,11 @@ fn look_at_everything( continue; }; - let (position, eye_height) = entity_positions.get(entity).unwrap(); + let (position, dimensions) = entity_positions.get(entity).unwrap(); let mut look_target = **position; - if let Some(eye_height) = eye_height { - look_target.y += **eye_height as f64; + if let Some(dimensions) = dimensions { + look_target.y += dimensions.eye_height as f64; } look_at_event.write(LookAtEvent { diff --git a/azalea/examples/testbot/commands/debug.rs b/azalea/examples/testbot/commands/debug.rs index 46f1ed33..b3a8b419 100644 --- a/azalea/examples/testbot/commands/debug.rs +++ b/azalea/examples/testbot/commands/debug.rs @@ -205,6 +205,13 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) { 1 })); + commands.register(literal("dimensions").executes(|ctx: &Ctx| { + let source = ctx.source.lock(); + let bot_dimensions = source.bot.dimensions(); + source.reply(format!("{bot_dimensions:?}")); + 1 + })); + commands.register(literal("debugecsleak").executes(|ctx: &Ctx| { let source = ctx.source.lock(); diff --git a/azalea/examples/testbot/commands/movement.rs b/azalea/examples/testbot/commands/movement.rs index 89be3d0c..a4ac787a 100644 --- a/azalea/examples/testbot/commands/movement.rs +++ b/azalea/examples/testbot/commands/movement.rs @@ -3,10 +3,11 @@ use std::time::Duration; use azalea::{ BlockPos, SprintDirection, WalkDirection, brigadier::prelude::*, - entity::{EyeHeight, Position}, + entity::Position, pathfinder::goals::{BlockPosGoal, RadiusGoal, XZGoal}, prelude::*, }; +use azalea_entity::dimensions::EntityDimensions; use parking_lot::Mutex; use super::{CommandSource, Ctx}; @@ -103,8 +104,8 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) { }; let eye_height = source .bot - .get_entity_component::<EyeHeight>(entity) - .map(|h| *h) + .get_entity_component::<EntityDimensions>(entity) + .map(|h| h.eye_height) .unwrap_or_default(); source.bot.look_at(position.up(eye_height as f64)); 1 @@ -155,7 +156,7 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) { tokio::time::sleep(Duration::from_secs_f32(seconds)).await; bot.walk(WalkDirection::None); }); - source.reply(format!("ok, spriting for {seconds} seconds")); + source.reply(format!("ok, sprinting for {seconds} seconds")); 1 })), ); @@ -200,6 +201,21 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) { })), ); + let sneak = |ctx: &Ctx| { + let source = ctx.source.lock(); + source.bot.set_crouching(!source.bot.crouching()); + source.reply("ok"); + 1 + }; + let sneak_enabled = argument("enabled", bool()).executes(|ctx: &Ctx| { + let sneaking = get_bool(ctx, "enabled").unwrap(); + let source = ctx.source.lock(); + source.bot.set_crouching(sneaking); + 1 + }); + commands.register(literal("sneak").executes(sneak).then(sneak_enabled.clone())); + commands.register(literal("crouch").executes(sneak).then(sneak_enabled)); + commands.register(literal("stop").executes(|ctx: &Ctx| { let source = ctx.source.lock(); source.bot.stop_pathfinding(); diff --git a/azalea/src/bot.rs b/azalea/src/bot.rs index 8784cb31..b037ed14 100644 --- a/azalea/src/bot.rs +++ b/azalea/src/bot.rs @@ -9,8 +9,8 @@ use azalea_core::{ tick::GameTick, }; use azalea_entity::{ - EyeHeight, Jumping, LocalEntity, LookDirection, Position, clamp_look_direction, - metadata::Player, + Jumping, LocalEntity, LookDirection, Position, clamp_look_direction, + dimensions::EntityDimensions, metadata::Player, update_dimensions, }; use azalea_physics::PhysicsSet; use bevy_app::Update; @@ -43,7 +43,9 @@ impl Plugin for BotPlugin { Update, ( insert_bot, - look_at_listener.before(clamp_look_direction), + look_at_listener + .before(clamp_look_direction) + .after(update_dimensions), jump_listener, ), ) @@ -224,12 +226,12 @@ pub struct LookAtEvent { } fn look_at_listener( mut events: EventReader<LookAtEvent>, - mut query: Query<(&Position, &EyeHeight, &mut LookDirection)>, + mut query: Query<(&Position, &EntityDimensions, &mut LookDirection)>, ) { for event in events.read() { - if let Ok((position, eye_height, mut look_direction)) = query.get_mut(event.entity) { + if let Ok((position, dimensions, mut look_direction)) = query.get_mut(event.entity) { let new_look_direction = - direction_looking_at(position.up(eye_height.into()), event.position); + direction_looking_at(position.up(dimensions.eye_height.into()), event.position); trace!("look at {} (currently at {})", event.position, **position); look_direction.update(new_look_direction); diff --git a/azalea/src/pathfinder/simulation.rs b/azalea/src/pathfinder/simulation.rs index 8f198ce8..89a8b3c4 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, default_attributes, + Attributes, LookDirection, Physics, Position, default_attributes, dimensions::EntityDimensions, }; use azalea_registry::EntityKind; use azalea_world::{ChunkStorage, Instance, InstanceContainer, MinecraftEntityId, PartialInstance}; @@ -35,7 +35,7 @@ impl SimulatedPlayerBundle { SimulatedPlayerBundle { position: Position::new(position), - physics: Physics::new(dimensions, position), + physics: Physics::new(&dimensions, position), physics_state: PhysicsState::default(), look_direction: LookDirection::default(), attributes: default_attributes(EntityKind::Player), @@ -112,7 +112,7 @@ fn create_simulation_player_complete_bundle( MineBundle::default(), BlockStatePredictionHandler::default(), azalea_client::local_player::PermissionLevel::default(), - azalea_client::local_player::PlayerAbilities::default(), + azalea_entity::PlayerAbilities::default(), ) } |
