aboutsummaryrefslogtreecommitdiff
path: root/azalea/src
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-06-02 03:14:08 -0430
committermat <git@matdoes.dev>2025-06-02 03:14:08 -0430
commit0569862a1b1f46f1854f4eafd1569359397f2515 (patch)
tree01f20f6b078db41d34f08d7f52000f9fb46f7c45 /azalea/src
parentd7cd30505954d841f05d85a4cfd74412739778dd (diff)
downloadazalea-drasl-0569862a1b1f46f1854f4eafd1569359397f2515.tar.xz
fix issues related to pathfinder mining
Diffstat (limited to 'azalea/src')
-rw-r--r--azalea/src/pathfinder/debug.rs2
-rw-r--r--azalea/src/pathfinder/mod.rs84
-rw-r--r--azalea/src/pathfinder/simulation.rs18
-rw-r--r--azalea/src/swarm/events.rs2
4 files changed, 82 insertions, 24 deletions
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::*;