From e74ed047dbaf3877db4a89a2d589e992abd0bb11 Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Thu, 14 Aug 2025 20:40:13 -0500 Subject: Sneaking (#237) * start implementing sneaking * fix horizontal_collision being inverted and cleanup * clippy * change dimensions and eye height based on pose * proper support for automatically crouching in certain cases * fix anticheat issues * add line to changelog and update a comment --- azalea-entity/src/attributes.rs | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'azalea-entity/src/attributes.rs') 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, + // 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, } } -- cgit v1.2.3