diff options
| author | mat <git@matdoes.dev> | 2025-06-02 03:14:08 -0430 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-06-02 03:14:08 -0430 |
| commit | 0569862a1b1f46f1854f4eafd1569359397f2515 (patch) | |
| tree | 01f20f6b078db41d34f08d7f52000f9fb46f7c45 /azalea | |
| parent | d7cd30505954d841f05d85a4cfd74412739778dd (diff) | |
| download | azalea-drasl-0569862a1b1f46f1854f4eafd1569359397f2515.tar.xz | |
fix issues related to pathfinder mining
Diffstat (limited to 'azalea')
| -rw-r--r-- | azalea/benches/pathfinder.rs | 15 | ||||
| -rw-r--r-- | azalea/benches/physics.rs | 2 | ||||
| -rw-r--r-- | azalea/examples/testbot/commands.rs | 4 | ||||
| -rw-r--r-- | azalea/src/pathfinder/debug.rs | 2 | ||||
| -rw-r--r-- | azalea/src/pathfinder/mod.rs | 84 | ||||
| -rw-r--r-- | azalea/src/pathfinder/simulation.rs | 18 | ||||
| -rw-r--r-- | azalea/src/swarm/events.rs | 2 |
7 files changed, 96 insertions, 31 deletions
diff --git a/azalea/benches/pathfinder.rs b/azalea/benches/pathfinder.rs index bb4e312a..cddaee2c 100644 --- a/azalea/benches/pathfinder.rs +++ b/azalea/benches/pathfinder.rs @@ -4,6 +4,7 @@ use azalea::{ BlockPos, pathfinder::{ astar::{self, PathfinderTimeout, WeightedNode, a_star}, + custom_state::CustomPathfinderStateRef, goals::{BlockPosGoal, Goal}, mining::MiningCache, rel_block_pos::RelBlockPos, @@ -41,13 +42,13 @@ fn generate_bedrock_world( let mut chunk = chunk.write(); for x in 0..16_u8 { for z in 0..16_u8 { - chunk.set( + chunk.set_block_state( &ChunkBlockPos::new(x, 1, z), azalea_registry::Block::Bedrock.into(), chunks.min_y, ); if rng.gen_bool(0.5) { - chunk.set( + chunk.set_block_state( &ChunkBlockPos::new(x, 2, z), azalea_registry::Block::Bedrock.into(), chunks.min_y, @@ -99,7 +100,7 @@ fn generate_mining_world( for y in chunks.min_y..(chunks.min_y + chunks.height as i32) { for x in 0..16_u8 { for z in 0..16_u8 { - chunk.set( + chunk.set_block_state( &ChunkBlockPos::new(x, y, z), azalea_registry::Block::Stone.into(), chunks.min_y, @@ -134,7 +135,13 @@ fn run_pathfinder_benchmark( let goal = BlockPosGoal(end); let successors = |pos: RelBlockPos| { - azalea::pathfinder::call_successors_fn(&cached_world, &mining_cache, successors_fn, pos) + azalea::pathfinder::call_successors_fn( + &cached_world, + &mining_cache, + &CustomPathfinderStateRef::default(), + successors_fn, + pos, + ) }; let astar::Path { diff --git a/azalea/benches/physics.rs b/azalea/benches/physics.rs index 5eb164d7..2f122014 100644 --- a/azalea/benches/physics.rs +++ b/azalea/benches/physics.rs @@ -25,7 +25,7 @@ fn generate_world(partial_chunks: &mut PartialChunkStorage, size: u32) -> ChunkS let mut chunk = chunk.write(); for x in 0..16_u8 { for z in 0..16_u8 { - chunk.set( + chunk.set_block_state( &ChunkBlockPos::new(x, 1, z), azalea_registry::Block::OakFence.into(), chunks.min_y, diff --git a/azalea/examples/testbot/commands.rs b/azalea/examples/testbot/commands.rs index da6b7cc2..79a73bd9 100644 --- a/azalea/examples/testbot/commands.rs +++ b/azalea/examples/testbot/commands.rs @@ -3,8 +3,8 @@ pub mod debug; pub mod movement; use azalea::{ - Client, GameProfileComponent, brigadier::prelude::*, chat::ChatPacket, ecs::prelude::*, - entity::metadata::Player, + Client, brigadier::prelude::*, chat::ChatPacket, ecs::prelude::*, entity::metadata::Player, + player::GameProfileComponent, }; use parking_lot::Mutex; diff --git a/azalea/src/pathfinder/debug.rs b/azalea/src/pathfinder/debug.rs index 72423243..b00e4272 100644 --- a/azalea/src/pathfinder/debug.rs +++ b/azalea/src/pathfinder/debug.rs @@ -1,4 +1,4 @@ -use azalea_client::{InstanceHolder, chat::SendChatEvent}; +use azalea_client::{chat::SendChatEvent, local_player::InstanceHolder}; use azalea_core::position::Vec3; use bevy_ecs::prelude::*; diff --git a/azalea/src/pathfinder/mod.rs b/azalea/src/pathfinder/mod.rs index 94d5bc69..08c72f9a 100644 --- a/azalea/src/pathfinder/mod.rs +++ b/azalea/src/pathfinder/mod.rs @@ -27,9 +27,10 @@ use std::{ use astar::{Edge, PathfinderTimeout}; use azalea_client::{ - InstanceHolder, StartSprintEvent, StartWalkEvent, + StartSprintEvent, StartWalkEvent, inventory::{Inventory, InventorySet, SetSelectedHotbarSlotEvent}, - mining::{Mining, StartMiningBlockEvent}, + local_player::InstanceHolder, + mining::{Mining, MiningSet, StartMiningBlockEvent}, movement::MoveEventsSet, }; use azalea_core::{position::BlockPos, tick::GameTick}; @@ -89,7 +90,8 @@ impl Plugin for PathfinderPlugin { ) .chain() .after(PhysicsSet) - .after(azalea_client::movement::send_position), + .after(azalea_client::movement::send_position) + .after(MiningSet), ) .add_systems(PreUpdate, add_default_pathfinder) .add_systems( @@ -1271,6 +1273,7 @@ mod tests { time::{Duration, Instant}, }; + use azalea_block::BlockState; use azalea_core::position::{BlockPos, ChunkPos, Vec3}; use azalea_world::{Chunk, ChunkStorage, PartialChunkStorage}; @@ -1286,9 +1289,9 @@ mod tests { partial_chunks: &mut PartialChunkStorage, start_pos: BlockPos, end_pos: BlockPos, - solid_blocks: Vec<BlockPos>, + solid_blocks: &[BlockPos], ) -> Simulation { - let mut simulation = setup_simulation_world(partial_chunks, start_pos, solid_blocks); + let mut simulation = setup_simulation_world(partial_chunks, start_pos, solid_blocks, &[]); // you can uncomment this while debugging tests to get trace logs // simulation.app.add_plugins(bevy_log::LogPlugin { @@ -1311,10 +1314,14 @@ mod tests { fn setup_simulation_world( partial_chunks: &mut PartialChunkStorage, start_pos: BlockPos, - solid_blocks: Vec<BlockPos>, + solid_blocks: &[BlockPos], + extra_blocks: &[(BlockPos, BlockState)], ) -> Simulation { let mut chunk_positions = HashSet::new(); - for block_pos in &solid_blocks { + for block_pos in solid_blocks { + chunk_positions.insert(ChunkPos::from(block_pos)); + } + for (block_pos, _) in extra_blocks { chunk_positions.insert(ChunkPos::from(block_pos)); } @@ -1323,8 +1330,12 @@ mod tests { partial_chunks.set(&chunk_pos, Some(Chunk::default()), &mut chunks); } for block_pos in solid_blocks { - chunks.set_block_state(&block_pos, azalea_registry::Block::Stone.into()); + chunks.set_block_state(block_pos, azalea_registry::Block::Stone.into()); } + for (block_pos, block_state) in extra_blocks { + chunks.set_block_state(block_pos, *block_state); + } + let player = SimulatedPlayerBundle::new(Vec3::new( start_pos.x as f64 + 0.5, start_pos.y as f64, @@ -1360,7 +1371,7 @@ mod tests { &mut partial_chunks, BlockPos::new(0, 71, 0), BlockPos::new(0, 71, 1), - vec![BlockPos::new(0, 70, 0), BlockPos::new(0, 70, 1)], + &[BlockPos::new(0, 70, 0), BlockPos::new(0, 70, 1)], ); assert_simulation_reaches(&mut simulation, 20, BlockPos::new(0, 71, 1)); } @@ -1372,7 +1383,7 @@ mod tests { &mut partial_chunks, BlockPos::new(0, 71, 0), BlockPos::new(2, 71, 2), - vec![ + &[ BlockPos::new(0, 70, 0), BlockPos::new(1, 70, 1), BlockPos::new(2, 70, 2), @@ -1390,7 +1401,7 @@ mod tests { &mut partial_chunks, BlockPos::new(0, 71, 3), BlockPos::new(5, 76, 0), - vec![ + &[ BlockPos::new(0, 70, 3), BlockPos::new(0, 70, 2), BlockPos::new(0, 70, 1), @@ -1412,7 +1423,7 @@ mod tests { &mut partial_chunks, BlockPos::new(0, 71, 0), BlockPos::new(0, 71, 3), - vec![BlockPos::new(0, 70, 0), BlockPos::new(0, 70, 3)], + &[BlockPos::new(0, 70, 0), BlockPos::new(0, 70, 3)], ); assert_simulation_reaches(&mut simulation, 40, BlockPos::new(0, 71, 3)); } @@ -1424,7 +1435,7 @@ mod tests { &mut partial_chunks, BlockPos::new(0, 71, 0), BlockPos::new(3, 67, 4), - vec![ + &[ BlockPos::new(0, 70, 0), BlockPos::new(0, 69, 1), BlockPos::new(0, 68, 2), @@ -1443,7 +1454,7 @@ mod tests { &mut partial_chunks, BlockPos::new(0, 71, 0), BlockPos::new(0, 70, 5), - vec![ + &[ BlockPos::new(0, 70, 0), BlockPos::new(0, 70, 1), BlockPos::new(0, 69, 2), @@ -1460,7 +1471,7 @@ mod tests { &mut partial_chunks, BlockPos::new(0, 71, 0), BlockPos::new(0, 68, 3), - vec![ + &[ BlockPos::new(0, 70, 0), BlockPos::new(0, 69, 1), BlockPos::new(0, 68, 2), @@ -1477,7 +1488,7 @@ mod tests { &mut partial_chunks, BlockPos::new(0, 71, 0), BlockPos::new(3, 74, 0), - vec![ + &[ BlockPos::new(0, 70, 0), BlockPos::new(0, 71, 3), BlockPos::new(3, 72, 3), @@ -1494,7 +1505,7 @@ mod tests { &mut partial_chunks, BlockPos::new(0, 71, 0), BlockPos::new(4, 71, 12), - vec![ + &[ BlockPos::new(0, 70, 0), BlockPos::new(0, 70, 4), BlockPos::new(0, 70, 8), @@ -1512,7 +1523,7 @@ mod tests { &mut partial_chunks, BlockPos::new(0, 71, 0), BlockPos::new(4, 74, 9), - vec![ + &[ BlockPos::new(0, 70, 0), BlockPos::new(0, 70, 1), BlockPos::new(0, 70, 2), @@ -1526,4 +1537,41 @@ mod tests { ); assert_simulation_reaches(&mut simulation, 80, BlockPos::new(4, 74, 9)); } + + #[test] + fn test_mine_through_non_colliding_block() { + let mut partial_chunks = PartialChunkStorage::default(); + + let mut simulation = setup_simulation_world( + &mut partial_chunks, + // the pathfinder can't actually dig straight down, so we start a block to the side so + // it can descend correctly + BlockPos::new(0, 72, 1), + &[BlockPos::new(0, 71, 1)], + &[ + ( + BlockPos::new(0, 71, 0), + azalea_registry::Block::SculkVein.into(), + ), + ( + BlockPos::new(0, 70, 0), + azalea_registry::Block::GrassBlock.into(), + ), + // this is an extra check to make sure that we don't accidentally break the block + // below (since tnt will break instantly) + (BlockPos::new(0, 69, 0), azalea_registry::Block::Tnt.into()), + ], + ); + + simulation.app.world_mut().send_event(GotoEvent { + entity: simulation.entity, + goal: Arc::new(BlockPosGoal(BlockPos::new(0, 70, 0))), + successors_fn: moves::default_move, + allow_mining: true, + min_timeout: PathfinderTimeout::Nodes(1_000_000), + max_timeout: PathfinderTimeout::Nodes(5_000_000), + }); + + assert_simulation_reaches(&mut simulation, 200, BlockPos::new(0, 70, 0)); + } } diff --git a/azalea/src/pathfinder/simulation.rs b/azalea/src/pathfinder/simulation.rs index 5a68bf88..337efda7 100644 --- a/azalea/src/pathfinder/simulation.rs +++ b/azalea/src/pathfinder/simulation.rs @@ -2,8 +2,13 @@ use std::sync::Arc; -use azalea_client::{PhysicsState, inventory::Inventory, packet::game::SendPacketEvent}; -use azalea_core::{position::Vec3, resource_location::ResourceLocation, tick::GameTick}; +use azalea_client::{ + PhysicsState, interact::CurrentSequenceNumber, inventory::Inventory, + local_player::LocalGameMode, mining::MineBundle, packet::game::SendPacketEvent, +}; +use azalea_core::{ + game_type::GameMode, position::Vec3, resource_location::ResourceLocation, tick::GameTick, +}; use azalea_entity::{ Attributes, EntityDimensions, LookDirection, Physics, Position, attributes::AttributeInstance, }; @@ -87,7 +92,7 @@ fn create_simulation_instance(chunks: ChunkStorage) -> (App, Arc<RwLock<Instance fn create_simulation_player_complete_bundle( instance: Arc<RwLock<Instance>>, player: &SimulatedPlayerBundle, -) -> impl Bundle + use<> { +) -> impl Bundle { let instance_name = simulation_instance_name(); ( @@ -100,12 +105,17 @@ fn create_simulation_player_complete_bundle( azalea_registry::EntityKind::Player, instance_name, ), - azalea_client::InstanceHolder { + azalea_client::local_player::InstanceHolder { // partial_instance is never actually used by the pathfinder so partial_instance: Arc::new(RwLock::new(PartialInstance::default())), instance: instance.clone(), }, Inventory::default(), + LocalGameMode::from(GameMode::Survival), + MineBundle::default(), + CurrentSequenceNumber::default(), + azalea_client::local_player::PermissionLevel::default(), + azalea_client::local_player::PlayerAbilities::default(), ) } diff --git a/azalea/src/swarm/events.rs b/azalea/src/swarm/events.rs index b8154c50..aff578a3 100644 --- a/azalea/src/swarm/events.rs +++ b/azalea/src/swarm/events.rs @@ -1,4 +1,4 @@ -use azalea_client::InstanceHolder; +use azalea_client::local_player::InstanceHolder; use azalea_world::MinecraftEntityId; use bevy_app::{App, Plugin, Update}; use bevy_ecs::prelude::*; |
