UseInHandEvent cleanup (#35231)

This commit is contained in:
slarticodefast
2025-02-18 13:27:30 +01:00
committed by GitHub
parent e09ef5aa6f
commit d171057680
9 changed files with 45 additions and 25 deletions

View File

@@ -12,6 +12,7 @@ public sealed class SpawnTableOnUseSystem : EntitySystem
[Dependency] private readonly EntityTableSystem _entityTable = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly SharedHandsSystem _hands = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
public override void Initialize()
{
@@ -25,17 +26,21 @@ public sealed class SpawnTableOnUseSystem : EntitySystem
if (args.Handled)
return;
args.Handled = true;
var coords = Transform(ent).Coordinates;
var spawns = _entityTable.GetSpawns(ent.Comp.Table);
// Don't delete the entity in the event bus, so we queue it for deletion.
// We need the free hand for the new item, so we send it to nullspace.
_transform.DetachEntity(ent, Transform(ent));
QueueDel(ent);
foreach (var id in spawns)
{
var spawned = Spawn(id, coords);
_adminLogger.Add(LogType.EntitySpawn, LogImpact.Low, $"{ToPrettyString(args.User):user} used {ToPrettyString(ent):spawner} which spawned {ToPrettyString(spawned)}");
_hands.TryPickupAnyHand(args.User, spawned);
_hands.PickupOrDrop(args.User, spawned);
}
Del(ent);
args.Handled = true;
}
}