From 9e728dc943e0f1e9d2889252a2e3544a02e2b073 Mon Sep 17 00:00:00 2001 From: mat Date: Fri, 10 Jan 2025 09:21:46 +0000 Subject: [PATCH] cleanup --- README.md | 2 +- azalea-block/src/fluid_state.rs | 5 +-- azalea-client/src/packet_handling/game.rs | 2 +- azalea-core/src/registry_holder.rs | 35 ++++++++++---------- azalea-entity/src/plugin/mod.rs | 2 +- azalea-physics/src/fluids.rs | 39 +++++++++++++++-------- azalea-physics/src/lib.rs | 14 ++++---- azalea-physics/src/travel.rs | 20 ++++++------ 8 files changed, 66 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index 992169f19..1672db69d 100755 --- a/README.md +++ b/README.md @@ -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) diff --git a/azalea-block/src/fluid_state.rs b/azalea-block/src/fluid_state.rs index 8b77bdb2b..edceac05f 100644 --- a/azalea-block/src/fluid_state.rs +++ b/azalea-block/src/fluid_state.rs @@ -1,7 +1,4 @@ -use crate::{ - block_state::{BlockState, BlockStateIntegerRepr}, - Block, -}; +use crate::block_state::{BlockState, BlockStateIntegerRepr}; #[derive(Clone, Debug)] pub struct FluidState { diff --git a/azalea-client/src/packet_handling/game.rs b/azalea-client/src/packet_handling/game.rs index 0b6d998ed..0d5a6afe3 100644 --- a/azalea-client/src/packet_handling/game.rs +++ b/azalea-client/src/packet_handling/game.rs @@ -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::().unwrap(); if new_look_direction != *look_direction { *look_direction = new_look_direction; diff --git a/azalea-core/src/registry_holder.rs b/azalea-core/src/registry_holder.rs index 8b3dd4e6a..abb7f509e 100644 --- a/azalea-core/src/registry_holder.rs +++ b/azalea-core/src/registry_holder.rs @@ -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> { + 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( &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> { - 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, #[simdnbt(flatten)] pub _extra: HashMap, } diff --git a/azalea-entity/src/plugin/mod.rs b/azalea-entity/src/plugin/mod.rs index fed146a1b..7624f0baa 100644 --- a/azalea-entity/src/plugin/mod.rs +++ b/azalea-entity/src/plugin/mod.rs @@ -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>) { 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; } } diff --git a/azalea-physics/src/fluids.rs b/azalea-physics/src/fluids.rs index 3d977a8cf..3de868cc3 100644 --- a/azalea-physics/src/fluids.rs +++ b/azalea-physics/src/fluids.rs @@ -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); - - // 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)) + == 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 diff --git a/azalea-physics/src/lib.rs b/azalea-physics/src/lib.rs index 77dde13e3..6ea4e9461 100644 --- a/azalea-physics/src/lib.rs +++ b/azalea-physics/src/lib.rs @@ -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::::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(); diff --git a/azalea-physics/src/travel.rs b/azalea-physics/src/travel.rs index c2d096868..08b598676 100644 --- a/azalea-physics/src/travel.rs +++ b/azalea-physics/src/travel.rs @@ -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,