Fix items deletion on recycling for entities with ItemSlotsComponent (#44486)

* Fix items deletion on recycling for entities with `ItemSlotsComponent`

* Make it to be dependent on `DestructionEvent` instead

* Revert testing changes

* Actual proto fix

* Fix some other recyclable prototypes with ItemSlots
This commit is contained in:
MilenVolf 2026-07-10 22:49:22 +03:00 • committed by GitHub
parent bea946d516
commit bc9a9207c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 30 additions and 11 deletions

View file

@ -169,6 +169,8 @@ public sealed partial class MaterialReclaimerSystem : SharedMaterialReclaimerSys
SpawnChemicalsFromComposition(uid, item, completion, true, component, xform);
}
var eventArgs = new DestructionEventArgs();
RaiseLocalEvent(item, eventArgs);
QueueDel(item);
}

View file

@ -7,6 +7,7 @@ using Content.Shared.Hands.Components;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using Content.Shared.Materials;
using Content.Shared.Popups;
using Content.Shared.Verbs;
using Content.Shared.Whitelist;
@ -621,6 +622,29 @@ namespace Content.Shared.Containers.ItemSlots
return true;
}
/// <summary>
/// Unlocks all slots and ejects items from them on the floor.
/// </summary>
public void EjectFromAllSlots(Entity<ItemSlotsComponent> entity)
{
EjectFromAllSlots(entity, _ => true);
}
/// <summary>
/// Unlocks all slots and ejects items from them on the floor. Works only while <paramref name="shouldEject"/> returns true.
/// </summary>
private void EjectFromAllSlots(Entity<ItemSlotsComponent> entity, Func<ItemSlot, bool> shouldEject)
{
foreach (var slot in entity.Comp.Slots.Values)
{
if (slot.HasItem && shouldEject(slot))
{
SetLock(entity.Owner, slot, false, entity.Comp);
TryEject(entity.Owner, slot, null, out _);
}
}
}
#endregion
#region Verbs
@ -826,14 +850,7 @@ namespace Content.Shared.Containers.ItemSlots
/// </summary>
private void OnBreak(EntityUid uid, ItemSlotsComponent component, EntityEventArgs args)
{
foreach (var slot in component.Slots.Values)
{
if (slot.EjectOnBreak && slot.HasItem)
{
SetLock(uid, slot, false, component);
TryEject(uid, slot, null, out var _);
}
}
EjectFromAllSlots((uid, component), slot => slot.EjectOnBreak);
}
/// <summary>

View file

@ -21,6 +21,7 @@
ejectVerbText: sheath-eject-verb
insertSound: /Audio/Items/sheath.ogg
ejectSound: /Audio/Items/unsheath.ogg
ejectOnBreak: true
whitelist:
tags:
- CaptainSabre

View file

@ -49,6 +49,7 @@
item:
name: clothing-boots-sidearm
priority: 4
ejectOnBreak: true
whitelist:
tags:
- Knife

View file

@ -19,6 +19,7 @@
slots:
item:
name: clothing-boots-sidearm
ejectOnBreak: true
whitelist:
tags:
- ToyKnife

View file

@ -54,7 +54,6 @@
name: id-card-console-privileged-id
ejectSound: /Audio/Machines/id_swipe.ogg
insertSound: /Audio/Weapons/Guns/MagIn/batrifle_magin.ogg
ejectOnBreak: true
swap: false
whitelist:
components:
@ -136,7 +135,6 @@
startingItem: UniversalIDCard
ejectSound: /Audio/Machines/id_swipe.ogg
insertSound: /Audio/Weapons/Guns/MagIn/batrifle_magin.ogg
ejectOnBreak: true
swap: false
whitelist:
components:
@ -164,7 +162,6 @@
startingItem: XenoborgIDCard
ejectSound: /Audio/Machines/id_swipe.ogg
insertSound: /Audio/Weapons/Guns/MagIn/batrifle_magin.ogg
ejectOnBreak: true
disableEject: true
swap: false
whitelist: