CatStation/Content.Server/Nutrition/EntitySystems/TrashOnSolutionEmptySystem.cs
Pieter-Jan Briers 5168b5f3d4
IoC source gen compatibility (#43863)
* IoC source gen compatibility

Can be merged before or after https://github.com/space-wizards/RobustToolbox/pull/6549 doesn't really matter.

* Missed a spot
2026-05-09 03:29:58 +00:00

51 lines
1.8 KiB
C#

using Content.Server.Nutrition.Components;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Components.SolutionManager;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Tag;
using Robust.Shared.Prototypes;
namespace Content.Server.Nutrition.EntitySystems
{
public sealed partial class TrashOnSolutionEmptySystem : EntitySystem
{
[Dependency] private SharedSolutionContainerSystem _solutionContainerSystem = default!;
[Dependency] private TagSystem _tagSystem = default!;
private static readonly ProtoId<TagPrototype> TrashTag = "Trash";
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<TrashOnSolutionEmptyComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<TrashOnSolutionEmptyComponent, SolutionChangedEvent>(OnSolutionChange);
}
public void OnMapInit(Entity<TrashOnSolutionEmptyComponent> entity, ref MapInitEvent args)
{
CheckSolutions(entity);
}
public void OnSolutionChange(Entity<TrashOnSolutionEmptyComponent> entity, ref SolutionChangedEvent args)
{
CheckSolutions(entity);
}
public void CheckSolutions(Entity<TrashOnSolutionEmptyComponent> entity)
{
if (_solutionContainerSystem.TryGetSolution(entity.Owner, entity.Comp.Solution, out _, out var solution))
UpdateTags(entity, solution);
}
public void UpdateTags(Entity<TrashOnSolutionEmptyComponent> entity, Solution solution)
{
if (solution.Volume <= 0)
{
_tagSystem.AddTag(entity.Owner, TrashTag);
return;
}
_tagSystem.RemoveTag(entity.Owner, TrashTag);
}
}
}