Fix inventory containers (#11944)
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user