Fix debug asserts in WoolySystem and UdderSystem (#35314)

This commit is contained in:
Tayrtahn
2025-05-08 03:55:41 -04:00
committed by GitHub
parent 4a521c56cf
commit 4aa635620c
2 changed files with 24 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ using Content.Shared.Nutrition.EntitySystems;
using Content.Shared.Popups;
using Content.Shared.Udder;
using Content.Shared.Verbs;
using Robust.Shared.Containers;
using Robust.Shared.Timing;
namespace Content.Shared.Animals;
@@ -31,6 +32,7 @@ public sealed class UdderSystem : EntitySystem
SubscribeLocalEvent<UdderComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<UdderComponent, GetVerbsEvent<AlternativeVerb>>(AddMilkVerb);
SubscribeLocalEvent<UdderComponent, MilkingDoAfterEvent>(OnDoAfter);
SubscribeLocalEvent<UdderComponent, EntRemovedFromContainerMessage>(OnEntRemoved);
}
private void OnMapInit(EntityUid uid, UdderComponent component, MapInitEvent args)
@@ -38,6 +40,16 @@ public sealed class UdderSystem : EntitySystem
component.NextGrowth = _timing.CurTime + component.GrowthDelay;
}
private void OnEntRemoved(Entity<UdderComponent> entity, ref EntRemovedFromContainerMessage args)
{
// Make sure the removed entity was our contained solution
if (entity.Comp.Solution == null || args.Entity != entity.Comp.Solution.Value.Owner)
return;
// Cleared our cached reference to the solution entity
entity.Comp.Solution = null;
}
public override void Update(float frameTime)
{
base.Update(frameTime);

View File

@@ -3,6 +3,7 @@ using Content.Shared.Mobs.Systems;
using Content.Shared.Nutrition;
using Content.Shared.Nutrition.Components;
using Content.Shared.Nutrition.EntitySystems;
using Robust.Shared.Containers;
using Robust.Shared.Timing;
namespace Content.Shared.Animals;
@@ -24,6 +25,7 @@ public sealed class WoolySystem : EntitySystem
SubscribeLocalEvent<WoolyComponent, BeforeFullyEatenEvent>(OnBeforeFullyEaten);
SubscribeLocalEvent<WoolyComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<WoolyComponent, EntRemovedFromContainerMessage>(OnEntRemoved);
}
private void OnMapInit(EntityUid uid, WoolyComponent component, MapInitEvent args)
@@ -31,6 +33,16 @@ public sealed class WoolySystem : EntitySystem
component.NextGrowth = _timing.CurTime + component.GrowthDelay;
}
private void OnEntRemoved(Entity<WoolyComponent> entity, ref EntRemovedFromContainerMessage args)
{
// Make sure the removed entity was our contained solution
if (entity.Comp.Solution == null || args.Entity != entity.Comp.Solution.Value.Owner)
return;
// Clear our cached reference to the solution entity
entity.Comp.Solution = null;
}
public override void Update(float frameTime)
{
base.Update(frameTime);