protected void RefRelayInventoryEvent<T>(EntityUid uid, InventoryComponent component, ref T args) where T : IInventoryRelayEvent
{
- var containerEnumerator = new ContainerSlotEnumerator(uid, component.TemplateId, _prototypeManager, this, args.TargetSlots);
+ RelayEvent((uid, component), args);
+ }
+
+ protected void RelayInventoryEvent<T>(EntityUid uid, InventoryComponent component, T args) where T : IInventoryRelayEvent
+ {
+ RelayEvent((uid, component), args);
+ }
+
+ public void RelayEvent<T>(Entity<InventoryComponent> inventory, ref T args) where T : IInventoryRelayEvent
+ {
+ var containerEnumerator = new ContainerSlotEnumerator(inventory, inventory.Comp.TemplateId, _prototypeManager, this, args.TargetSlots);
- // this copies the by-ref event
+ // this copies the by-ref event if it is a struct
var ev = new InventoryRelayedEvent<T>(args);
while (containerEnumerator.MoveNext(out var container))
{
- if (!container.ContainedEntity.HasValue) continue;
+ if (!container.ContainedEntity.HasValue)
+ continue;
+
RaiseLocalEvent(container.ContainedEntity.Value, ev);
}
args = ev.Args;
}
- protected void RelayInventoryEvent<T>(EntityUid uid, InventoryComponent component, T args) where T : IInventoryRelayEvent
+ public void RelayEvent<T>(Entity<InventoryComponent> inventory, T args) where T : IInventoryRelayEvent
{
if (args.TargetSlots == SlotFlags.NONE)
return;
- var containerEnumerator = new ContainerSlotEnumerator(uid, component.TemplateId, _prototypeManager, this, args.TargetSlots);
+ var containerEnumerator = new ContainerSlotEnumerator(inventory, inventory.Comp.TemplateId, _prototypeManager, this, args.TargetSlots);
var ev = new InventoryRelayedEvent<T>(args);
while (containerEnumerator.MoveNext(out var container))
{
- if (!container.ContainedEntity.HasValue) continue;
+ if (!container.ContainedEntity.HasValue)
+ continue;
+
RaiseLocalEvent(container.ContainedEntity.Value, ev);
}
}