aboutsummaryrefslogtreecommitdiff
path: root/azalea-physics/src/fluids.rs
diff options
context:
space:
mode:
Diffstat (limited to 'azalea-physics/src/fluids.rs')
-rw-r--r--azalea-physics/src/fluids.rs68
1 files changed, 36 insertions, 32 deletions
diff --git a/azalea-physics/src/fluids.rs b/azalea-physics/src/fluids.rs
index bbc044f6..f8643b9c 100644
--- a/azalea-physics/src/fluids.rs
+++ b/azalea-physics/src/fluids.rs
@@ -27,6 +27,8 @@ pub fn update_in_water_state_and_do_fluid_pushing(
.expect("All entities with InLoadedChunk should be in a valid world");
let world = world_lock.read();
+ // reset the heights since they're going to be set in
+ // update_in_water_state_and_do_water_current_pushing
physics.water_fluid_height = 0.;
physics.lava_fluid_height = 0.;
@@ -110,9 +112,9 @@ fn update_fluid_height_and_do_fluid_pushing(
let mut additional_player_delta = Vec3::default();
let mut num_fluids_being_touched = 0;
- for cur_x in min_x..=max_x {
- for cur_y in min_y..=max_y {
- for cur_z in min_z..=max_z {
+ for cur_x in min_x..max_x {
+ for cur_y in min_y..max_y {
+ for cur_z in min_z..max_z {
let cur_pos = BlockPos::new(cur_x, cur_y, cur_z);
let Some(fluid_at_cur_pos) = world.get_fluid_state(&cur_pos) else {
continue;
@@ -184,42 +186,44 @@ pub fn get_fluid_flow(fluid: &FluidState, world: &Instance, pos: BlockPos) -> Ve
let mut z_flow: f64 = 0.;
let mut x_flow: f64 = 0.;
+ let cur_fluid_height = fluid.height();
+
for direction in Direction::HORIZONTAL {
let adjacent_block_pos = pos.offset_with_direction(direction);
- let adjacent_fluid_state = world
- .get_fluid_state(&adjacent_block_pos)
+
+ let adjacent_block_state = world
+ .get_block_state(&adjacent_block_pos)
.unwrap_or_default();
- if fluid.affects_flow(&adjacent_fluid_state) {
- let mut adjacent_fluid_height = adjacent_fluid_state.height();
- let mut adjacent_height_difference: f32 = 0.;
-
- if adjacent_fluid_height == 0. {
- if !legacy_blocks_motion(
- world
- .get_block_state(&adjacent_block_pos)
- .unwrap_or_default(),
- ) {
- let block_pos_below_adjacent = adjacent_block_pos.down(1);
- let fluid_below_adjacent = world
- .get_fluid_state(&block_pos_below_adjacent)
- .unwrap_or_default();
-
- if fluid.affects_flow(&fluid_below_adjacent) {
- adjacent_fluid_height = fluid_below_adjacent.height();
- if adjacent_fluid_height > 0. {
- adjacent_height_difference =
- fluid.height() - (adjacent_fluid_height - 0.8888889);
- }
+ let adjacent_fluid_state = FluidState::from(adjacent_block_state);
+
+ if !fluid.affects_flow(&adjacent_fluid_state) {
+ continue;
+ };
+ let mut adjacent_fluid_height = adjacent_fluid_state.height();
+ let mut adjacent_height_difference: f32 = 0.;
+
+ if adjacent_fluid_height == 0. {
+ if !legacy_blocks_motion(adjacent_block_state) {
+ let block_pos_below_adjacent = adjacent_block_pos.down(1);
+ let fluid_below_adjacent = world
+ .get_fluid_state(&block_pos_below_adjacent)
+ .unwrap_or_default();
+
+ if fluid.affects_flow(&fluid_below_adjacent) {
+ adjacent_fluid_height = fluid_below_adjacent.height();
+ if adjacent_fluid_height > 0. {
+ adjacent_height_difference =
+ cur_fluid_height - (adjacent_fluid_height - 0.8888889);
}
}
- } else if adjacent_fluid_height > 0. {
- adjacent_height_difference = fluid.height() - adjacent_fluid_height;
}
+ } else if adjacent_fluid_height > 0. {
+ adjacent_height_difference = cur_fluid_height - adjacent_fluid_height;
+ }
- if adjacent_height_difference != 0. {
- x_flow += (direction.x() as f32 * adjacent_height_difference) as f64;
- z_flow += (direction.z() as f32 * adjacent_height_difference) as f64;
- }
+ if adjacent_height_difference != 0. {
+ x_flow += (direction.x() as f32 * adjacent_height_difference) as f64;
+ z_flow += (direction.z() as f32 * adjacent_height_difference) as f64;
}
}