From d261888b48ab877a335185b6e3ac04595d1eb2f7 Mon Sep 17 00:00:00 2001
From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Date: Sun, 1 May 2022 09:27:07 +1200
Subject: [PATCH] Fix entity storage masks (#7844)
---
.../Components/EntityStorageComponent.cs | 37 +++++++++++--------
1 file changed, 21 insertions(+), 16 deletions(-)
diff --git a/Content.Server/Storage/Components/EntityStorageComponent.cs b/Content.Server/Storage/Components/EntityStorageComponent.cs
index 626935df9c..d247df22d2 100644
--- a/Content.Server/Storage/Components/EntityStorageComponent.cs
+++ b/Content.Server/Storage/Components/EntityStorageComponent.cs
@@ -19,15 +19,9 @@ using Content.Shared.Storage;
using Content.Shared.Tools;
using Robust.Shared.Audio;
using Robust.Shared.Containers;
-using Robust.Shared.GameObjects;
-using Robust.Shared.IoC;
-using Robust.Shared.Localization;
-using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Player;
-using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
-using Robust.Shared.ViewVariables;
namespace Content.Server.Storage.Components
{
@@ -44,11 +38,19 @@ namespace Content.Server.Storage.Components
public static readonly TimeSpan InternalOpenAttemptDelay = TimeSpan.FromSeconds(0.5);
public TimeSpan LastInternalOpenAttempt;
- private const int OpenMask = (int) (
+ ///
+ /// Collision masks that get removed when the storage gets opened.
+ ///
+ private const int MasksToRemove = (int) (
CollisionGroup.MobImpassable |
CollisionGroup.VaultImpassable |
CollisionGroup.SmallImpassable);
+ ///
+ /// Collision masks that were removed from ANY layer when the storage was opened;
+ ///
+ [DataField("removedMasks")] public int RemovedMasks;
+
[ViewVariables]
[DataField("Capacity")]
private int _storageCapacityMax = 30;
@@ -312,21 +314,24 @@ namespace Content.Server.Storage.Components
private void ModifyComponents()
{
- if (!_isCollidableWhenOpen && _entMan.TryGetComponent(Owner, out var manager))
+ if (!_isCollidableWhenOpen && _entMan.TryGetComponent(Owner, out var manager)
+ && manager.Fixtures.Count > 0)
{
+ // currently only works for single-fixture entities. If they have more than one fixture, then
+ // RemovedMasks needs to be tracked separately for each fixture, using a fixture Id Dictionary. Also the
+ // fixture IDs probably cant be automatically generated without causing issues, unless there is some
+ // guarantee that they will get deserialized with the same auto-generated ID when saving+loading the map.
+ var fixture = manager.Fixtures.Values.First();
+
if (Open)
{
- foreach (var (_, fixture) in manager.Fixtures)
- {
- fixture.CollisionLayer &= ~OpenMask;
- }
+ RemovedMasks = fixture.CollisionLayer & MasksToRemove;
+ fixture.CollisionLayer &= ~MasksToRemove;
}
else
{
- foreach (var (_, fixture) in manager.Fixtures)
- {
- fixture.CollisionLayer |= OpenMask;
- }
+ fixture.CollisionLayer |= RemovedMasks;
+ RemovedMasks = 0;
}
}