1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 06:16:04 +00:00

fix going too fast

This commit is contained in:
mat 2022-11-01 21:53:44 -05:00
parent 6daaf9e6b7
commit 8db3a45729
5 changed files with 28 additions and 17 deletions

View file

@ -100,6 +100,9 @@ fn tick_execute_path(bot: &mut Client, path: &mut VecDeque<Node>) {
if target.is_reached(&bot.entity()) {
println!("ok target reached");
path.pop_front();
if path.is_empty() {
bot.walk(WalkDirection::None);
}
}
}
@ -120,12 +123,12 @@ impl Node {
/// Returns whether the entity is at the node and should start going to the
/// next node.
pub fn is_reached(&self, entity: &EntityData) -> bool {
println!(
"entity.yya: {} {:?}=={:?}",
entity.yya,
BlockPos::from(entity.pos()),
self.pos
);
// println!(
// "entity.yya: {} {:?}=={:?}",
// entity.yya,
// BlockPos::from(entity.pos()),
// self.pos
// );
entity.yya == 0. && BlockPos::from(entity.pos()) == self.pos
}
}

View file

@ -158,6 +158,8 @@ impl MovableEntity for Entity<'_> {
if vertical_collision {
// blockBelow.updateEntityAfterFallOn(this.level, this);
// the default implementation of updateEntityAfterFallOn sets the y movement to 0
self.delta.y = 0.;
}
if on_ground {

View file

@ -143,12 +143,16 @@ fn handle_relative_friction_and_calculate_movement(
acceleration: &Vec3,
block_friction: f32,
) -> Vec3 {
entity.move_relative(get_speed(&*entity, block_friction), acceleration);
entity.move_relative(
get_friction_influenced_speed(&*entity, block_friction),
acceleration,
);
// entity.delta = entity.handle_on_climbable(entity.delta);
entity
.move_colliding(&MoverType::Own, &entity.delta.clone())
.expect("Entity should exist.");
// let delta_movement = entity.delta;
// ladders
// if ((entity.horizontalCollision || entity.jumping) && (entity.onClimbable() || entity.getFeetBlockState().is(Blocks.POWDER_SNOW) && PowderSnowBlock.canEntityWalkOnPowderSnow(entity))) {
// var3 = new Vec3(var3.x, 0.2D, var3.z);
// }
@ -160,10 +164,10 @@ fn handle_relative_friction_and_calculate_movement(
// private float getFrictionInfluencedSpeed(float friction) {
// return this.onGround ? this.getSpeed() * (0.21600002F / (friction * friction * friction)) : this.flyingSpeed;
// }
fn get_speed(entity: &EntityData, friction: f32) -> f32 {
fn get_friction_influenced_speed(entity: &EntityData, friction: f32) -> f32 {
// TODO: have speed & flying_speed fields in entity
if entity.on_ground {
let speed: f32 = 0.7;
let speed: f32 = 0.1;
speed * (0.216f32 / (friction * friction * friction))
} else {
// entity.flying_speed

View file

@ -38,10 +38,9 @@ impl BotTrait for azalea_client::Client {
fn look_at(&mut self, pos: &Vec3) {
// borrowed from mineflayer's Bot.lookAt because i didn't want to do math
let delta = self.entity().pos() - pos;
let x_rot = (PI - f64::atan2(-delta.x, -delta.z)) * (180.0 / PI);
let y_rot = (PI - f64::atan2(-delta.x, -delta.z)) * (180.0 / PI);
let ground_distance = f64::sqrt(delta.x * delta.x + delta.z * delta.z);
let y_rot = f64::atan2(delta.y, ground_distance) * -(180.0 / PI);
println!("x_rot: {}, y_rot: {}", x_rot, y_rot);
let x_rot = f64::atan2(delta.y, ground_distance) * -(180.0 / PI);
self.set_rotation(y_rot as f32, x_rot as f32);
}
}

View file

@ -1,4 +1,4 @@
use azalea::{prelude::*, BlockPos};
use azalea::{prelude::*, BlockPos, WalkDirection};
use azalea::{Account, Client, Event};
use azalea_pathfinder::{BlockPosGoal, Trait};
@ -24,7 +24,7 @@ async fn main() -> anyhow::Result<()> {
Ok(())
}
async fn handle(bot: Client, event: Event, _state: State) -> anyhow::Result<()> {
async fn handle(mut bot: Client, event: Event, _state: State) -> anyhow::Result<()> {
match event {
Event::Login => {
// bot.chat("Hello world").await?;
@ -32,14 +32,17 @@ async fn handle(bot: Client, event: Event, _state: State) -> anyhow::Result<()>
Event::Chat(m) => {
println!("{}", m.message().to_ansi(None));
if m.message().to_string() == "<py5> goto" {
let target_pos: BlockPos = bot
let target_pos_vec3 = bot
.dimension
.read()
.entity_by_uuid(&uuid::uuid!("6536bfed869548fd83a1ecd24cf2a0fd"))
.unwrap()
.pos()
.into();
bot.goto(BlockPosGoal::from(target_pos));
.clone();
// let target_pos: BlockPos = target_pos_vec3.into();
// bot.look_at(&target_pos_vec3);
// bot.goto(BlockPosGoal::from(target_pos));
bot.walk(WalkDirection::Forward);
}
}
Event::Initialize => {