diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2025-12-09 13:29:59 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-12-09 13:29:59 -0600 |
| commit | 26d619c9a329087a23d6577ee74bd764f50cd773 (patch) | |
| tree | 8020fe902257764a23a445c6ed9987ea4848189d /azalea-entity/src/attributes.rs | |
| parent | 84cd261118c9d1e3145d4d1751c0d22098cd8cd8 (diff) | |
| download | azalea-drasl-26d619c9a329087a23d6577ee74bd764f50cd773.tar.xz | |
Enchantments (#286)
* start implementing enchants
* store parsed registries
* more work on enchants
* implement deserializer for some entity effects
* mostly working definitions for enchants
* fix tests
* detect equipment changes
* fix errors
* update changelog
* fix some imports
* remove outdated todo
* add basic test for enchants applying attributes
* use git simdnbt
Diffstat (limited to 'azalea-entity/src/attributes.rs')
| -rw-r--r-- | azalea-entity/src/attributes.rs | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/azalea-entity/src/attributes.rs b/azalea-entity/src/attributes.rs index ca02e639..d0bd2c21 100644 --- a/azalea-entity/src/attributes.rs +++ b/azalea-entity/src/attributes.rs @@ -2,17 +2,25 @@ use std::collections::{HashMap, hash_map}; -use azalea_buf::AzBuf; -use azalea_core::identifier::Identifier; +use azalea_core::{ + attribute_modifier_operation::AttributeModifierOperation, identifier::Identifier, +}; +use azalea_inventory::components::AttributeModifier; +use azalea_registry::Attribute; use bevy_ecs::component::Component; use thiserror::Error; +/// A component that contains the current attribute values for an entity. +/// +/// Each attribute can have multiple modifiers, and these modifiers are the +/// result of things like sprinting or enchantments. #[derive(Clone, Debug, Component)] pub struct Attributes { pub movement_speed: AttributeInstance, pub sneaking_speed: AttributeInstance, pub attack_speed: AttributeInstance, pub water_movement_efficiency: AttributeInstance, + pub mining_efficiency: AttributeInstance, pub block_interaction_range: AttributeInstance, pub entity_interaction_range: AttributeInstance, @@ -20,6 +28,25 @@ pub struct Attributes { pub step_height: AttributeInstance, } +impl Attributes { + /// Returns a mutable reference to the [`AttributeInstance`] for the given + /// attribute, or `None` if the attribute isn't implemented. + pub fn get_mut(&mut self, attribute: Attribute) -> Option<&mut AttributeInstance> { + let value = match attribute { + Attribute::MovementSpeed => &mut self.movement_speed, + Attribute::SneakingSpeed => &mut self.sneaking_speed, + Attribute::AttackSpeed => &mut self.attack_speed, + Attribute::WaterMovementEfficiency => &mut self.water_movement_efficiency, + Attribute::MiningEfficiency => &mut self.mining_efficiency, + Attribute::BlockInteractionRange => &mut self.block_interaction_range, + Attribute::EntityInteractionRange => &mut self.entity_interaction_range, + Attribute::StepHeight => &mut self.step_height, + _ => return None, + }; + Some(value) + } +} + #[derive(Clone, Debug)] pub struct AttributeInstance { pub base: f64, @@ -78,20 +105,6 @@ impl AttributeInstance { } } -#[derive(Clone, Debug, AzBuf, PartialEq)] -pub struct AttributeModifier { - pub id: Identifier, - pub amount: f64, - pub operation: AttributeModifierOperation, -} - -#[derive(Clone, Debug, Copy, AzBuf, PartialEq)] -pub enum AttributeModifierOperation { - AddValue, - AddMultipliedBase, - AddMultipliedTotal, -} - pub fn sprinting_modifier() -> AttributeModifier { AttributeModifier { id: Identifier::new("sprinting"), |
