]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Prevent crates, pet carriers and other things from going into disposals (#35557)
authorSlamBamActionman <83650252+SlamBamActionman@users.noreply.github.com>
Thu, 27 Feb 2025 17:43:56 +0000 (18:43 +0100)
committerGitHub <noreply@github.com>
Thu, 27 Feb 2025 17:43:56 +0000 (18:43 +0100)
* Initial commit

* Solve underlying bug, readd to disposals

* Apply suggestions from code review

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
Content.Server/Containers/ThrowInsertContainerSystem.cs
Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs
Content.Shared/Storage/EntitySystems/SharedEntityStorageSystem.cs
Resources/Prototypes/Entities/Structures/Furniture/toilet.yml
Resources/Prototypes/Entities/Structures/Piping/Disposal/units.yml

index cbaec7f5c6e10f83ccb426f2afeb1c2321de4dd0..09176c423ca9f15e714afbef7a659ed5ae439e1d 100644 (file)
@@ -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)}");
     }
 }
+
+/// <summary>
+/// Sent before the insertion is made.
+/// Allows preventing the insertion if any system on the entity should need to.
+/// </summary>
+[ByRefEvent]
+public record struct BeforeThrowInsertEvent(EntityUid ThrownEntity, bool Cancelled = false);
index 2cf88efc6e7085f725fdf71598de604005fe1527..136ac2c440f0bb562fddbd7b84be96e02176f27f 100644 (file)
@@ -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<DisposalUnitComponent, DisposalDoAfterEvent>(OnDoAfter);
 
+        SubscribeLocalEvent<DisposalUnitComponent, BeforeThrowInsertEvent>(OnThrowInsert);
+
         SubscribeLocalEvent<DisposalUnitComponent, SharedDisposalUnitComponent.UiButtonPressedMessage>(OnUiButtonPressed);
     }
 
@@ -195,6 +198,12 @@ public sealed class DisposalUnitSystem : SharedDisposalUnitSystem
         args.Handled = true;
     }
 
+    private void OnThrowInsert(Entity<DisposalUnitComponent> 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))
index 5b0f331234d48fc136bc0971fba5f7aa0532c306..52e2fb68d8d6d445b8d31278ad8cfd7d117832d8 100644 (file)
@@ -301,8 +301,20 @@ public abstract class SharedEntityStorageSystem : EntitySystem
         if (!ResolveStorage(container, ref component))
             return false;
 
-        RemComp<InsideEntityStorageComponent>(toRemove);
         _container.Remove(toRemove, component.Contents);
+
+        if (_container.IsEntityInContainer(container))
+        {
+            if (_container.TryGetOuterContainer(container, Transform(container), out var outerContainer) &&
+                !HasComp<HandsComponent>(outerContainer.Owner))
+            {
+                _container.Insert(toRemove, outerContainer);
+                return true;
+            }
+        }
+
+        RemComp<InsideEntityStorageComponent>(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<HandsComponent>(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<WallMountComponent>(target)) //if the entering position is offset
         {
index 8fbc01fbb9e459551d673b2f541c865b610fc3df..cb3ae3d06562bca2f4389831b1b0fa12259b433d 100644 (file)
@@ -39,6 +39,7 @@
       - HumanoidAppearance
       - Plunger
       - SolutionTransfer
+      - EntityStorage
     whitelist:
       components:
       - Item
index 9e14234af4a38492ecafa571f5cb4d6e5c078fb8..9d04b32563ed77030ef6404466823e4fa7c20d84 100644 (file)
     whitelist:
       components:
       - Item
+    blacklist:
+      components:
+      - EntityStorage
   - type: MailingUnit
   - type: DeviceNetwork
     deviceNetId: Wired