make printed items from lathes automatically stack (#13603)
Closes https://github.com/space-wizards/space-station-14/issues/10402
This commit is contained in:
@@ -6,6 +6,7 @@ using Content.Server.Lathe.Components;
|
||||
using Content.Server.Materials;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.Power.EntitySystems;
|
||||
using Content.Server.Stack;
|
||||
using Content.Server.UserInterface;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Lathe;
|
||||
@@ -29,6 +30,7 @@ namespace Content.Server.Lathe
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly UserInterfaceSystem _uiSys = default!;
|
||||
[Dependency] private readonly MaterialStorageSystem _materialStorage = default!;
|
||||
[Dependency] private readonly StackSystem _stack = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -85,22 +87,22 @@ namespace Content.Server.Lathe
|
||||
}
|
||||
|
||||
[PublicAPI]
|
||||
public bool TryGetAvailableRecipes(EntityUid uid, [NotNullWhen(true)] out List<string>? recipes, LatheComponent? component = null)
|
||||
public bool TryGetAvailableRecipes(EntityUid uid, [NotNullWhen(true)] out List<string>? recipes, [NotNullWhen(true)] LatheComponent? component = null)
|
||||
{
|
||||
recipes = null;
|
||||
if (!Resolve(uid, ref component))
|
||||
return false;
|
||||
recipes = GetAvailableRecipes(component);
|
||||
recipes = GetAvailableRecipes(uid, component);
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<string> GetAvailableRecipes(LatheComponent component)
|
||||
public List<string> GetAvailableRecipes(EntityUid uid, LatheComponent component)
|
||||
{
|
||||
var ev = new LatheGetRecipesEvent(component.Owner)
|
||||
var ev = new LatheGetRecipesEvent(uid)
|
||||
{
|
||||
Recipes = component.StaticRecipes
|
||||
};
|
||||
RaiseLocalEvent(component.Owner, ev);
|
||||
RaiseLocalEvent(uid, ev);
|
||||
return ev.Recipes;
|
||||
}
|
||||
|
||||
@@ -147,7 +149,7 @@ namespace Content.Server.Lathe
|
||||
lathe.ProductionLength = recipe.CompleteTime * component.TimeMultiplier;
|
||||
component.CurrentRecipe = recipe;
|
||||
|
||||
_audio.PlayPvs(component.ProducingSound, component.Owner);
|
||||
_audio.PlayPvs(component.ProducingSound, uid);
|
||||
UpdateRunningAppearance(uid, true);
|
||||
UpdateUserInterfaceState(uid, component);
|
||||
return true;
|
||||
@@ -159,13 +161,17 @@ namespace Content.Server.Lathe
|
||||
return;
|
||||
|
||||
if (comp.CurrentRecipe != null)
|
||||
Spawn(comp.CurrentRecipe.Result, Transform(uid).Coordinates);
|
||||
{
|
||||
var result = Spawn(comp.CurrentRecipe.Result, Transform(uid).Coordinates);
|
||||
_stack.TryMergeToContacts(result);
|
||||
}
|
||||
|
||||
comp.CurrentRecipe = null;
|
||||
prodComp.StartTime = _timing.CurTime;
|
||||
|
||||
if (!TryStartProducing(uid, comp))
|
||||
{
|
||||
RemCompDeferred(prodComp.Owner, prodComp);
|
||||
RemCompDeferred(uid, prodComp);
|
||||
UpdateUserInterfaceState(uid, comp);
|
||||
UpdateRunningAppearance(uid, false);
|
||||
}
|
||||
@@ -179,7 +185,7 @@ namespace Content.Server.Lathe
|
||||
var ui = _uiSys.GetUi(uid, LatheUiKey.Key);
|
||||
var producing = component.CurrentRecipe ?? component.Queue.FirstOrDefault();
|
||||
|
||||
var state = new LatheUpdateState(GetAvailableRecipes(component), component.Queue, producing);
|
||||
var state = new LatheUpdateState(GetAvailableRecipes(uid, component), component.Queue, producing);
|
||||
_uiSys.SetUiState(ui, state);
|
||||
}
|
||||
|
||||
@@ -254,7 +260,7 @@ namespace Content.Server.Lathe
|
||||
|
||||
protected override bool HasRecipe(EntityUid uid, LatheRecipePrototype recipe, LatheComponent component)
|
||||
{
|
||||
return GetAvailableRecipes(component).Contains(recipe.ID);
|
||||
return GetAvailableRecipes(uid, component).Contains(recipe.ID);
|
||||
}
|
||||
|
||||
#region UI Messages
|
||||
|
||||
Reference in New Issue
Block a user