Fix stuck lathe queue (#10311)

This commit is contained in:
Leon Friedrich
2022-08-05 11:19:31 +12:00
committed by GitHub
parent a695c626d0
commit 8f445d44fa

View File

@@ -189,10 +189,14 @@ namespace Content.Server.Lathe
} }
if (!component.CanProduce(recipe) || !TryComp(uid, out MaterialStorageComponent? storage)) if (!component.CanProduce(recipe) || !TryComp(uid, out MaterialStorageComponent? storage))
{
component.Queue.RemoveAt(0);
return false; return false;
}
prodComp ??= EnsureComp<LatheProducingComponent>(uid); prodComp ??= EnsureComp<LatheProducingComponent>(uid);
// Do nothing if the lathe is already producing something.
if (prodComp.Recipe != null) if (prodComp.Recipe != null)
return false; return false;
@@ -203,6 +207,7 @@ namespace Content.Server.Lathe
foreach (var (material, amount) in recipe.RequiredMaterials) foreach (var (material, amount) in recipe.RequiredMaterials)
{ {
// This should always return true, otherwise CanProduce fucked up. // This should always return true, otherwise CanProduce fucked up.
// TODO just remove materials when first queuing, to avoid queuing more items than can actually be produced.
storage.RemoveMaterial(material, amount); storage.RemoveMaterial(material, amount);
} }
@@ -278,6 +283,7 @@ namespace Content.Server.Lathe
{ {
for (var i = 0; i < args.Quantity; i++) for (var i = 0; i < args.Quantity; i++)
{ {
// TODO check required materials exist and make materials unavailable.
component.Queue.Add(recipe.ID); component.Queue.Add(recipe.ID);
} }