Skip to content

Commit

Permalink
different travel function in water
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-1 committed Jan 9, 2025
1 parent 7d92a7e commit 63b4406
Show file tree
Hide file tree
Showing 8 changed files with 283 additions and 88 deletions.
4 changes: 2 additions & 2 deletions azalea-client/src/movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ pub fn local_player_ai_step(
) {
for (physics_state, mut physics, mut sprinting, mut attributes) in query.iter_mut() {
// server ai step
physics.xxa = physics_state.left_impulse;
physics.zza = physics_state.forward_impulse;
physics.x_acceleration = physics_state.left_impulse;
physics.z_acceleration = physics_state.forward_impulse;

// TODO: food data and abilities
// let has_enough_food_to_sprint = self.food_data().food_level ||
Expand Down
1 change: 1 addition & 0 deletions azalea-entity/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use thiserror::Error;
pub struct Attributes {
pub speed: AttributeInstance,
pub attack_speed: AttributeInstance,
pub water_movement_efficiency: AttributeInstance,
}

#[derive(Clone, Debug)]
Expand Down
29 changes: 20 additions & 9 deletions azalea-entity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,14 @@ pub struct Physics {
pub velocity: Vec3,
pub vec_delta_codec: VecDeltaCodec,

/// X acceleration.
pub xxa: f32,
/// Y acceleration.
pub yya: f32,
/// Z acceleration.
pub zza: f32,
/// The acceleration here is the force that will be attempted to be added to
/// the entity's velocity next tick.
///
/// You should typically not set this yourself, since it's controlled by how
/// the entity is trying to move.
pub x_acceleration: f32,
pub y_acceleration: f32,
pub z_acceleration: f32,

on_ground: bool,
last_on_ground: bool,
Expand Down Expand Up @@ -295,9 +297,9 @@ impl Physics {
velocity: Vec3::default(),
vec_delta_codec: VecDeltaCodec::new(pos),

xxa: 0.,
yya: 0.,
zza: 0.,
x_acceleration: 0.,
y_acceleration: 0.,
z_acceleration: 0.,

on_ground: false,
last_on_ground: false,
Expand Down Expand Up @@ -345,6 +347,14 @@ impl Physics {
pub fn clear_fire(&mut self) {
self.remaining_fire_ticks = 0;
}

pub fn is_in_water(&self) -> bool {
self.was_touching_water
}
pub fn is_in_lava(&self) -> bool {
// TODO: also check `!this.firstTick &&`
self.lava_fluid_height > 0.
}
}

/// Marker component for entities that are dead.
Expand Down Expand Up @@ -444,6 +454,7 @@ impl EntityBundle {
// entities have different defaults
speed: AttributeInstance::new(0.1),
attack_speed: AttributeInstance::new(4.0),
water_movement_efficiency: AttributeInstance::new(0.0),
},

jumping: Jumping(false),
Expand Down
5 changes: 4 additions & 1 deletion azalea-physics/src/collision/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use tracing::warn;

use self::world_collisions::get_block_collisions;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MoverType {
Own,
Player,
Expand Down Expand Up @@ -143,8 +144,10 @@ fn collide(movement: &Vec3, world: &Instance, physics: &azalea_entity::Physics)
}

/// Move an entity by a given delta, checking for collisions.
///
/// In Mojmap, this is `Entity.move`.
pub fn move_colliding(
_mover_type: &MoverType,
_mover_type: MoverType,
movement: &Vec3,
world: &Instance,
position: &mut Mut<azalea_entity::Position>,
Expand Down
15 changes: 0 additions & 15 deletions azalea-physics/src/fluids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,11 @@ pub fn update_in_water_state_and_do_fluid_pushing(
.expect("All entities should be in a valid world");
let world = world_lock.read();

println!("update_in_water_state_and_do_fluid_pushing");

physics.water_fluid_height = 0.;
physics.lava_fluid_height = 0.;

update_in_water_state_and_do_water_current_pushing(&mut physics, &world, &position);

Check warning on line 31 in azalea-physics/src/fluids.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

warning: this expression creates a reference which is immediately dereferenced by the compiler --> azalea-physics/src/fluids.rs:31:82 | 31 | update_in_water_state_and_do_water_current_pushing(&mut physics, &world, &position); | ^^^^^^^^^ help: change this to: `position` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `#[warn(clippy::needless_borrow)]` on by default

println!("physics.water_fluid_height: {}", physics.water_fluid_height);

// let lava_push_factor = world
// .registries
// .dimension_type()
Expand Down Expand Up @@ -117,10 +113,6 @@ fn update_fluid_height_and_do_fluid_pushing(
}
let mut additional_player_delta_for_fluid =
get_fluid_flow(&fluid_at_cur_pos, world, cur_pos);
println!(
"additional_player_delta_for_fluid: {}",
additional_player_delta_for_fluid
);
if min_height_touching < 0.4 {
additional_player_delta_for_fluid *= min_height_touching;
};
Expand All @@ -131,9 +123,6 @@ fn update_fluid_height_and_do_fluid_pushing(
}
}

println!("num_fluids_being_touched: {}", num_fluids_being_touched);
println!("additional_player_delta: {}", additional_player_delta);

if additional_player_delta.length() > 0. {
additional_player_delta /= num_fluids_being_touched as f64;

Expand Down Expand Up @@ -180,10 +169,6 @@ pub fn get_fluid_flow(fluid: &FluidState, world: &Instance, pos: BlockPos) -> Ve
.get_fluid_state(&adjacent_block_pos)
.unwrap_or_default();
if fluid.affects_flow(&adjacent_fluid_state) {
println!(
"affects flow {adjacent_block_pos} {:?}",
adjacent_fluid_state
);
let mut adjacent_fluid_height = adjacent_fluid_state.height();
let mut adjacent_height_difference: f32 = 0.;

Expand Down
Loading

0 comments on commit 63b4406

Please sign in to comment.