From dabf3d1521fc077df00256cbb04414632ff59010 Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Wed, 19 Jun 2024 07:47:19 +1000 Subject: [PATCH] Fix material storage going BRRT (#29167) If the volume hits 0 we just remove it. --- Content.Client/Lathe/UI/LatheMenu.xaml.cs | 3 --- .../Materials/SharedMaterialStorageSystem.cs | 12 ++++++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Content.Client/Lathe/UI/LatheMenu.xaml.cs b/Content.Client/Lathe/UI/LatheMenu.xaml.cs index 9e15f8239e..40f553fcd6 100644 --- a/Content.Client/Lathe/UI/LatheMenu.xaml.cs +++ b/Content.Client/Lathe/UI/LatheMenu.xaml.cs @@ -78,9 +78,6 @@ public sealed partial class LatheMenu : DefaultWindow /// public void PopulateRecipes() { - if (!_entityManager.TryGetComponent(_owner, out var component)) - return; - var recipesToShow = new List(); foreach (var recipe in Recipes) { diff --git a/Content.Shared/Materials/SharedMaterialStorageSystem.cs b/Content.Shared/Materials/SharedMaterialStorageSystem.cs index a27e0fb9cf..dc4858fd74 100644 --- a/Content.Shared/Materials/SharedMaterialStorageSystem.cs +++ b/Content.Shared/Materials/SharedMaterialStorageSystem.cs @@ -1,11 +1,13 @@ using System.Linq; using Content.Shared.Interaction; using Content.Shared.Interaction.Components; +using Content.Shared.Mobs; using Content.Shared.Stacks; using Content.Shared.Whitelist; using JetBrains.Annotations; using Robust.Shared.Prototypes; using Robust.Shared.Timing; +using Robust.Shared.Utility; namespace Content.Shared.Materials; @@ -166,8 +168,14 @@ public abstract class SharedMaterialStorageSystem : EntitySystem return false; if (!CanChangeMaterialAmount(uid, materialId, volume, component)) return false; - component.Storage.TryAdd(materialId, 0); - component.Storage[materialId] += volume; + + var existing = component.Storage.GetOrNew(materialId); + existing += volume; + + if (existing == 0) + component.Storage.Remove(materialId); + else + component.Storage[materialId] = existing; var ev = new MaterialAmountChangedEvent(); RaiseLocalEvent(uid, ref ev);