Skip to content

Commit 63b4406

Browse files
committed
different travel function in water
1 parent 7d92a7e commit 63b4406

File tree

8 files changed

+283
-88
lines changed

8 files changed

+283
-88
lines changed

azalea-client/src/movement.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,8 @@ pub fn local_player_ai_step(
325325
) {
326326
for (physics_state, mut physics, mut sprinting, mut attributes) in query.iter_mut() {
327327
// server ai step
328-
physics.xxa = physics_state.left_impulse;
329-
physics.zza = physics_state.forward_impulse;
328+
physics.x_acceleration = physics_state.left_impulse;
329+
physics.z_acceleration = physics_state.forward_impulse;
330330

331331
// TODO: food data and abilities
332332
// let has_enough_food_to_sprint = self.food_data().food_level ||

azalea-entity/src/attributes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use thiserror::Error;
1111
pub struct Attributes {
1212
pub speed: AttributeInstance,
1313
pub attack_speed: AttributeInstance,
14+
pub water_movement_efficiency: AttributeInstance,
1415
}
1516

1617
#[derive(Clone, Debug)]

azalea-entity/src/lib.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,14 @@ pub struct Physics {
257257
pub velocity: Vec3,
258258
pub vec_delta_codec: VecDeltaCodec,
259259

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

267269
on_ground: bool,
268270
last_on_ground: bool,
@@ -295,9 +297,9 @@ impl Physics {
295297
velocity: Vec3::default(),
296298
vec_delta_codec: VecDeltaCodec::new(pos),
297299

298-
xxa: 0.,
299-
yya: 0.,
300-
zza: 0.,
300+
x_acceleration: 0.,
301+
y_acceleration: 0.,
302+
z_acceleration: 0.,
301303

302304
on_ground: false,
303305
last_on_ground: false,
@@ -345,6 +347,14 @@ impl Physics {
345347
pub fn clear_fire(&mut self) {
346348
self.remaining_fire_ticks = 0;
347349
}
350+
351+
pub fn is_in_water(&self) -> bool {
352+
self.was_touching_water
353+
}
354+
pub fn is_in_lava(&self) -> bool {
355+
// TODO: also check `!this.firstTick &&`
356+
self.lava_fluid_height > 0.
357+
}
348358
}
349359

350360
/// Marker component for entities that are dead.
@@ -444,6 +454,7 @@ impl EntityBundle {
444454
// entities have different defaults
445455
speed: AttributeInstance::new(0.1),
446456
attack_speed: AttributeInstance::new(4.0),
457+
water_movement_efficiency: AttributeInstance::new(0.0),
447458
},
448459

449460
jumping: Jumping(false),

azalea-physics/src/collision/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use tracing::warn;
2222

2323
use self::world_collisions::get_block_collisions;
2424

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

145146
/// Move an entity by a given delta, checking for collisions.
147+
///
148+
/// In Mojmap, this is `Entity.move`.
146149
pub fn move_colliding(
147-
_mover_type: &MoverType,
150+
_mover_type: MoverType,
148151
movement: &Vec3,
149152
world: &Instance,
150153
position: &mut Mut<azalea_entity::Position>,

azalea-physics/src/fluids.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,11 @@ pub fn update_in_water_state_and_do_fluid_pushing(
2525
.expect("All entities should be in a valid world");
2626
let world = world_lock.read();
2727

28-
println!("update_in_water_state_and_do_fluid_pushing");
29-
3028
physics.water_fluid_height = 0.;
3129
physics.lava_fluid_height = 0.;
3230

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

35-
println!("physics.water_fluid_height: {}", physics.water_fluid_height);
36-
3733
// let lava_push_factor = world
3834
// .registries
3935
// .dimension_type()
@@ -117,10 +113,6 @@ fn update_fluid_height_and_do_fluid_pushing(
117113
}
118114
let mut additional_player_delta_for_fluid =
119115
get_fluid_flow(&fluid_at_cur_pos, world, cur_pos);
120-
println!(
121-
"additional_player_delta_for_fluid: {}",
122-
additional_player_delta_for_fluid
123-
);
124116
if min_height_touching < 0.4 {
125117
additional_player_delta_for_fluid *= min_height_touching;
126118
};
@@ -131,9 +123,6 @@ fn update_fluid_height_and_do_fluid_pushing(
131123
}
132124
}
133125

134-
println!("num_fluids_being_touched: {}", num_fluids_being_touched);
135-
println!("additional_player_delta: {}", additional_player_delta);
136-
137126
if additional_player_delta.length() > 0. {
138127
additional_player_delta /= num_fluids_being_touched as f64;
139128

@@ -180,10 +169,6 @@ pub fn get_fluid_flow(fluid: &FluidState, world: &Instance, pos: BlockPos) -> Ve
180169
.get_fluid_state(&adjacent_block_pos)
181170
.unwrap_or_default();
182171
if fluid.affects_flow(&adjacent_fluid_state) {
183-
println!(
184-
"affects flow {adjacent_block_pos} {:?}",
185-
adjacent_fluid_state
186-
);
187172
let mut adjacent_fluid_height = adjacent_fluid_state.height();
188173
let mut adjacent_height_difference: f32 = 0.;
189174

0 commit comments

Comments
 (0)