mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 23:44:38 +00:00
cleanup
This commit is contained in:
parent
558b469d72
commit
9e728dc943
8 changed files with 65 additions and 52 deletions
|
@ -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)
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
use crate::{
|
||||
block_state::{BlockState, BlockStateIntegerRepr},
|
||||
Block,
|
||||
};
|
||||
use crate::block_state::{BlockState, BlockStateIntegerRepr};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct FluidState {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
@ -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.
|
||||
|
@ -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>,
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
|
@ -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);
|
||||
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
|
||||
let is_ultrawarm = world
|
||||
.registries
|
||||
.dimension_type()
|
||||
.and_then(|d| d.map.get(instance_name).and_then(|d| 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 {
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
|
|
@ -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};
|
||||
|
@ -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),
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
|
|
|
@ -72,11 +72,11 @@ pub fn travel(
|
|||
&mut physics,
|
||||
&direction,
|
||||
position,
|
||||
&attributes,
|
||||
attributes,
|
||||
sprinting,
|
||||
&on_climbable,
|
||||
on_climbable,
|
||||
pose,
|
||||
&jumping,
|
||||
jumping,
|
||||
&world,
|
||||
);
|
||||
}
|
||||
|
@ -84,6 +84,7 @@ pub fn travel(
|
|||
}
|
||||
|
||||
/// 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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue