Predict virtual hands and co (#36617)

These are the easy ones anything else gets slightly spicier.
This commit is contained in:
metalgearsloth
2025-04-19 16:51:12 +10:00
committed by GitHub
parent 63dfd21b14
commit 4682149e74
5 changed files with 23 additions and 52 deletions

View File

@@ -157,11 +157,6 @@ public abstract class SharedVirtualItemSystem : EntitySystem
/// </summary>
public void DeleteInHandsMatching(EntityUid user, EntityUid matching)
{
// Client can't currently predict deleting networked entities so we use this workaround, another
// problem can popup when the hands leave PVS for example and this avoids that too
if (_netManager.IsClient)
return;
foreach (var hand in _handsSystem.EnumerateHands(user))
{
if (TryComp(hand.HeldEntity, out VirtualItemComponent? virt) && virt.BlockingEntity == matching)
@@ -206,11 +201,6 @@ public abstract class SharedVirtualItemSystem : EntitySystem
/// <param name="slotName">Set this param if you have the name of the slot, it avoids unnecessary queries</param>
public void DeleteInSlotMatching(EntityUid user, EntityUid matching, string? slotName = null)
{
// Client can't currently predict deleting networked entities so we use this workaround, another
// problem can popup when the hands leave PVS for example and this avoids that too
if (_netManager.IsClient)
return;
if (slotName != null)
{
if (!_inventorySystem.TryGetSlotEntity(user, slotName, out var slotEnt))
@@ -244,14 +234,8 @@ public abstract class SharedVirtualItemSystem : EntitySystem
/// <param name="virtualItem">The virtual item, if spawned</param>
public bool TrySpawnVirtualItem(EntityUid blockingEnt, EntityUid user, [NotNullWhen(true)] out EntityUid? virtualItem)
{
if (_netManager.IsClient)
{
virtualItem = null;
return false;
}
var pos = Transform(user).Coordinates;
virtualItem = Spawn(VirtualItem, pos);
virtualItem = PredictedSpawnAttachedTo(VirtualItem, pos);
var virtualItemComp = Comp<VirtualItemComponent>(virtualItem.Value);
virtualItemComp.BlockingEntity = blockingEnt;
Dirty(virtualItem.Value, virtualItemComp);
@@ -273,7 +257,6 @@ public abstract class SharedVirtualItemSystem : EntitySystem
return;
_transformSystem.DetachEntity(item, Transform(item));
if (_netManager.IsServer)
QueueDel(item);
PredictedQueueDel(item);
}
}