From c7b9a76342d03681bcd61b0610ed2c2b270f7143 Mon Sep 17 00:00:00 2001 From: SlamBamActionman <83650252+SlamBamActionman@users.noreply.github.com> Date: Thu, 27 Feb 2025 18:43:56 +0100 Subject: [PATCH] Prevent crates, pet carriers and other things from going into disposals (#35557) * Initial commit * Solve underlying bug, readd to disposals * Apply suggestions from code review --------- Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> --- .../Containers/ThrowInsertContainerSystem.cs | 13 ++++++++++ .../Unit/EntitySystems/DisposalUnitSystem.cs | 9 +++++++ .../SharedEntityStorageSystem.cs | 25 ++++++++++--------- .../Entities/Structures/Furniture/toilet.yml | 1 + .../Structures/Piping/Disposal/units.yml | 3 +++ 5 files changed, 39 insertions(+), 12 deletions(-) diff --git a/Content.Server/Containers/ThrowInsertContainerSystem.cs b/Content.Server/Containers/ThrowInsertContainerSystem.cs index cbaec7f5c6..09176c423c 100644 --- a/Content.Server/Containers/ThrowInsertContainerSystem.cs +++ b/Content.Server/Containers/ThrowInsertContainerSystem.cs @@ -30,6 +30,12 @@ public sealed class ThrowInsertContainerSystem : EntitySystem if (!_containerSystem.CanInsert(args.Thrown, container)) return; + var beforeThrowArgs = new BeforeThrowInsertEvent(args.Thrown); + RaiseLocalEvent(ent, ref beforeThrowArgs); + + if (beforeThrowArgs.Cancelled) + return; + if (_random.Prob(ent.Comp.Probability)) { _audio.PlayPvs(ent.Comp.MissSound, ent); @@ -46,3 +52,10 @@ public sealed class ThrowInsertContainerSystem : EntitySystem _adminLogger.Add(LogType.Landed, LogImpact.Low, $"{ToPrettyString(args.Thrown)} thrown by {ToPrettyString(args.Component.Thrower.Value):player} landed in {ToPrettyString(ent)}"); } } + +/// +/// Sent before the insertion is made. +/// Allows preventing the insertion if any system on the entity should need to. +/// +[ByRefEvent] +public record struct BeforeThrowInsertEvent(EntityUid ThrownEntity, bool Cancelled = false); diff --git a/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs b/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs index 2cf88efc6e..136ac2c440 100644 --- a/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs +++ b/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs @@ -2,6 +2,7 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; using Content.Server.Administration.Logs; using Content.Server.Atmos.EntitySystems; +using Content.Server.Containers; using Content.Server.Disposal.Tube; using Content.Server.Disposal.Tube.Components; using Content.Server.Disposal.Unit.Components; @@ -85,6 +86,8 @@ public sealed class DisposalUnitSystem : SharedDisposalUnitSystem SubscribeLocalEvent(OnDoAfter); + SubscribeLocalEvent(OnThrowInsert); + SubscribeLocalEvent(OnUiButtonPressed); } @@ -195,6 +198,12 @@ public sealed class DisposalUnitSystem : SharedDisposalUnitSystem args.Handled = true; } + private void OnThrowInsert(Entity ent, ref BeforeThrowInsertEvent args) + { + if (!CanInsert(ent, ent, args.ThrownEntity)) + args.Cancelled = true; + } + public override void DoInsertDisposalUnit(EntityUid uid, EntityUid toInsert, EntityUid user, SharedDisposalUnitComponent? disposal = null) { if (!ResolveDisposals(uid, ref disposal)) diff --git a/Content.Shared/Storage/EntitySystems/SharedEntityStorageSystem.cs b/Content.Shared/Storage/EntitySystems/SharedEntityStorageSystem.cs index 5b0f331234..52e2fb68d8 100644 --- a/Content.Shared/Storage/EntitySystems/SharedEntityStorageSystem.cs +++ b/Content.Shared/Storage/EntitySystems/SharedEntityStorageSystem.cs @@ -301,8 +301,20 @@ public abstract class SharedEntityStorageSystem : EntitySystem if (!ResolveStorage(container, ref component)) return false; - RemComp(toRemove); _container.Remove(toRemove, component.Contents); + + if (_container.IsEntityInContainer(container)) + { + if (_container.TryGetOuterContainer(container, Transform(container), out var outerContainer) && + !HasComp(outerContainer.Owner)) + { + _container.Insert(toRemove, outerContainer); + return true; + } + } + + RemComp(toRemove); + var pos = TransformSystem.GetWorldPosition(xform) + TransformSystem.GetWorldRotation(xform).RotateVec(component.EnteringOffset); TransformSystem.SetWorldPosition(toRemove, pos); return true; @@ -366,17 +378,6 @@ public abstract class SharedEntityStorageSystem : EntitySystem return false; } - if (_container.IsEntityInContainer(target)) - { - if (_container.TryGetOuterContainer(target,Transform(target) ,out var container) && - !HasComp(container.Owner)) - { - Popup.PopupClient(Loc.GetString("entity-storage-component-already-contains-user-message"), user, user); - - return false; - } - } - //Checks to see if the opening position, if offset, is inside of a wall. if (component.EnteringOffset != new Vector2(0, 0) && !HasComp(target)) //if the entering position is offset { diff --git a/Resources/Prototypes/Entities/Structures/Furniture/toilet.yml b/Resources/Prototypes/Entities/Structures/Furniture/toilet.yml index 8fbc01fbb9..cb3ae3d065 100644 --- a/Resources/Prototypes/Entities/Structures/Furniture/toilet.yml +++ b/Resources/Prototypes/Entities/Structures/Furniture/toilet.yml @@ -39,6 +39,7 @@ - HumanoidAppearance - Plunger - SolutionTransfer + - EntityStorage whitelist: components: - Item diff --git a/Resources/Prototypes/Entities/Structures/Piping/Disposal/units.yml b/Resources/Prototypes/Entities/Structures/Piping/Disposal/units.yml index 9e14234af4..9d04b32563 100644 --- a/Resources/Prototypes/Entities/Structures/Piping/Disposal/units.yml +++ b/Resources/Prototypes/Entities/Structures/Piping/Disposal/units.yml @@ -120,6 +120,9 @@ whitelist: components: - Item + blacklist: + components: + - EntityStorage - type: MailingUnit - type: DeviceNetwork deviceNetId: Wired