diff --git a/Content.Client/Clothing/ClothingVisualsSystem.cs b/Content.Client/Clothing/ClothingVisualsSystem.cs index aecf94eabd..304a3cc5c7 100644 --- a/Content.Client/Clothing/ClothingVisualsSystem.cs +++ b/Content.Client/Clothing/ClothingVisualsSystem.cs @@ -172,7 +172,8 @@ public sealed class ClothingVisualsSystem : EntitySystem public void InitClothing(EntityUid uid, ClientInventoryComponent? component = null, SpriteComponent? sprite = null) { - if (!_inventorySystem.TryGetSlots(uid, out var slots, component) || !Resolve(uid, ref sprite, ref component)) return; + if (!Resolve(uid, ref sprite, ref component) || !_inventorySystem.TryGetSlots(uid, out var slots, component)) + return; foreach (var slot in slots) { diff --git a/Content.Client/Inventory/ClientInventorySystem.cs b/Content.Client/Inventory/ClientInventorySystem.cs index 99eccc52de..4db601abea 100644 --- a/Content.Client/Inventory/ClientInventorySystem.cs +++ b/Content.Client/Inventory/ClientInventorySystem.cs @@ -43,7 +43,6 @@ namespace Content.Client.Inventory SubscribeLocalEvent(OnPlayerAttached); SubscribeLocalEvent(OnPlayerDetached); - SubscribeLocalEvent(OnInit); SubscribeLocalEvent(OnShutdown); SubscribeLocalEvent((_, comp, args) => @@ -145,16 +144,17 @@ namespace Content.Client.Inventory base.Shutdown(); } - private void OnInit(EntityUid uid, ClientInventoryComponent component, ComponentInit args) + protected override void OnInit(EntityUid uid, InventoryComponent component, ComponentInit args) { - _clothingVisualsSystem.InitClothing(uid, component); + base.OnInit(uid, component, args); + _clothingVisualsSystem.InitClothing(uid, (ClientInventoryComponent) component); if (!_prototypeManager.TryIndex(component.TemplateId, out InventoryTemplatePrototype? invTemplate)) return; foreach (var slot in invTemplate.Slots) { - TryAddSlotDef(uid, component, slot); + TryAddSlotDef(uid, (ClientInventoryComponent)component, slot); } } @@ -191,7 +191,6 @@ namespace Content.Client.Inventory if (!component.SlotData.TryAdd(newSlotDef.Name, newSlotData)) return false; - if (owner == _playerManager.LocalPlayer?.ControlledEntity) OnSlotAdded?.Invoke(newSlotData); return true; @@ -283,6 +282,8 @@ namespace Content.Client.Inventory public EntityUid? HeldEntity => Container?.ContainedEntity; public bool Blocked; public bool Highlighted; + + [ViewVariables] public ContainerSlot? Container; public bool HasSlotGroup => SlotDef.SlotGroup != "Default"; public Vector2i ButtonOffset => SlotDef.UIWindowPosition; diff --git a/Content.IntegrationTests/Tests/DeleteInventoryTest.cs b/Content.IntegrationTests/Tests/DeleteInventoryTest.cs index 0bc69de7ea..5efc6912da 100644 --- a/Content.IntegrationTests/Tests/DeleteInventoryTest.cs +++ b/Content.IntegrationTests/Tests/DeleteInventoryTest.cs @@ -33,11 +33,11 @@ namespace Content.IntegrationTests.Tests var entMgr = IoCManager.Resolve(); var container = entMgr.SpawnEntity(null, MapCoordinates.Nullspace); - entMgr.AddComponent(container); - entMgr.AddComponent(container); + entMgr.EnsureComponent(container); + entMgr.EnsureComponent(container); var child = entMgr.SpawnEntity(null, MapCoordinates.Nullspace); - var item = entMgr.AddComponent(child); + var item = entMgr.EnsureComponent(child); IoCManager.Resolve().GetEntitySystem().SetSlots(item.Owner, SlotFlags.HEAD, item); diff --git a/Content.Shared/Inventory/InventorySystem.Slots.cs b/Content.Shared/Inventory/InventorySystem.Slots.cs index 571988bcce..b251720046 100644 --- a/Content.Shared/Inventory/InventorySystem.Slots.cs +++ b/Content.Shared/Inventory/InventorySystem.Slots.cs @@ -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(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(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(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; diff --git a/Content.Shared/Inventory/InventorySystem.cs b/Content.Shared/Inventory/InventorySystem.cs index 906133e5ad..b50f17c2d1 100644 --- a/Content.Shared/Inventory/InventorySystem.cs +++ b/Content.Shared/Inventory/InventorySystem.cs @@ -1,4 +1,4 @@ -namespace Content.Shared.Inventory; +namespace Content.Shared.Inventory; public partial class InventorySystem { @@ -8,5 +8,6 @@ public partial class InventorySystem base.Initialize(); InitializeEquip(); InitializeRelay(); + InitializeSlots(); } }