From: Doomsdrayk Date: Thu, 13 Jun 2024 06:30:39 +0000 (-0600) Subject: Fix guns appearing to cycle bolt when wielded (#28756) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=249e4a9c15c8e3960dd1cd77db4ad4090bf6609d;p=space-station-14.git Fix guns appearing to cycle bolt when wielded (#28756) Adds a check during wielding to see if the code is running clientside, and if so skip the part responsible for creating the virtual items. This is necessary because TrySpawnVirtualItem is blocked from running clientside, so trying to spawn the virtual items for wielding causes the client to always believe the wield has failed. This erroneous failure leads to the display of incorrect feedback until the server's successful wield attempt makes it to the client. The added check prevents wielding from failing in this way and therefore allows the client to behave as expected. --- diff --git a/Content.Shared/Wieldable/WieldableSystem.cs b/Content.Shared/Wieldable/WieldableSystem.cs index cb95c1d7e7..a0c9d04ff7 100644 --- a/Content.Shared/Wieldable/WieldableSystem.cs +++ b/Content.Shared/Wieldable/WieldableSystem.cs @@ -17,6 +17,7 @@ using Content.Shared.Weapons.Ranged.Events; using Content.Shared.Weapons.Ranged.Systems; using Content.Shared.Wieldable.Components; using Robust.Shared.Audio.Systems; +using Robust.Shared.Network; using Robust.Shared.Timing; namespace Content.Shared.Wieldable; @@ -32,6 +33,7 @@ public sealed class WieldableSystem : EntitySystem [Dependency] private readonly UseDelaySystem _delay = default!; [Dependency] private readonly SharedGunSystem _gun = default!; [Dependency] private readonly IGameTiming _timing = default!; + [Dependency] private readonly INetManager _netManager = default!; public override void Initialize() { @@ -213,21 +215,27 @@ public sealed class WieldableSystem : EntitySystem if (component.WieldSound != null) _audioSystem.PlayPredicted(component.WieldSound, used, user); - var virtuals = new List(); - for (var i = 0; i < component.FreeHandsRequired; i++) + //This section handles spawning the virtual item(s) to occupy the required additional hand(s). + //Since the client can't currently predict entity spawning, only do this if this is running serverside. + //Remove this check if TrySpawnVirtualItem in SharedVirtualItemSystem is allowed to complete clientside. + if (_netManager.IsServer) { - if (_virtualItemSystem.TrySpawnVirtualItemInHand(used, user, out var virtualItem, true)) + var virtuals = new List(); + for (var i = 0; i < component.FreeHandsRequired; i++) { - virtuals.Add(virtualItem.Value); - continue; + if (_virtualItemSystem.TrySpawnVirtualItemInHand(used, user, out var virtualItem, true)) + { + virtuals.Add(virtualItem.Value); + continue; + } + + foreach (var existingVirtual in virtuals) + { + QueueDel(existingVirtual); + } + + return false; } - - foreach (var existingVirtual in virtuals) - { - QueueDel(existingVirtual); - } - - return false; } if (TryComp(used, out UseDelayComponent? useDelay)