From c8292ccbfc2bf6593b8412a91517a8dace77c674 Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Tue, 10 Jan 2023 22:57:26 +1100 Subject: [PATCH] Dont refresh movespeed in clothing handler (#13398) --- .../Clothing/ClothingSpeedModifierSystem.cs | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/Content.Shared/Clothing/ClothingSpeedModifierSystem.cs b/Content.Shared/Clothing/ClothingSpeedModifierSystem.cs index d75310ea00..4ce63fbc81 100644 --- a/Content.Shared/Clothing/ClothingSpeedModifierSystem.cs +++ b/Content.Shared/Clothing/ClothingSpeedModifierSystem.cs @@ -53,16 +53,22 @@ public sealed class ClothingSpeedModifierSystem : EntitySystem private void OnHandleState(EntityUid uid, ClothingSpeedModifierComponent component, ref ComponentHandleState args) { - if (args.Current is ClothingSpeedModifierComponentState state) - { - component.WalkModifier = state.WalkModifier; - component.SprintModifier = state.SprintModifier; - component.Enabled = state.Enabled; + if (args.Current is not ClothingSpeedModifierComponentState state) + return; - if (_container.TryGetContainingContainer(uid, out var container)) - { - _movementSpeed.RefreshMovementSpeedModifiers(container.Owner); - } + var diff = component.Enabled != state.Enabled || + !MathHelper.CloseTo(component.SprintModifier, state.SprintModifier) || + !MathHelper.CloseTo(component.WalkModifier, state.WalkModifier); + + component.WalkModifier = state.WalkModifier; + component.SprintModifier = state.SprintModifier; + component.Enabled = state.Enabled; + + // Avoid raising the event for the container if nothing changed. + // We'll still set the values in case they're slightly different but within tolerance. + if (diff && _container.TryGetContainingContainer(uid, out var container)) + { + _movementSpeed.RefreshMovementSpeedModifiers(container.Owner); } }