Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-1 committed Jan 10, 2025
1 parent 558b469 commit 9e728dc
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 53 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ _Currently supported Minecraft version: `1.21.4`._
## Features

- [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)
- [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)
- [Pathfinder](https://azalea.matdoes.dev/azalea/pathfinder/index.html)
- [Swarms](https://azalea.matdoes.dev/azalea/swarm/index.html)
- [Breaking blocks](https://azalea.matdoes.dev/azalea/struct.Client.html#method.mine)
Expand Down
5 changes: 1 addition & 4 deletions azalea-block/src/fluid_state.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::{
block_state::{BlockState, BlockStateIntegerRepr},
Block,
};
use crate::block_state::{BlockState, BlockStateIntegerRepr};

#[derive(Clone, Debug)]
pub struct FluidState {
Expand Down
2 changes: 1 addition & 1 deletion azalea-client/src/packet_handling/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ pub fn process_packet_events(ecs: &mut World) {
if new_pos != **position {
**position = new_pos;
}
let position = position.clone();
let position = *position;
let mut look_direction = entity.get_mut::<LookDirection>().unwrap();
if new_look_direction != *look_direction {
*look_direction = new_look_direction;
Expand Down
35 changes: 18 additions & 17 deletions azalea-core/src/registry_holder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ impl RegistryHolder {
}
}

/// Get the dimension type registry, or `None` if it doesn't exist. You
/// should do some type of error handling if this returns `None`.
pub fn dimension_type(&self) -> Option<RegistryType<DimensionTypeElement>> {
let name = ResourceLocation::new("minecraft:dimension_type");
match self.get(&name) {
Some(Ok(registry)) => Some(registry),
Some(Err(err)) => {
error!(
"Error deserializing dimension type registry: {err:?}\n{:?}",
self.map.get(&name)
);
None
}
None => None,
}
}

fn get<T: Deserialize>(
&self,
name: &ResourceLocation,
Expand Down Expand Up @@ -66,23 +83,6 @@ impl RegistryHolder {

Some(Ok(RegistryType { map }))
}

/// Get the dimension type registry, or `None` if it doesn't exist. You
/// should do some type of error handling if this returns `None`.
pub fn dimension_type(&self) -> Option<RegistryType<DimensionTypeElement>> {
let name = ResourceLocation::new("minecraft:dimension_type");
match self.get(&name) {
Some(Ok(registry)) => Some(registry),
Some(Err(err)) => {
error!(
"Error deserializing dimension type registry: {err:?}\n{:?}",
self.map.get(&name)
);
None
}
None => None,
}
}
}

/// A collection of values for a certain type of registry data.
Expand Down Expand Up @@ -161,6 +161,7 @@ pub struct DimensionTypeElement {
pub struct DimensionTypeElement {
pub height: u32,
pub min_y: i32,
pub ultrawarm: Option<u8>,
#[simdnbt(flatten)]
pub _extra: HashMap<String, NbtTag>,
}
Expand Down
2 changes: 1 addition & 1 deletion azalea-entity/src/plugin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ pub fn clamp_look_direction(mut query: Query<&mut LookDirection>) {
/// Cached position in the world must be updated.
pub fn update_bounding_box(mut query: Query<(&Position, &mut Physics), Changed<Position>>) {
for (position, mut physics) in query.iter_mut() {
let bounding_box = physics.dimensions.make_bounding_box(&position);
let bounding_box = physics.dimensions.make_bounding_box(position);
physics.bounding_box = bounding_box;
}
}
Expand Down
39 changes: 26 additions & 13 deletions azalea-physics/src/fluids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ use azalea_core::{
position::{BlockPos, Vec3},
};
use azalea_entity::{InLoadedChunk, LocalEntity, Physics, Position};
use azalea_registry::Fluid;
use azalea_world::{Instance, InstanceContainer, InstanceName};
use bevy_ecs::prelude::*;

use crate::collision::legacy_blocks_motion;

#[allow(clippy::type_complexity)]
pub fn update_in_water_state_and_do_fluid_pushing(
mut query: Query<
(&mut Physics, &Position, &InstanceName),
Expand All @@ -29,19 +29,31 @@ pub fn 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);

// let lava_push_factor = world
// .registries
// .dimension_type()
// .map(|d| d.lava_push_factor);
// TODO
update_in_water_state_and_do_water_current_pushing(&mut physics, &world, position);

let is_ultrawarm = world
.registries
.dimension_type()
.and_then(|d| d.map.get(instance_name).and_then(|d| d.ultrawarm))

Check failure on line 37 in azalea-physics/src/fluids.rs

View workflow job for this annotation

GitHub Actions / clippy

mismatched types

error[E0308]: mismatched types --> azalea-physics/src/fluids.rs:37:65 | 37 | .and_then(|d| d.map.get(instance_name).and_then(|d| d.ultrawarm)) | ^^^^^^^^^^^ expected `Option<_>`, found `bool` | = note: expected enum `std::option::Option<_>` found type `bool` help: try wrapping the expression in `Some` | 37 | .and_then(|d| d.map.get(instance_name).and_then(|d| Some(d.ultrawarm))) | +++++ +
== Some(1);
let lava_push_factor = if is_ultrawarm {
0.007
} else {
0.0023333333333333335
};

update_fluid_height_and_do_fluid_pushing(
&mut physics,
&world,
FluidKind::Lava,
lava_push_factor,
);
}
}
fn update_in_water_state_and_do_water_current_pushing(
physics: &mut Physics,
world: &Instance,
position: &Position,
_position: &Position,
) {
// TODO: implement vehicles and boats
// if vehicle == AbstractBoat {
Expand Down Expand Up @@ -237,6 +249,7 @@ fn is_solid_face(
let registry_block = azalea_registry::Block::from(block_state);
if matches!(
registry_block,
// frosted ice is from frost walker
azalea_registry::Block::Ice | azalea_registry::Block::FrostedIce
) {
return false;
Expand All @@ -245,10 +258,10 @@ fn is_solid_face(
}

fn is_face_sturdy(
block_state: BlockState,
world: &Instance,
pos: BlockPos,
direction: Direction,
_block_state: BlockState,
_world: &Instance,
_pos: BlockPos,
_direction: Direction,
) -> bool {
// TODO: this does a whole bunch of physics shape checks for waterlogged blocks
// that i honestly cannot be bothered to implement right now
Expand Down
14 changes: 8 additions & 6 deletions azalea-physics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ use std::collections::HashSet;

use azalea_block::{fluid_state::FluidState, properties, Block, BlockState};
use azalea_core::{
aabb::AABB,
math,
position::{BlockPos, Vec3},
tick::GameTick,
};
use azalea_entity::{
metadata::Sprinting, move_relative, Attributes, InLoadedChunk, Jumping, LastSentPosition,
LocalEntity, LookDirection, OnClimbable, Physics, Pose, Position,
metadata::Sprinting, move_relative, Attributes, InLoadedChunk, Jumping, LocalEntity,
LookDirection, OnClimbable, Physics, Pose, Position,
};
use azalea_world::{Instance, InstanceContainer, InstanceName};
use bevy_app::{App, Plugin};
Expand Down Expand Up @@ -149,6 +148,7 @@ fn jump_in_liquid(physics: &mut Physics) {
}

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

let mut movement_this_tick = Vec::<EntityMovement>::new();
movement_this_tick.push(EntityMovement {
// minecraft adds more entries to the list when the code is running on the
// server
let movement_this_tick = [EntityMovement {
from: physics.old_position,
to: **position,
});
}];

check_inside_blocks(&mut physics, &world, &movement_this_tick);
}
Expand Down Expand Up @@ -271,6 +272,7 @@ fn handle_entity_inside_block(
physics: &mut Physics,
) {
let registry_block = azalea_registry::Block::from(block);
#[allow(clippy::single_match)]
match registry_block {
azalea_registry::Block::BubbleColumn => {
let block_above = world.get_block_state(&block_pos.up(1)).unwrap_or_default();
Expand Down
20 changes: 10 additions & 10 deletions azalea-physics/src/travel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,19 @@ pub fn travel(
&mut physics,
&direction,
position,
&attributes,
attributes,
sprinting,
&on_climbable,
on_climbable,
pose,
&jumping,
jumping,
&world,
);
}
}
}

/// The usual movement when we're not in water or using an elytra.
#[allow(clippy::too_many_arguments)]
fn travel_in_air(
physics: &mut Physics,
direction: &LookDirection,
Expand Down Expand Up @@ -116,9 +117,9 @@ fn travel_in_air(
let mut movement = handle_relative_friction_and_calculate_movement(
HandleRelativeFrictionAndCalculateMovementOpts {
block_friction,
world: &world,
world,
physics,
direction: &direction,
direction,
position,
attributes,
is_sprinting: *sprinting,
Expand Down Expand Up @@ -256,15 +257,14 @@ fn get_fluid_falling_adjusted_movement(
sprinting: Sprinting,
) -> Vec3 {
if gravity != 0. && !*sprinting {
let new_y_velocity;
if moving_down
let new_y_velocity = if moving_down
&& (new_velocity.y - 0.005).abs() >= 0.003
&& f64::abs(new_velocity.y - gravity / 16.0) < 0.003
{
new_y_velocity = -0.003;
-0.003
} else {
new_y_velocity = new_velocity.y - gravity / 16.0;
}
new_velocity.y - gravity / 16.0
};

Vec3 {
x: new_velocity.x,
Expand Down

0 comments on commit 9e728dc

Please sign in to comment.