From de8dcb75bfef334b3f49f97441556f2999c5729a Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Wed, 23 Feb 2022 17:58:06 +1300 Subject: [PATCH] Fix interact using sometimes having target==used (#6847) --- Content.Shared/Interaction/IInteractUsing.cs | 6 ++++++ Content.Shared/Interaction/SharedInteractionSystem.cs | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/Content.Shared/Interaction/IInteractUsing.cs b/Content.Shared/Interaction/IInteractUsing.cs index 04f1e6c003..5a639e27ab 100644 --- a/Content.Shared/Interaction/IInteractUsing.cs +++ b/Content.Shared/Interaction/IInteractUsing.cs @@ -4,6 +4,7 @@ using JetBrains.Annotations; using Robust.Shared.Analyzers; using Robust.Shared.GameObjects; using Robust.Shared.Map; +using Robust.Shared.Utility; namespace Content.Shared.Interaction { @@ -78,6 +79,11 @@ namespace Content.Shared.Interaction public InteractUsingEvent(EntityUid user, EntityUid used, EntityUid target, EntityCoordinates clickLocation, bool predicted = false) { + // Interact using should not have the same used and target. + // That should be a use-in-hand event instead. + // If this is not the case, can lead to bugs (e.g., attempting to merge a item stack into itself). + DebugTools.Assert(used != target); + User = user; Used = used; Target = target; diff --git a/Content.Shared/Interaction/SharedInteractionSystem.cs b/Content.Shared/Interaction/SharedInteractionSystem.cs index 8874b7cc0c..253b77b6f3 100644 --- a/Content.Shared/Interaction/SharedInteractionSystem.cs +++ b/Content.Shared/Interaction/SharedInteractionSystem.cs @@ -216,6 +216,12 @@ namespace Content.Shared.Interaction if (checkCanUse && !_actionBlockerSystem.CanUseHeldEntity(user)) return; + if (target == hand.HeldEntity) + { + UseInHandInteraction(user, target.Value, checkCanUse: false, checkCanInteract: false); + return; + } + if (inRangeUnobstructed && target != null) { InteractUsing(