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
This commit is contained in:
Red
2025-07-11 15:55:41 +03:00
committed by GitHub
parent 932fd47861
commit 37ece7228f
10 changed files with 4716 additions and 7251 deletions

View File

@@ -0,0 +1,37 @@
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);
}
}
}