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:
@@ -0,0 +1,10 @@
|
||||
namespace Content.Server._CP14.Workbench;
|
||||
|
||||
/// <summary>
|
||||
/// Provides resources to the workbench located on ItemPlacer
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
[Access(typeof(CP14WorkbenchSystem))]
|
||||
public sealed partial class CP14WorkbenchPlaceableProviderComponent : Component
|
||||
{
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,10 +26,10 @@ public sealed partial class CP14WorkbenchSystem
|
||||
|
||||
private void UpdateUIRecipes(Entity<CP14WorkbenchComponent> entity)
|
||||
{
|
||||
if (!TryComp<ItemPlacerComponent>(entity.Owner, out var placer))
|
||||
return;
|
||||
var getResource = new CP14WorkbenchGetResourcesEvent();
|
||||
RaiseLocalEvent(entity, getResource);
|
||||
|
||||
var placedEntities = placer.PlacedEntities;
|
||||
var resources = getResource.Resources;
|
||||
|
||||
var recipes = new List<CP14WorkbenchUiRecipesEntry>();
|
||||
foreach (var recipeId in entity.Comp.Recipes)
|
||||
@@ -41,7 +41,7 @@ public sealed partial class CP14WorkbenchSystem
|
||||
|
||||
foreach (var requirement in indexedRecipe.Requirements)
|
||||
{
|
||||
if (!requirement.CheckRequirement(EntityManager, _proto, placedEntities))
|
||||
if (!requirement.CheckRequirement(EntityManager, _proto, resources))
|
||||
{
|
||||
canCraft = false;
|
||||
break;
|
||||
|
||||
@@ -33,6 +33,7 @@ public sealed partial class CP14WorkbenchSystem : CP14SharedWorkbenchSystem
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
InitProviders();
|
||||
|
||||
SubscribeLocalEvent<CP14WorkbenchComponent, MapInitEvent>(OnMapInit);
|
||||
|
||||
@@ -82,11 +83,12 @@ public sealed partial class CP14WorkbenchSystem : CP14SharedWorkbenchSystem
|
||||
if (!_proto.TryIndex(args.Recipe, out var recipe))
|
||||
return;
|
||||
|
||||
var placedEntities = _lookup.GetEntitiesInRange(Transform(ent).Coordinates,
|
||||
ent.Comp.WorkbenchRadius,
|
||||
LookupFlags.Uncontained);
|
||||
var getResource = new CP14WorkbenchGetResourcesEvent();
|
||||
RaiseLocalEvent(ent.Owner, getResource);
|
||||
|
||||
if (!CanCraftRecipe(recipe, placedEntities, args.User))
|
||||
var resources = getResource.Resources;
|
||||
|
||||
if (!CanCraftRecipe(recipe, resources, args.User))
|
||||
{
|
||||
_popup.PopupEntity(Loc.GetString("cp14-workbench-cant-craft"), ent, args.User);
|
||||
return;
|
||||
@@ -106,7 +108,7 @@ public sealed partial class CP14WorkbenchSystem : CP14SharedWorkbenchSystem
|
||||
|
||||
foreach (var req in recipe.Requirements)
|
||||
{
|
||||
req.PostCraft(EntityManager, _proto, placedEntities);
|
||||
req.PostCraft(EntityManager, _proto, resources);
|
||||
}
|
||||
|
||||
if (passConditions)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,10 +1,10 @@
|
||||
meta:
|
||||
format: 7
|
||||
category: Map
|
||||
engineVersion: 262.0.0
|
||||
engineVersion: 264.0.0
|
||||
forkId: ""
|
||||
forkVersion: ""
|
||||
time: 07/06/2025 09:42:48
|
||||
time: 07/11/2025 11:55:54
|
||||
entityCount: 23414
|
||||
maps:
|
||||
- 1
|
||||
@@ -100462,61 +100462,51 @@ entities:
|
||||
- uid: 19835
|
||||
components:
|
||||
- type: Transform
|
||||
rot: -1.5707963267948966 rad
|
||||
pos: -1.5,-18.5
|
||||
parent: 1
|
||||
- uid: 19836
|
||||
components:
|
||||
- type: Transform
|
||||
rot: -1.5707963267948966 rad
|
||||
pos: -0.5,-17.5
|
||||
parent: 1
|
||||
- uid: 19837
|
||||
components:
|
||||
- type: Transform
|
||||
rot: -1.5707963267948966 rad
|
||||
pos: -2.5,-19.5
|
||||
parent: 1
|
||||
- uid: 19838
|
||||
components:
|
||||
- type: Transform
|
||||
rot: -1.5707963267948966 rad
|
||||
pos: -2.5,-20.5
|
||||
parent: 1
|
||||
- uid: 19839
|
||||
components:
|
||||
- type: Transform
|
||||
rot: -1.5707963267948966 rad
|
||||
pos: -2.5,-18.5
|
||||
parent: 1
|
||||
- uid: 19840
|
||||
components:
|
||||
- type: Transform
|
||||
rot: -1.5707963267948966 rad
|
||||
pos: -1.5,-17.5
|
||||
parent: 1
|
||||
- uid: 19841
|
||||
components:
|
||||
- type: Transform
|
||||
rot: -1.5707963267948966 rad
|
||||
pos: 0.5,-17.5
|
||||
parent: 1
|
||||
- uid: 19842
|
||||
components:
|
||||
- type: Transform
|
||||
rot: -1.5707963267948966 rad
|
||||
pos: 0.5,-18.5
|
||||
parent: 1
|
||||
- uid: 19843
|
||||
components:
|
||||
- type: Transform
|
||||
rot: -1.5707963267948966 rad
|
||||
pos: 1.5,-18.5
|
||||
parent: 1
|
||||
- uid: 19844
|
||||
components:
|
||||
- type: Transform
|
||||
rot: -1.5707963267948966 rad
|
||||
pos: 0.5,-19.5
|
||||
parent: 1
|
||||
- uid: 19845
|
||||
@@ -100617,13 +100607,11 @@ entities:
|
||||
- uid: 19864
|
||||
components:
|
||||
- type: Transform
|
||||
rot: -1.5707963267948966 rad
|
||||
pos: -0.5,-19.5
|
||||
parent: 1
|
||||
- uid: 19865
|
||||
components:
|
||||
- type: Transform
|
||||
rot: -1.5707963267948966 rad
|
||||
pos: -0.5,-20.5
|
||||
parent: 1
|
||||
- uid: 19866
|
||||
@@ -100739,31 +100727,26 @@ entities:
|
||||
- uid: 19888
|
||||
components:
|
||||
- type: Transform
|
||||
rot: -1.5707963267948966 rad
|
||||
pos: -4.5,-19.5
|
||||
parent: 1
|
||||
- uid: 19889
|
||||
components:
|
||||
- type: Transform
|
||||
rot: -1.5707963267948966 rad
|
||||
pos: -3.5,-20.5
|
||||
parent: 1
|
||||
- uid: 19890
|
||||
components:
|
||||
- type: Transform
|
||||
rot: -1.5707963267948966 rad
|
||||
pos: -4.5,-18.5
|
||||
parent: 1
|
||||
- uid: 19891
|
||||
components:
|
||||
- type: Transform
|
||||
rot: -1.5707963267948966 rad
|
||||
pos: -3.5,-17.5
|
||||
parent: 1
|
||||
- uid: 19892
|
||||
components:
|
||||
- type: Transform
|
||||
rot: -1.5707963267948966 rad
|
||||
pos: 1.5,-19.5
|
||||
parent: 1
|
||||
- uid: 19893
|
||||
@@ -100774,37 +100757,31 @@ entities:
|
||||
- uid: 19894
|
||||
components:
|
||||
- type: Transform
|
||||
rot: -1.5707963267948966 rad
|
||||
pos: -2.5,-17.5
|
||||
parent: 1
|
||||
- uid: 19895
|
||||
components:
|
||||
- type: Transform
|
||||
rot: -1.5707963267948966 rad
|
||||
pos: -3.5,-19.5
|
||||
parent: 1
|
||||
- uid: 19896
|
||||
components:
|
||||
- type: Transform
|
||||
rot: -1.5707963267948966 rad
|
||||
pos: -3.5,-18.5
|
||||
parent: 1
|
||||
- uid: 19897
|
||||
components:
|
||||
- type: Transform
|
||||
rot: -1.5707963267948966 rad
|
||||
pos: -1.5,-19.5
|
||||
parent: 1
|
||||
- uid: 19898
|
||||
components:
|
||||
- type: Transform
|
||||
rot: -1.5707963267948966 rad
|
||||
pos: -1.5,-20.5
|
||||
parent: 1
|
||||
- uid: 19899
|
||||
components:
|
||||
- type: Transform
|
||||
rot: -1.5707963267948966 rad
|
||||
pos: -0.5,-18.5
|
||||
parent: 1
|
||||
- uid: 19900
|
||||
@@ -100815,13 +100792,11 @@ entities:
|
||||
- uid: 19901
|
||||
components:
|
||||
- type: Transform
|
||||
rot: -1.5707963267948966 rad
|
||||
pos: -4.5,-20.5
|
||||
parent: 1
|
||||
- uid: 19902
|
||||
components:
|
||||
- type: Transform
|
||||
rot: -1.5707963267948966 rad
|
||||
pos: -5.5,-19.5
|
||||
parent: 1
|
||||
- uid: 19903
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -55,6 +55,7 @@
|
||||
min: 1
|
||||
max: 2
|
||||
- type: PlaceableSurface
|
||||
- type: CP14WorkbenchPlaceableProvider
|
||||
- type: ItemPlacer
|
||||
maxEntities: 0
|
||||
- type: Fixtures
|
||||
|
||||
Reference in New Issue
Block a user