Skip to content

Commit 9e728dc

Browse files
committed
cleanup
1 parent 558b469 commit 9e728dc

File tree

8 files changed

+66
-53
lines changed

8 files changed

+66
-53
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ _Currently supported Minecraft version: `1.21.4`._
1818
1919
## Features
2020

21-
- [Accurate physics](https://github.com/azalea-rs/azalea/blob/main/azalea-physics/src/lib.rs) (but some features like entity collisions and water physics aren't yet implemented)
21+
- [Accurate physics](https://github.com/azalea-rs/azalea/blob/main/azalea-physics/src/lib.rs) (but some features like entity collisions and elytras aren't yet implemented)
2222
- [Pathfinder](https://azalea.matdoes.dev/azalea/pathfinder/index.html)
2323
- [Swarms](https://azalea.matdoes.dev/azalea/swarm/index.html)
2424
- [Breaking blocks](https://azalea.matdoes.dev/azalea/struct.Client.html#method.mine)

azalea-block/src/fluid_state.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use crate::{
2-
block_state::{BlockState, BlockStateIntegerRepr},
3-
Block,
4-
};
1+
use crate::block_state::{BlockState, BlockStateIntegerRepr};
52

63
#[derive(Clone, Debug)]
74
pub struct FluidState {

azalea-client/src/packet_handling/game.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ pub fn process_packet_events(ecs: &mut World) {
856856
if new_pos != **position {
857857
**position = new_pos;
858858
}
859-
let position = position.clone();
859+
let position = *position;
860860
let mut look_direction = entity.get_mut::<LookDirection>().unwrap();
861861
if new_look_direction != *look_direction {
862862
*look_direction = new_look_direction;

azalea-core/src/registry_holder.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,23 @@ impl RegistryHolder {
3939
}
4040
}
4141

42+
/// Get the dimension type registry, or `None` if it doesn't exist. You
43+
/// should do some type of error handling if this returns `None`.
44+
pub fn dimension_type(&self) -> Option<RegistryType<DimensionTypeElement>> {
45+
let name = ResourceLocation::new("minecraft:dimension_type");
46+
match self.get(&name) {
47+
Some(Ok(registry)) => Some(registry),
48+
Some(Err(err)) => {
49+
error!(
50+
"Error deserializing dimension type registry: {err:?}\n{:?}",
51+
self.map.get(&name)
52+
);
53+
None
54+
}
55+
None => None,
56+
}
57+
}
58+
4259
fn get<T: Deserialize>(
4360
&self,
4461
name: &ResourceLocation,
@@ -66,23 +83,6 @@ impl RegistryHolder {
6683

6784
Some(Ok(RegistryType { map }))
6885
}
69-
70-
/// Get the dimension type registry, or `None` if it doesn't exist. You
71-
/// should do some type of error handling if this returns `None`.
72-
pub fn dimension_type(&self) -> Option<RegistryType<DimensionTypeElement>> {
73-
let name = ResourceLocation::new("minecraft:dimension_type");
74-
match self.get(&name) {
75-
Some(Ok(registry)) => Some(registry),
76-
Some(Err(err)) => {
77-
error!(
78-
"Error deserializing dimension type registry: {err:?}\n{:?}",
79-
self.map.get(&name)
80-
);
81-
None
82-
}
83-
None => None,
84-
}
85-
}
8686
}
8787

8888
/// A collection of values for a certain type of registry data.
@@ -161,6 +161,7 @@ pub struct DimensionTypeElement {
161161
pub struct DimensionTypeElement {
162162
pub height: u32,
163163
pub min_y: i32,
164+
pub ultrawarm: Option<u8>,
164165
#[simdnbt(flatten)]
165166
pub _extra: HashMap<String, NbtTag>,
166167
}

azalea-entity/src/plugin/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ pub fn clamp_look_direction(mut query: Query<&mut LookDirection>) {
198198
/// Cached position in the world must be updated.
199199
pub fn update_bounding_box(mut query: Query<(&Position, &mut Physics), Changed<Position>>) {
200200
for (position, mut physics) in query.iter_mut() {
201-
let bounding_box = physics.dimensions.make_bounding_box(&position);
201+
let bounding_box = physics.dimensions.make_bounding_box(position);
202202
physics.bounding_box = bounding_box;
203203
}
204204
}

azalea-physics/src/fluids.rs

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ use azalea_core::{
77
position::{BlockPos, Vec3},
88
};
99
use azalea_entity::{InLoadedChunk, LocalEntity, Physics, Position};
10-
use azalea_registry::Fluid;
1110
use azalea_world::{Instance, InstanceContainer, InstanceName};
1211
use bevy_ecs::prelude::*;
1312

1413
use crate::collision::legacy_blocks_motion;
1514

15+
#[allow(clippy::type_complexity)]
1616
pub fn update_in_water_state_and_do_fluid_pushing(
1717
mut query: Query<
1818
(&mut Physics, &Position, &InstanceName),
@@ -29,19 +29,31 @@ pub fn update_in_water_state_and_do_fluid_pushing(
2929
physics.water_fluid_height = 0.;
3030
physics.lava_fluid_height = 0.;
3131

32-
update_in_water_state_and_do_water_current_pushing(&mut physics, &world, &position);
33-
34-
// let lava_push_factor = world
35-
// .registries
36-
// .dimension_type()
37-
// .map(|d| d.lava_push_factor);
38-
// TODO
32+
update_in_water_state_and_do_water_current_pushing(&mut physics, &world, position);
33+
34+
let is_ultrawarm = world
35+
.registries
36+
.dimension_type()
37+
.and_then(|d| d.map.get(instance_name).and_then(|d| d.ultrawarm))
38+
== Some(1);
39+
let lava_push_factor = if is_ultrawarm {
40+
0.007
41+
} else {
42+
0.0023333333333333335
43+
};
44+
45+
update_fluid_height_and_do_fluid_pushing(
46+
&mut physics,
47+
&world,
48+
FluidKind::Lava,
49+
lava_push_factor,
50+
);
3951
}
4052
}
4153
fn update_in_water_state_and_do_water_current_pushing(
4254
physics: &mut Physics,
4355
world: &Instance,
44-
position: &Position,
56+
_position: &Position,
4557
) {
4658
// TODO: implement vehicles and boats
4759
// if vehicle == AbstractBoat {
@@ -237,6 +249,7 @@ fn is_solid_face(
237249
let registry_block = azalea_registry::Block::from(block_state);
238250
if matches!(
239251
registry_block,
252+
// frosted ice is from frost walker
240253
azalea_registry::Block::Ice | azalea_registry::Block::FrostedIce
241254
) {
242255
return false;
@@ -245,10 +258,10 @@ fn is_solid_face(
245258
}
246259

247260
fn is_face_sturdy(
248-
block_state: BlockState,
249-
world: &Instance,
250-
pos: BlockPos,
251-
direction: Direction,
261+
_block_state: BlockState,
262+
_world: &Instance,
263+
_pos: BlockPos,
264+
_direction: Direction,
252265
) -> bool {
253266
// TODO: this does a whole bunch of physics shape checks for waterlogged blocks
254267
// that i honestly cannot be bothered to implement right now

azalea-physics/src/lib.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@ use std::collections::HashSet;
1010

1111
use azalea_block::{fluid_state::FluidState, properties, Block, BlockState};
1212
use azalea_core::{
13-
aabb::AABB,
1413
math,
1514
position::{BlockPos, Vec3},
1615
tick::GameTick,
1716
};
1817
use azalea_entity::{
19-
metadata::Sprinting, move_relative, Attributes, InLoadedChunk, Jumping, LastSentPosition,
20-
LocalEntity, LookDirection, OnClimbable, Physics, Pose, Position,
18+
metadata::Sprinting, move_relative, Attributes, InLoadedChunk, Jumping, LocalEntity,
19+
LookDirection, OnClimbable, Physics, Pose, Position,
2120
};
2221
use azalea_world::{Instance, InstanceContainer, InstanceName};
2322
use bevy_app::{App, Plugin};
@@ -149,6 +148,7 @@ fn jump_in_liquid(physics: &mut Physics) {
149148
}
150149

151150
// in minecraft, this is done as part of aiStep immediately after travel
151+
#[allow(clippy::type_complexity)]
152152
pub fn apply_effects_from_blocks(
153153
mut query: Query<
154154
(&mut Physics, &Position, &InstanceName),
@@ -172,11 +172,12 @@ pub fn apply_effects_from_blocks(
172172
// var4.getBlock().stepOn(this.level(), var3, var4, this);
173173
// }
174174

175-
let mut movement_this_tick = Vec::<EntityMovement>::new();
176-
movement_this_tick.push(EntityMovement {
175+
// minecraft adds more entries to the list when the code is running on the
176+
// server
177+
let movement_this_tick = [EntityMovement {
177178
from: physics.old_position,
178179
to: **position,
179-
});
180+
}];
180181

181182
check_inside_blocks(&mut physics, &world, &movement_this_tick);
182183
}
@@ -271,6 +272,7 @@ fn handle_entity_inside_block(
271272
physics: &mut Physics,
272273
) {
273274
let registry_block = azalea_registry::Block::from(block);
275+
#[allow(clippy::single_match)]
274276
match registry_block {
275277
azalea_registry::Block::BubbleColumn => {
276278
let block_above = world.get_block_state(&block_pos.up(1)).unwrap_or_default();

azalea-physics/src/travel.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,19 @@ pub fn travel(
7272
&mut physics,
7373
&direction,
7474
position,
75-
&attributes,
75+
attributes,
7676
sprinting,
77-
&on_climbable,
77+
on_climbable,
7878
pose,
79-
&jumping,
79+
jumping,
8080
&world,
8181
);
8282
}
8383
}
8484
}
8585

8686
/// The usual movement when we're not in water or using an elytra.
87+
#[allow(clippy::too_many_arguments)]
8788
fn travel_in_air(
8889
physics: &mut Physics,
8990
direction: &LookDirection,
@@ -116,9 +117,9 @@ fn travel_in_air(
116117
let mut movement = handle_relative_friction_and_calculate_movement(
117118
HandleRelativeFrictionAndCalculateMovementOpts {
118119
block_friction,
119-
world: &world,
120+
world,
120121
physics,
121-
direction: &direction,
122+
direction,
122123
position,
123124
attributes,
124125
is_sprinting: *sprinting,
@@ -256,15 +257,14 @@ fn get_fluid_falling_adjusted_movement(
256257
sprinting: Sprinting,
257258
) -> Vec3 {
258259
if gravity != 0. && !*sprinting {
259-
let new_y_velocity;
260-
if moving_down
260+
let new_y_velocity = if moving_down
261261
&& (new_velocity.y - 0.005).abs() >= 0.003
262262
&& f64::abs(new_velocity.y - gravity / 16.0) < 0.003
263263
{
264-
new_y_velocity = -0.003;
264+
-0.003
265265
} else {
266-
new_y_velocity = new_velocity.y - gravity / 16.0;
267-
}
266+
new_velocity.y - gravity / 16.0
267+
};
268268

269269
Vec3 {
270270
x: new_velocity.x,

0 commit comments

Comments
 (0)