Files
crystall-punk-14/Content.Server/_CP14/Workbench/CP14WorkbenchSystem.Provider.cs
Red 37ece7228f Refactor workbench resource handling with provider component (#1522)
* Refactor workbench resource handling with provider component

Introduces CP14WorkbenchPlaceableProviderComponent and related event to abstract resource provision for workbenches. Updates system logic to use the new provider event instead of directly accessing ItemPlacerComponent, improving modularity and extensibility. Adjusts entity prototype to include the new provider component.

* map resave

* resave Frigid
2025-07-11 15:55:41 +03:00

38 lines
979 B
C#

using Content.Shared.Placeable;
namespace Content.Server._CP14.Workbench;
public sealed partial class CP14WorkbenchSystem
{
private void InitProviders()
{
SubscribeLocalEvent<CP14WorkbenchPlaceableProviderComponent, CP14WorkbenchGetResourcesEvent>(OnGetResource);
}
private void OnGetResource(Entity<CP14WorkbenchPlaceableProviderComponent> ent, ref CP14WorkbenchGetResourcesEvent args)
{
if (!TryComp<ItemPlacerComponent>(ent, out var placer))
return;
args.AddResources(placer.PlacedEntities);
}
}
public sealed class CP14WorkbenchGetResourcesEvent : EntityEventArgs
{
public HashSet<EntityUid> Resources { get; private set; } = new();
public void AddResource(EntityUid resource)
{
Resources.Add(resource);
}
public void AddResources(IEnumerable<EntityUid> resources)
{
foreach (var resource in resources)
{
Resources.Add(resource);
}
}
}