mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
execute path every tick
This commit is contained in:
parent
8a507244d3
commit
7118f883dd
4 changed files with 24 additions and 14 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -264,6 +264,7 @@ dependencies = [
|
|||
"azalea-physics",
|
||||
"azalea-world",
|
||||
"num-traits",
|
||||
"parking_lot 0.12.1",
|
||||
"priority-queue",
|
||||
]
|
||||
|
||||
|
|
|
@ -15,4 +15,5 @@ azalea-core = { version = "0.3.0", path = "../azalea-core" }
|
|||
azalea-physics = { version = "0.3.0", path = "../azalea-physics" }
|
||||
azalea-world = { version = "0.3.0", path = "../azalea-world" }
|
||||
num-traits = "0.2.15"
|
||||
parking_lot = "0.12.1"
|
||||
priority-queue = "1.2.3"
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#![feature(let_chains)]
|
||||
|
||||
mod moves;
|
||||
mod mtdstarlite;
|
||||
|
||||
|
@ -10,28 +8,33 @@ use azalea_core::BlockPos;
|
|||
use azalea_world::entity::EntityData;
|
||||
use mtdstarlite::Edge;
|
||||
pub use mtdstarlite::MTDStarLite;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use parking_lot::Mutex;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
pub struct Plugin {
|
||||
pub state: Arc<Mutex<State>>,
|
||||
pub state: State,
|
||||
}
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
pub struct State {
|
||||
// pathfinder: Option<MTDStarLite<Node, f32>>,
|
||||
pub path: Arc<Mutex<Vec<Node>>>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl azalea::Plugin for Plugin {
|
||||
async fn handle(self: Box<Self>, event: Event, bot: Client) {
|
||||
// match *
|
||||
async fn handle(self: Box<Self>, event: Event, mut bot: Client) {
|
||||
let path = self.state.path.lock();
|
||||
|
||||
if !path.is_empty() {
|
||||
tick_execute_path(&mut bot, &path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Trait {
|
||||
fn goto(&self, goal: impl Goal);
|
||||
fn tick_execute_path(&mut self, path: &Vec<Node>);
|
||||
}
|
||||
|
||||
impl Trait for azalea_client::Client {
|
||||
|
@ -73,13 +76,13 @@ impl Trait for azalea_client::Client {
|
|||
);
|
||||
let p = pf.find_path();
|
||||
}
|
||||
}
|
||||
|
||||
fn tick_execute_path(&mut self, path: &Vec<Node>) {
|
||||
let start = path[0];
|
||||
let center = start.pos.center();
|
||||
self.look_at(¢er);
|
||||
self.walk(WalkDirection::Forward);
|
||||
}
|
||||
fn tick_execute_path(bot: &mut Client, path: &Vec<Node>) {
|
||||
let start = path[0];
|
||||
let center = start.pos.center();
|
||||
bot.look_at(¢er);
|
||||
bot.walk(WalkDirection::Forward);
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Hash, Clone, Copy, Debug)]
|
||||
|
|
|
@ -256,7 +256,12 @@ impl<
|
|||
|
||||
// identify a path from sstart to sgoal using the parent pointers
|
||||
let mut target = self.state(&self.goal).par;
|
||||
while !(Some(self.start) == target) && let Some(this_target) = target {
|
||||
while !(Some(self.start) == target) {
|
||||
let this_target = if let Some(this_target) = target {
|
||||
this_target
|
||||
} else {
|
||||
break;
|
||||
};
|
||||
// hunter follows path from start to goal;
|
||||
reverse_path.push(this_target);
|
||||
target = self.state(&this_target).par;
|
||||
|
|
Loading…
Add table
Reference in a new issue