diff --git a/Content.Server/Cabinet/ItemCabinetSystem.cs b/Content.Server/Cabinet/ItemCabinetSystem.cs index b678b523fb..7fcdbde124 100644 --- a/Content.Server/Cabinet/ItemCabinetSystem.cs +++ b/Content.Server/Cabinet/ItemCabinetSystem.cs @@ -43,7 +43,7 @@ namespace Content.Server.Cabinet private void OnComponentStartup(EntityUid uid, ItemCabinetComponent cabinet, ComponentStartup args) { UpdateAppearance(uid, cabinet); - _itemSlotsSystem.SetLock(uid, cabinet.CabinetSlot.ID, !cabinet.Opened); + _itemSlotsSystem.SetLock(uid, cabinet.CabinetSlot, !cabinet.Opened); } private void UpdateAppearance(EntityUid uid, @@ -105,7 +105,7 @@ namespace Content.Server.Cabinet cabinet.Opened = !cabinet.Opened; SoundSystem.Play(Filter.Pvs(uid), cabinet.DoorSound.GetSound(), uid, AudioHelpers.WithVariation(0.15f)); - _itemSlotsSystem.SetLock(uid, cabinet.CabinetSlot.ID, !cabinet.Opened); + _itemSlotsSystem.SetLock(uid, cabinet.CabinetSlot, !cabinet.Opened); UpdateAppearance(uid, cabinet); } diff --git a/Content.Server/Containers/EmptyOnMachineDeconstructSystem.cs b/Content.Server/Containers/EmptyOnMachineDeconstructSystem.cs index 1642319c08..7e89288f47 100644 --- a/Content.Server/Containers/EmptyOnMachineDeconstructSystem.cs +++ b/Content.Server/Containers/EmptyOnMachineDeconstructSystem.cs @@ -27,7 +27,7 @@ namespace Content.Server.Containers foreach (var slot in component.Slots.Values) { if (slot.EjectOnDeconstruct && slot.Item != null) - slot.ContainerSlot.Remove(slot.Item.Value); + slot.ContainerSlot?.Remove(slot.Item.Value); } } diff --git a/Content.Shared/Containers/ItemSlot/ItemSlotsComponent.cs b/Content.Shared/Containers/ItemSlot/ItemSlotsComponent.cs index 41cfd479cc..c385f4698e 100644 --- a/Content.Shared/Containers/ItemSlot/ItemSlotsComponent.cs +++ b/Content.Shared/Containers/ItemSlot/ItemSlotsComponent.cs @@ -156,7 +156,7 @@ namespace Content.Shared.Containers.ItemSlots public string? EjectVerbText; [ViewVariables] - public ContainerSlot ContainerSlot = default!; + public ContainerSlot? ContainerSlot = default!; /// /// If this slot belongs to some de-constructible component, should the item inside the slot be ejected upon @@ -192,10 +192,10 @@ namespace Content.Shared.Containers.ItemSlots [DataField("swap")] public bool Swap = true; - public string ID => ContainerSlot.ID; + public string? ID => ContainerSlot?.ID; // Convenience properties - public bool HasItem => ContainerSlot.ContainedEntity != null; - public EntityUid? Item => ContainerSlot.ContainedEntity; + public bool HasItem => ContainerSlot?.ContainedEntity != null; + public EntityUid? Item => ContainerSlot?.ContainedEntity; } } diff --git a/Content.Shared/Containers/ItemSlot/ItemSlotsSystem.cs b/Content.Shared/Containers/ItemSlot/ItemSlotsSystem.cs index ba5d102d98..6f753b56a3 100644 --- a/Content.Shared/Containers/ItemSlot/ItemSlotsSystem.cs +++ b/Content.Shared/Containers/ItemSlot/ItemSlotsSystem.cs @@ -61,7 +61,7 @@ namespace Content.Shared.Containers.ItemSlots continue; var item = EntityManager.SpawnEntity(slot.StartingItem, EntityManager.GetComponent(itemSlots.Owner).Coordinates); - slot.ContainerSlot.Insert(item); + slot.ContainerSlot?.Insert(item); } } @@ -95,6 +95,9 @@ namespace Content.Shared.Containers.ItemSlots /// public void RemoveItemSlot(EntityUid uid, ItemSlot slot, ItemSlotsComponent? itemSlots = null) { + if (slot.ContainerSlot == null) + return; + slot.ContainerSlot.Shutdown(); // Don't log missing resolves. when an entity has all of its components removed, the ItemSlotsComponent may @@ -102,7 +105,7 @@ namespace Content.Shared.Containers.ItemSlots if (!Resolve(uid, ref itemSlots, logMissing: false)) return; - itemSlots.Slots.Remove(slot.ID); + itemSlots.Slots.Remove(slot.ContainerSlot.ID); if (itemSlots.Slots.Count == 0) EntityManager.RemoveComponent(uid, itemSlots); @@ -193,7 +196,7 @@ namespace Content.Shared.Containers.ItemSlots /// Useful for predicted interactions private void Insert(EntityUid uid, ItemSlot slot, EntityUid item, EntityUid? user, bool excludeUserAudio = false) { - slot.ContainerSlot.Insert(item); + slot.ContainerSlot?.Insert(item); // ContainerSlot automatically raises a directed EntInsertedIntoContainerMessage PlaySound(uid, slot.InsertSound, slot.SoundOptions, excludeUserAudio ? user : null); @@ -242,7 +245,7 @@ namespace Content.Shared.Containers.ItemSlots return false; } - return slot.ContainerSlot.CanInsertIfEmpty(usedUid, EntityManager); + return slot.ContainerSlot?.CanInsertIfEmpty(usedUid, EntityManager) ?? false; } /// @@ -305,7 +308,7 @@ namespace Content.Shared.Containers.ItemSlots if (slot.Locked || slot.Item == null) return false; - return slot.ContainerSlot.CanRemove(slot.Item.Value, EntityManager); + return slot.ContainerSlot?.CanRemove(slot.Item.Value, EntityManager) ?? false; } /// @@ -316,7 +319,7 @@ namespace Content.Shared.Containers.ItemSlots /// Useful for predicted interactions private void Eject(EntityUid uid, ItemSlot slot, EntityUid item, EntityUid? user, bool excludeUserAudio = false) { - slot.ContainerSlot.Remove(item); + slot.ContainerSlot?.Remove(item); // ContainerSlot automatically raises a directed EntRemovedFromContainerMessage PlaySound(uid, slot.EjectSound, slot.SoundOptions, excludeUserAudio ? user : null); @@ -520,14 +523,17 @@ namespace Content.Shared.Containers.ItemSlots if (!itemSlots.Slots.TryGetValue(id, out var slot)) return; - SetLock(itemSlots, slot, locked); + SetLock(uid, slot, locked, itemSlots); } /// /// Lock an item slot. This stops items from being inserted into or ejected from this slot. /// - public void SetLock(ItemSlotsComponent itemSlots, ItemSlot slot, bool locked) + public void SetLock(EntityUid uid, ItemSlot slot, bool locked, ItemSlotsComponent? itemSlots = null) { + if (!Resolve(uid, ref itemSlots)) + return; + slot.Locked = locked; itemSlots.Dirty(); }