Fix inventory containers (#11944)

This commit is contained in:
Leon Friedrich
2022-10-16 17:16:27 +13:00
committed by GitHub
parent 7e41a7a31d
commit 243876474c
5 changed files with 33 additions and 14 deletions

View File

@@ -1,4 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.CodeAnalysis;
using Robust.Shared.Containers;
using Robust.Shared.Prototypes;
@@ -8,6 +8,22 @@ public partial class InventorySystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
private void InitializeSlots()
{
SubscribeLocalEvent<InventoryComponent, ComponentInit>(OnInit);
}
protected virtual void OnInit(EntityUid uid, InventoryComponent component, ComponentInit args)
{
if (!_prototypeManager.TryIndex(component.TemplateId, out InventoryTemplatePrototype? invTemplate))
return;
foreach (var slot in invTemplate.Slots)
{
_containerSystem.EnsureContainer<ContainerSlot>(uid, slot.Name).OccludesLight = false;
}
}
public bool TryGetSlotContainer(EntityUid uid, string slot, [NotNullWhen(true)] out ContainerSlot? containerSlot, [NotNullWhen(true)] out SlotDefinition? slotDefinition,
InventoryComponent? inventory = null, ContainerManagerComponent? containerComp = null)
{
@@ -21,9 +37,9 @@ public partial class InventorySystem : EntitySystem
if (!containerComp.TryGetContainer(slotDefinition.Name, out var container))
{
containerSlot = containerComp.MakeContainer<ContainerSlot>(slotDefinition.Name);
containerSlot.OccludesLight = false;
return true;
if (inventory.LifeStage >= ComponentLifeStage.Initialized)
Logger.Error($"Missing inventory container {slot} on entity {ToPrettyString(uid)}");
return false;
}
if (container is not ContainerSlot containerSlotChecked) return false;