}
/// <summary>
- /// Convert an entity-uid to a matching entity specifier. Usefull when doing entity lookups & checking that the
- /// right quantity of entities/materials werre produced.
+ /// Convert an entity-uid to a matching entity specifier. Useful when doing entity lookups & checking that the
+ /// right quantity of entities/materials werre produced. Returns null if passed an entity with a null prototype.
/// </summary>
- protected EntitySpecifier ToEntitySpecifier(EntityUid uid)
+ protected EntitySpecifier? ToEntitySpecifier(EntityUid uid)
{
if (SEntMan.TryGetComponent(uid, out StackComponent? stack))
return new EntitySpecifier(stack.StackTypeId, stack.Count) { Converted = true };
var meta = SEntMan.GetComponent<MetaDataComponent>(uid);
- Assert.That(meta.EntityPrototype, Is.Not.Null);
- return new(meta.EntityPrototype!.ID, 1) { Converted = true };
+ if (meta.EntityPrototype is null)
+ return null;
+
+ return new(meta.EntityPrototype.ID, 1) { Converted = true };
}
}
protected EntitySpecifierCollection ToEntityCollection(IEnumerable<EntityUid> entities)
{
- var collection = new EntitySpecifierCollection(entities.Select(uid => ToEntitySpecifier(uid)));
+ var collection = new EntitySpecifierCollection(entities
+ .Select(ToEntitySpecifier)
+ .OfType<EntitySpecifier>());
Assert.That(collection.Converted);
return collection;
}
/// <summary>
/// Performs an entity lookup and asserts that only the listed entities exist and that they are all present.
- /// Ignores the grid, map, player, target and contained entities.
+ /// Ignores the grid, map, player, target, contained entities, and entities with null prototypes.
/// </summary>
protected async Task AssertEntityLookup(
EntitySpecifierCollection collection,
foreach (var uid in entities)
{
var found = ToEntitySpecifier(uid);
+ if (found is null)
+ continue;
+
if (spec.Prototype != found.Prototype)
continue;