From 0401683a9cb684a89b4e5cda2fc6eaaa1b08853a Mon Sep 17 00:00:00 2001 From: ScarKy0 <106310278+ScarKy0@users.noreply.github.com> Date: Thu, 9 Jul 2026 18:22:46 +0200 Subject: [PATCH] Unpredict handheld grinder audio (#44574) * modern * unpredict audio * prediction't --- .../EntitySystems/HandheldGrinderSystem.cs | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Content.Shared/Kitchen/EntitySystems/HandheldGrinderSystem.cs b/Content.Shared/Kitchen/EntitySystems/HandheldGrinderSystem.cs index c3f853deda..9061c6cf40 100644 --- a/Content.Shared/Kitchen/EntitySystems/HandheldGrinderSystem.cs +++ b/Content.Shared/Kitchen/EntitySystems/HandheldGrinderSystem.cs @@ -9,6 +9,7 @@ using Content.Shared.Popups; using Content.Shared.Stacks; using Robust.Shared.Audio.Systems; using Robust.Shared.Containers; +using Robust.Shared.Network; using Robust.Shared.Serialization; namespace Content.Shared.Kitchen.EntitySystems; @@ -23,18 +24,11 @@ public sealed partial class HandheldGrinderSystem : EntitySystem [Dependency] private SharedAudioSystem _audio = default!; [Dependency] private SharedPuddleSystem _puddle = default!; [Dependency] private SharedPopupSystem _popup = default!; - - public override void Initialize() - { - base.Initialize(); - - SubscribeLocalEvent(OnGrinderRemoved); - SubscribeLocalEvent(OnInteractUsing); - SubscribeLocalEvent(OnHandheldDoAfter); - } + [Dependency] private INetManager _net = default!; // prevent the infamous UdderSystem debug assert, see https://github.com/space-wizards/space-station-14/pull/35314 // TODO: find a better solution than copy pasting this into every shared system that caches solution entities + [SubscribeLocalEvent] private void OnGrinderRemoved(Entity entity, ref EntRemovedFromContainerMessage args) { // Make sure the removed entity was our contained solution and set it to null @@ -44,6 +38,7 @@ public sealed partial class HandheldGrinderSystem : EntitySystem entity.Comp.GrinderSolution = null; } + [SubscribeLocalEvent] private void OnInteractUsing(Entity ent, ref InteractUsingEvent args) { if (args.Handled) @@ -55,7 +50,7 @@ public sealed partial class HandheldGrinderSystem : EntitySystem if (!CanGrinderBeUsed(ent, item, out var reason)) { - _popup.PopupClient(reason, ent, args.User); + _popup.PopupEntity(reason, ent, args.User); return; } @@ -65,6 +60,11 @@ public sealed partial class HandheldGrinderSystem : EntitySystem if (!_solution.ResolveSolution(ent.Owner, ent.Comp.SolutionName, ref ent.Comp.GrinderSolution)) return; + ent.Comp.AudioStream = _audio.Stop(ent.Comp.AudioStream); + + if (_net.IsServer) // Cannot correctly cancel predicted audio. + ent.Comp.AudioStream = _audio.PlayPvs(ent.Comp.Sound, ent)?.Entity; + var doAfter = new DoAfterArgs(EntityManager, args.User, ent.Comp.DoAfterDuration, new HandheldGrinderDoAfterEvent(), ent, ent, item) { NeedHand = true, @@ -74,10 +74,10 @@ public sealed partial class HandheldGrinderSystem : EntitySystem BreakOnMove = true }; - if (_doAfter.TryStartDoAfter(doAfter)) - ent.Comp.AudioStream = _audio.PlayPredicted(ent.Comp.Sound, ent, args.User)?.Entity ?? ent.Comp.AudioStream; + _doAfter.TryStartDoAfter(doAfter); } + [SubscribeLocalEvent] private void OnHandheldDoAfter(Entity ent, ref HandheldGrinderDoAfterEvent args) { ent.Comp.AudioStream = _audio.Stop(ent.Comp.AudioStream); @@ -90,7 +90,7 @@ public sealed partial class HandheldGrinderSystem : EntitySystem if (!CanGrinderBeUsed(ent, item, out var reason)) { - _popup.PopupClient(reason, ent, args.User); + _popup.PopupEntity(reason, ent, args.User); return; } @@ -110,7 +110,7 @@ public sealed partial class HandheldGrinderSystem : EntitySystem else _destructibleSystem.DestroyEntity(item); - _popup.PopupClient(Loc.GetString(ent.Comp.FinishedPopup, ("item", item)), ent, args.User); + _popup.PopupEntity(Loc.GetString(ent.Comp.FinishedPopup, ("item", item)), ent, args.User); } ///