Fix ServerStorageComponent making bad assumptions about GetEntity/GetComponent.

It assumed they returned null instead of throwing, and had wrong/invalid logic as a result.
This commit is contained in:
Vera Aguilera Puerto
2021-10-02 11:21:25 +02:00
parent 48c9f0d646
commit 2992bd74cd

View File

@@ -374,7 +374,7 @@ namespace Content.Server.Storage.Components
base.Initialize();
// ReSharper disable once StringLiteralTypo
_storage = ContainerHelpers.EnsureContainer<Container>(Owner, "storagebase");
_storage = Owner.EnsureContainer<Container>("storagebase");
_storage.OccludesLight = _occludesLight;
}
@@ -409,15 +409,12 @@ namespace Content.Server.Storage.Components
break;
}
var entity = Owner.EntityManager.GetEntity(remove.EntityUid);
if (entity == null || _storage?.Contains(entity) == false)
if (!Owner.EntityManager.TryGetEntity(remove.EntityUid, out var entity) || _storage?.Contains(entity) == false)
{
break;
}
var item = entity.GetComponent<ItemComponent>();
if (item == null || !player.TryGetComponent(out HandsComponent? hands))
if (!entity.TryGetComponent(out ItemComponent? item) || !player.TryGetComponent(out HandsComponent? hands))
{
break;
}