* 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
38 lines
979 B
C#
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);
|
|
}
|
|
}
|
|
}
|