diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2023-03-07 14:14:36 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-07 14:14:36 -0600 |
| commit | 719379a8a76ab0685f2bd14bebe2f0cd1e97f06b (patch) | |
| tree | ce5d6c62bc36fb1d1ec31083bc8e81a0109c12df /azalea/src/pathfinder | |
| parent | bf4ff517890cad3ff4e36b4b78959504192e5374 (diff) | |
| download | azalea-drasl-719379a8a76ab0685f2bd14bebe2f0cd1e97f06b.tar.xz | |
Bevy 0.10 (#79)
* replace 0.9.1 with 0.10.0
* start migrating to bevy .10
* well it compiles
* doesn't immediately panic
* remove unused imports
* fmt
* delete azalea-ecs
* make RelativeEntityUpdate an EntityCommand
* fix a doc test
* explain what FixedUpdate does
Diffstat (limited to 'azalea/src/pathfinder')
| -rw-r--r-- | azalea/src/pathfinder/mod.rs | 20 | ||||
| -rw-r--r-- | azalea/src/pathfinder/moves.rs | 20 |
2 files changed, 23 insertions, 17 deletions
diff --git a/azalea/src/pathfinder/mod.rs b/azalea/src/pathfinder/mod.rs index 8289d9c4..61a92038 100644 --- a/azalea/src/pathfinder/mod.rs +++ b/azalea/src/pathfinder/mod.rs @@ -4,18 +4,18 @@ mod mtdstarlite; use crate::bot::{JumpEvent, LookAtEvent}; use crate::{SprintDirection, WalkDirection}; -use azalea_client::{StartSprintEvent, StartWalkEvent}; -use azalea_core::{BlockPos, CardinalDirection}; -use azalea_ecs::{ - app::{App, Plugin}, +use crate::app::{App, CoreSchedule, IntoSystemAppConfig, Plugin}; +use crate::ecs::{ component::Component, entity::Entity, event::{EventReader, EventWriter}, query::{With, Without}, - schedule::IntoSystemDescriptor, + schedule::IntoSystemConfig, system::{Commands, Query, Res}, - AppTickExt, }; +use azalea_client::{StartSprintEvent, StartWalkEvent}; +use azalea_core::{BlockPos, CardinalDirection}; +use azalea_physics::PhysicsSet; use azalea_world::entity::metadata::Player; use azalea_world::entity::Local; use azalea_world::{ @@ -36,7 +36,13 @@ impl Plugin for PathfinderPlugin { fn build(&self, app: &mut App) { app.add_event::<GotoEvent>() .add_event::<PathFoundEvent>() - .add_tick_system(tick_execute_path.before("ai_step")) + .add_system( + // Adding `.in_schedule(CoreSchedule::FixedUpdate)` makes a system run every + // Minecraft tick (every 50 milliseconds). + tick_execute_path + .in_schedule(CoreSchedule::FixedUpdate) + .before(PhysicsSet), + ) .add_system(goto_listener) .add_system(add_default_pathfinder) .add_system(handle_tasks.before(path_found_listener)) diff --git a/azalea/src/pathfinder/moves.rs b/azalea/src/pathfinder/moves.rs index 011d8349..3639c091 100644 --- a/azalea/src/pathfinder/moves.rs +++ b/azalea/src/pathfinder/moves.rs @@ -1,10 +1,10 @@ use super::{Node, VerticalVel}; use azalea_core::{BlockPos, CardinalDirection}; use azalea_physics::collision::{self, BlockWithShape}; -use azalea_world::World; +use azalea_world::Instance; /// whether this block is passable -fn is_block_passable(pos: &BlockPos, world: &World) -> bool { +fn is_block_passable(pos: &BlockPos, world: &Instance) -> bool { if let Some(block) = world.chunks.get_block_state(pos) { block.shape() == &collision::empty_shape() } else { @@ -13,7 +13,7 @@ fn is_block_passable(pos: &BlockPos, world: &World) -> bool { } /// whether this block has a solid hitbox (i.e. we can stand on it) -fn is_block_solid(pos: &BlockPos, world: &World) -> bool { +fn is_block_solid(pos: &BlockPos, world: &Instance) -> bool { if let Some(block) = world.chunks.get_block_state(pos) { block.shape() == &collision::block_shape() } else { @@ -22,14 +22,14 @@ fn is_block_solid(pos: &BlockPos, world: &World) -> bool { } /// Whether this block and the block above are passable -fn is_passable(pos: &BlockPos, world: &World) -> bool { +fn is_passable(pos: &BlockPos, world: &Instance) -> bool { is_block_passable(pos, world) && is_block_passable(&pos.up(1), world) } /// Whether we can stand in this position. Checks if the block below is solid, /// and that the two blocks above that are passable. -fn is_standable(pos: &BlockPos, world: &World) -> bool { +fn is_standable(pos: &BlockPos, world: &Instance) -> bool { is_block_solid(&pos.down(1), world) && is_passable(pos, world) } @@ -37,7 +37,7 @@ const JUMP_COST: f32 = 0.5; const WALK_ONE_BLOCK_COST: f32 = 1.0; pub trait Move: Send + Sync { - fn cost(&self, world: &World, node: &Node) -> f32; + fn cost(&self, world: &Instance, node: &Node) -> f32; /// Returns by how much the entity's position should be changed when this /// move is executed. fn offset(&self) -> BlockPos; @@ -51,7 +51,7 @@ pub trait Move: Send + Sync { pub struct ForwardMove(pub CardinalDirection); impl Move for ForwardMove { - fn cost(&self, world: &World, node: &Node) -> f32 { + fn cost(&self, world: &Instance, node: &Node) -> f32 { if is_standable(&(node.pos + self.offset()), world) && node.vertical_vel == VerticalVel::None { @@ -67,7 +67,7 @@ impl Move for ForwardMove { pub struct AscendMove(pub CardinalDirection); impl Move for AscendMove { - fn cost(&self, world: &World, node: &Node) -> f32 { + fn cost(&self, world: &Instance, node: &Node) -> f32 { if node.vertical_vel == VerticalVel::None && is_block_passable(&node.pos.up(2), world) && is_standable(&(node.pos + self.offset()), world) @@ -89,7 +89,7 @@ impl Move for AscendMove { } pub struct DescendMove(pub CardinalDirection); impl Move for DescendMove { - fn cost(&self, world: &World, node: &Node) -> f32 { + fn cost(&self, world: &Instance, node: &Node) -> f32 { // check whether 3 blocks vertically forward are passable if node.vertical_vel == VerticalVel::None && is_standable(&(node.pos + self.offset()), world) @@ -112,7 +112,7 @@ impl Move for DescendMove { } pub struct DiagonalMove(pub CardinalDirection); impl Move for DiagonalMove { - fn cost(&self, world: &World, node: &Node) -> f32 { + fn cost(&self, world: &Instance, node: &Node) -> f32 { if node.vertical_vel != VerticalVel::None { return f32::INFINITY; } |
