aboutsummaryrefslogtreecommitdiff
path: root/azalea-entity/src/attributes.rs
diff options
context:
space:
mode:
Diffstat (limited to 'azalea-entity/src/attributes.rs')
-rw-r--r--azalea-entity/src/attributes.rs34
1 files changed, 18 insertions, 16 deletions
diff --git a/azalea-entity/src/attributes.rs b/azalea-entity/src/attributes.rs
index c2a22e9b..021fcd56 100644
--- a/azalea-entity/src/attributes.rs
+++ b/azalea-entity/src/attributes.rs
@@ -9,23 +9,26 @@ use thiserror::Error;
#[derive(Clone, Debug, Component)]
pub struct Attributes {
- pub speed: AttributeInstance,
+ pub movement_speed: AttributeInstance,
pub sneaking_speed: AttributeInstance,
pub attack_speed: AttributeInstance,
pub water_movement_efficiency: AttributeInstance,
pub block_interaction_range: AttributeInstance,
pub entity_interaction_range: AttributeInstance,
+
+ pub step_height: AttributeInstance,
}
#[derive(Clone, Debug)]
pub struct AttributeInstance {
pub base: f64,
modifiers_by_id: HashMap<ResourceLocation, AttributeModifier>,
+ // TODO: add cache
}
#[derive(Clone, Debug, Error)]
-#[error("A modifier with this UUID is already present.")]
+#[error("A modifier with this ID is already present.")]
pub struct AlreadyPresentError;
impl AttributeInstance {
@@ -40,13 +43,12 @@ impl AttributeInstance {
let mut total = self.base;
for modifier in self.modifiers_by_id.values() {
match modifier.operation {
- AttributeModifierOperation::Addition => total += modifier.amount,
- AttributeModifierOperation::MultiplyBase => total += self.base * modifier.amount,
- _ => {}
- }
- if let AttributeModifierOperation::MultiplyTotal = modifier.operation {
- total *= 1.0 + modifier.amount;
- }
+ AttributeModifierOperation::AddValue => total += modifier.amount,
+ AttributeModifierOperation::AddMultipliedBase => {
+ total += modifier.amount * self.base
+ }
+ AttributeModifierOperation::AddMultipliedTotal => total *= 1. + modifier.amount,
+ };
}
total
}
@@ -85,30 +87,30 @@ pub struct AttributeModifier {
#[derive(Clone, Debug, Copy, AzBuf)]
pub enum AttributeModifierOperation {
- Addition,
- MultiplyBase,
- MultiplyTotal,
+ AddValue,
+ AddMultipliedBase,
+ AddMultipliedTotal,
}
pub fn sprinting_modifier() -> AttributeModifier {
AttributeModifier {
id: ResourceLocation::new("sprinting"),
amount: 0.3f32 as f64,
- operation: AttributeModifierOperation::MultiplyTotal,
+ operation: AttributeModifierOperation::AddMultipliedTotal,
}
}
pub fn base_attack_speed_modifier(amount: f64) -> AttributeModifier {
AttributeModifier {
id: ResourceLocation::new("base_attack_speed"),
amount,
- operation: AttributeModifierOperation::Addition,
+ operation: AttributeModifierOperation::AddValue,
}
}
pub fn creative_block_interaction_range_modifier() -> AttributeModifier {
AttributeModifier {
id: ResourceLocation::new("creative_mode_block_range"),
amount: 0.5,
- operation: AttributeModifierOperation::Addition,
+ operation: AttributeModifierOperation::AddValue,
}
}
@@ -116,6 +118,6 @@ pub fn creative_entity_interaction_range_modifier() -> AttributeModifier {
AttributeModifier {
id: ResourceLocation::new("creative_mode_entity_range"),
amount: 2.0,
- operation: AttributeModifierOperation::Addition,
+ operation: AttributeModifierOperation::AddValue,
}
}