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>
This commit is contained in:
SlamBamActionman
2025-02-27 18:43:56 +01:00
committed by GitHub
parent 19c23682b0
commit c7b9a76342
5 changed files with 39 additions and 12 deletions

View File

@@ -30,6 +30,12 @@ public sealed class ThrowInsertContainerSystem : EntitySystem
if (!_containerSystem.CanInsert(args.Thrown, container)) if (!_containerSystem.CanInsert(args.Thrown, container))
return; return;
var beforeThrowArgs = new BeforeThrowInsertEvent(args.Thrown);
RaiseLocalEvent(ent, ref beforeThrowArgs);
if (beforeThrowArgs.Cancelled)
return;
if (_random.Prob(ent.Comp.Probability)) if (_random.Prob(ent.Comp.Probability))
{ {
_audio.PlayPvs(ent.Comp.MissSound, ent); _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)}"); _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);

View File

@@ -2,6 +2,7 @@ using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using Content.Server.Administration.Logs; using Content.Server.Administration.Logs;
using Content.Server.Atmos.EntitySystems; using Content.Server.Atmos.EntitySystems;
using Content.Server.Containers;
using Content.Server.Disposal.Tube; using Content.Server.Disposal.Tube;
using Content.Server.Disposal.Tube.Components; using Content.Server.Disposal.Tube.Components;
using Content.Server.Disposal.Unit.Components; using Content.Server.Disposal.Unit.Components;
@@ -85,6 +86,8 @@ public sealed class DisposalUnitSystem : SharedDisposalUnitSystem
SubscribeLocalEvent<DisposalUnitComponent, DisposalDoAfterEvent>(OnDoAfter); SubscribeLocalEvent<DisposalUnitComponent, DisposalDoAfterEvent>(OnDoAfter);
SubscribeLocalEvent<DisposalUnitComponent, BeforeThrowInsertEvent>(OnThrowInsert);
SubscribeLocalEvent<DisposalUnitComponent, SharedDisposalUnitComponent.UiButtonPressedMessage>(OnUiButtonPressed); SubscribeLocalEvent<DisposalUnitComponent, SharedDisposalUnitComponent.UiButtonPressedMessage>(OnUiButtonPressed);
} }
@@ -195,6 +198,12 @@ public sealed class DisposalUnitSystem : SharedDisposalUnitSystem
args.Handled = true; 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) public override void DoInsertDisposalUnit(EntityUid uid, EntityUid toInsert, EntityUid user, SharedDisposalUnitComponent? disposal = null)
{ {
if (!ResolveDisposals(uid, ref disposal)) if (!ResolveDisposals(uid, ref disposal))

View File

@@ -301,8 +301,20 @@ public abstract class SharedEntityStorageSystem : EntitySystem
if (!ResolveStorage(container, ref component)) if (!ResolveStorage(container, ref component))
return false; return false;
RemComp<InsideEntityStorageComponent>(toRemove);
_container.Remove(toRemove, component.Contents); _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); var pos = TransformSystem.GetWorldPosition(xform) + TransformSystem.GetWorldRotation(xform).RotateVec(component.EnteringOffset);
TransformSystem.SetWorldPosition(toRemove, pos); TransformSystem.SetWorldPosition(toRemove, pos);
return true; return true;
@@ -366,17 +378,6 @@ public abstract class SharedEntityStorageSystem : EntitySystem
return false; 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. //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 if (component.EnteringOffset != new Vector2(0, 0) && !HasComp<WallMountComponent>(target)) //if the entering position is offset
{ {

View File

@@ -39,6 +39,7 @@
- HumanoidAppearance - HumanoidAppearance
- Plunger - Plunger
- SolutionTransfer - SolutionTransfer
- EntityStorage
whitelist: whitelist:
components: components:
- Item - Item

View File

@@ -120,6 +120,9 @@
whitelist: whitelist:
components: components:
- Item - Item
blacklist:
components:
- EntityStorage
- type: MailingUnit - type: MailingUnit
- type: DeviceNetwork - type: DeviceNetwork
deviceNetId: Wired deviceNetId: Wired