]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Pulled item interaction fix (#34587)
authorthemias <89101928+themias@users.noreply.github.com>
Tue, 11 Feb 2025 03:29:37 +0000 (22:29 -0500)
committerGitHub <noreply@github.com>
Tue, 11 Feb 2025 03:29:37 +0000 (14:29 +1100)
Content.Shared/Hands/EntitySystems/SharedHandsSystem.Interactions.cs
Content.Shared/Interaction/SharedInteractionSystem.cs
Content.Shared/Inventory/VirtualItem/SharedVirtualItemSystem.cs

index fc5adfaf15a70c84ed865015b6c8d123be34f7af..3b22917fe8e4682586e0a3db8034cc57e589278f 100644 (file)
@@ -188,11 +188,13 @@ public abstract partial class SharedHandsSystem : EntitySystem
         if (args.Handled)
             return;
 
-        // TODO: this pattern is super uncommon, but it might be worth changing GetUsedEntityEvent to be recursive.
-        if (TryComp<VirtualItemComponent>(component.ActiveHandEntity, out var virtualItem))
-            args.Used = virtualItem.BlockingEntity;
-        else
-            args.Used = component.ActiveHandEntity;
+        if (component.ActiveHandEntity.HasValue)
+        {
+            // allow for the item to return a different entity, e.g. virtual items
+            RaiseLocalEvent(component.ActiveHandEntity.Value, ref args);
+        }
+
+        args.Used ??= component.ActiveHandEntity;
     }
 
     //TODO: Actually shows all items/clothing/etc.
index f53895cf8d6dfaf16daa0c845288cec3481768c3..1eb7bd112d3ec5e3e777cc9b132054a339ff6b1f 100644 (file)
@@ -1413,7 +1413,7 @@ namespace Content.Shared.Interaction
         /// <returns>If there is an entity being used.</returns>
         public bool TryGetUsedEntity(EntityUid user, [NotNullWhen(true)] out EntityUid? used, bool checkCanUse = true)
         {
-            var ev = new GetUsedEntityEvent();
+            var ev = new GetUsedEntityEvent(user);
             RaiseLocalEvent(user, ref ev);
 
             used = ev.Used;
@@ -1464,8 +1464,9 @@ namespace Content.Shared.Interaction
     ///     Raised directed by-ref on an entity to determine what item will be used in interactions.
     /// </summary>
     [ByRefEvent]
-    public record struct GetUsedEntityEvent()
+    public record struct GetUsedEntityEvent(EntityUid User)
     {
+        public EntityUid User = User;
         public EntityUid? Used = null;
 
         public bool Handled => Used != null;
index 8e62c5163daa3808330cc0a61e1a7fb417020735..9eac60adc4028cc66b0172f1bea5a3676f32b637 100644 (file)
@@ -46,6 +46,8 @@ public abstract class SharedVirtualItemSystem : EntitySystem
 
         SubscribeLocalEvent<VirtualItemComponent, BeforeRangedInteractEvent>(OnBeforeRangedInteract);
         SubscribeLocalEvent<VirtualItemComponent, GettingInteractedWithAttemptEvent>(OnGettingInteractedWithAttemptEvent);
+
+        SubscribeLocalEvent<VirtualItemComponent, GetUsedEntityEvent>(OnGetUsedEntity);
     }
 
     /// <summary>
@@ -81,6 +83,23 @@ public abstract class SharedVirtualItemSystem : EntitySystem
         args.Cancelled = true;
     }
 
+    private void OnGetUsedEntity(Entity<VirtualItemComponent> ent, ref GetUsedEntityEvent args)
+    {
+        if (args.Handled)
+            return;
+
+        // if the user is holding the real item the virtual item points to,
+        // we allow them to use it in the interaction
+        foreach (var hand in _handsSystem.EnumerateHands(args.User))
+        {
+            if (hand.HeldEntity == ent.Comp.BlockingEntity)
+            {
+                args.Used = ent.Comp.BlockingEntity;
+                return;
+            }
+        }
+    }
+
     #region Hands
 
     /// <summary>