diff options
| author | ShayBox <shaybox@shaybox.com> | 2025-10-30 12:14:19 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-30 11:14:19 -0500 |
| commit | 818f2d01d49e574946d1a704e1445156afc9c2fb (patch) | |
| tree | 4190ce61994e7d1280cbcd6b43811fa9f6b03b09 /azalea-physics/src | |
| parent | c7cc381fae569f3dfc9f2abe86c2c38d59b68cf2 (diff) | |
| download | azalea-drasl-818f2d01d49e574946d1a704e1445156afc9c2fb.tar.xz | |
Add support for mob effects (#269)
* Add support for mob effects
* Remove Option
* MobEffectFlags
* jump_boost_power f32
Diffstat (limited to 'azalea-physics/src')
| -rw-r--r-- | azalea-physics/src/lib.rs | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/azalea-physics/src/lib.rs b/azalea-physics/src/lib.rs index ab9c2084..e3b95484 100644 --- a/azalea-physics/src/lib.rs +++ b/azalea-physics/src/lib.rs @@ -16,11 +16,11 @@ use azalea_core::{ tick::GameTick, }; use azalea_entity::{ - Attributes, EntityKindComponent, HasClientLoaded, Jumping, LocalEntity, LookDirection, - OnClimbable, Physics, Pose, Position, dimensions::EntityDimensions, metadata::Sprinting, - move_relative, + ActiveEffects, Attributes, EntityKindComponent, HasClientLoaded, Jumping, LocalEntity, + LookDirection, OnClimbable, Physics, Pose, Position, dimensions::EntityDimensions, + metadata::Sprinting, move_relative, }; -use azalea_registry::{Block, EntityKind}; +use azalea_registry::{Block, EntityKind, MobEffect}; use azalea_world::{Instance, InstanceContainer, InstanceName}; use bevy_app::{App, Plugin, Update}; use bevy_ecs::prelude::*; @@ -70,6 +70,7 @@ pub fn ai_step( &Position, &LookDirection, &Sprinting, + &ActiveEffects, &InstanceName, &EntityKindComponent, ), @@ -77,8 +78,16 @@ pub fn ai_step( >, instance_container: Res<InstanceContainer>, ) { - for (mut physics, jumping, position, look_direction, sprinting, instance_name, entity_kind) in - &mut query + for ( + mut physics, + jumping, + position, + look_direction, + sprinting, + active_effects, + instance_name, + entity_kind, + ) in &mut query { let is_player = **entity_kind == EntityKind::Player; @@ -140,6 +149,7 @@ pub fn ai_step( *sprinting, instance_name, &instance_container, + active_effects, ); physics.no_jump_delay = 10; } @@ -331,17 +341,19 @@ pub fn jump_from_ground( sprinting: Sprinting, instance_name: &InstanceName, instance_container: &InstanceContainer, + active_effects: &ActiveEffects, ) { let world_lock = instance_container .get(instance_name) .expect("All entities should be in a valid world"); let world = world_lock.read(); - let jump_power: f64 = jump_power(&world, position) as f64 + jump_boost_power(); + let base_jump = jump_power(&world, position); + let jump_power = base_jump + jump_boost_power(active_effects); let old_delta_movement = physics.velocity; physics.velocity = Vec3 { x: old_delta_movement.x, - y: jump_power, + y: f64::from(jump_power), z: old_delta_movement.z, }; if *sprinting { @@ -504,16 +516,9 @@ fn jump_power(world: &Instance, position: Position) -> f32 { 0.42 * block_jump_factor(world, position) } -fn jump_boost_power() -> f64 { - // TODO: potion effects - // if let Some(effects) = entity.effects() { - // if let Some(jump_effect) = effects.get(&Effect::Jump) { - // 0.1 * (jump_effect.amplifier + 1) as f32 - // } else { - // 0. - // } - // } else { - // 0. - // } - 0. +fn jump_boost_power(active_effects: &ActiveEffects) -> f32 { + active_effects + .get_level(MobEffect::JumpBoost) + .map(|level| 0.1 * (level + 1) as f32) + .unwrap_or(0.) } |
