Prevent erroneous materials from being placed in lathes. (#9454)
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
@@ -3,6 +3,9 @@ using Content.Shared.Research.Prototypes;
|
|||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Content.Shared.Sound;
|
using Content.Shared.Sound;
|
||||||
using Content.Shared.Whitelist;
|
using Content.Shared.Whitelist;
|
||||||
|
using Robust.Shared.Prototypes;
|
||||||
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
|
||||||
|
using Content.Shared.Materials;
|
||||||
|
|
||||||
namespace Content.Server.Lathe.Components
|
namespace Content.Server.Lathe.Components
|
||||||
{
|
{
|
||||||
@@ -16,6 +19,13 @@ namespace Content.Server.Lathe.Components
|
|||||||
[DataField("whitelist")]
|
[DataField("whitelist")]
|
||||||
public EntityWhitelist? LatheWhitelist;
|
public EntityWhitelist? LatheWhitelist;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whitelist generated on runtime for what items are specifically used for the lathe's recipes.
|
||||||
|
/// </summary>
|
||||||
|
[ViewVariables]
|
||||||
|
[DataField("materialWhiteList", customTypeSerializer: typeof(PrototypeIdListSerializer<MaterialPrototype>))]
|
||||||
|
public List<string> MaterialWhiteList = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The lathe's construction queue
|
/// The lathe's construction queue
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ using Robust.Shared.Prototypes;
|
|||||||
using Robust.Shared.Player;
|
using Robust.Shared.Player;
|
||||||
using Robust.Shared.Audio;
|
using Robust.Shared.Audio;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace Content.Server.Lathe
|
namespace Content.Server.Lathe
|
||||||
{
|
{
|
||||||
@@ -93,10 +94,26 @@ namespace Content.Server.Lathe
|
|||||||
component.UserInterface.OnReceiveMessage += msg => UserInterfaceOnOnReceiveMessage(uid, component, msg);
|
component.UserInterface.OnReceiveMessage += msg => UserInterfaceOnOnReceiveMessage(uid, component, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!TryComp<AppearanceComponent>(uid, out var appearance))
|
if (TryComp<AppearanceComponent>(uid, out var appearance))
|
||||||
|
{
|
||||||
|
appearance.SetData(LatheVisuals.IsInserting, false);
|
||||||
|
appearance.SetData(LatheVisuals.IsRunning, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Fix this awful shit once Lathes get ECS'd.
|
||||||
|
List<LatheRecipePrototype>? recipes = null;
|
||||||
|
if (TryComp<ProtolatheDatabaseComponent>(uid, out var database))
|
||||||
|
recipes = database.ProtolatheRecipes.ToList();
|
||||||
|
else if (TryComp<LatheDatabaseComponent>(uid, out var database2))
|
||||||
|
recipes = database2._recipes;
|
||||||
|
|
||||||
|
if (recipes == null)
|
||||||
return;
|
return;
|
||||||
appearance.SetData(LatheVisuals.IsInserting, false);
|
|
||||||
appearance.SetData(LatheVisuals.IsRunning, false);
|
foreach (var recipe in recipes)
|
||||||
|
foreach (var mat in recipe.RequiredMaterials)
|
||||||
|
if (!component.MaterialWhiteList.Contains(mat.Key))
|
||||||
|
component.MaterialWhiteList.Add(mat.Key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -110,6 +127,17 @@ namespace Content.Server.Lathe
|
|||||||
|| component.LatheWhitelist?.IsValid(args.Used) == false)
|
|| component.LatheWhitelist?.IsValid(args.Used) == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
var matUsed = false;
|
||||||
|
foreach (var mat in material.Materials)
|
||||||
|
if (component.MaterialWhiteList.Contains(mat.ID))
|
||||||
|
matUsed = true;
|
||||||
|
|
||||||
|
if (!matUsed)
|
||||||
|
{
|
||||||
|
_popupSystem.PopupEntity(Loc.GetString("lathe-popup-material-not-used"), uid, Filter.Pvs(uid));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var multiplier = 1;
|
var multiplier = 1;
|
||||||
|
|
||||||
if (TryComp<StackComponent>(args.Used, out var stack))
|
if (TryComp<StackComponent>(args.Used, out var stack))
|
||||||
|
|||||||
@@ -11,8 +11,7 @@ namespace Content.Shared.Lathe
|
|||||||
public abstract class SharedLatheDatabaseComponent : Component, IEnumerable<LatheRecipePrototype>, ISerializationHooks
|
public abstract class SharedLatheDatabaseComponent : Component, IEnumerable<LatheRecipePrototype>, ISerializationHooks
|
||||||
{
|
{
|
||||||
[DataField("recipes", customTypeSerializer: typeof(PrototypeIdListSerializer<LatheRecipePrototype>))] private List<string> _recipeIds = new();
|
[DataField("recipes", customTypeSerializer: typeof(PrototypeIdListSerializer<LatheRecipePrototype>))] private List<string> _recipeIds = new();
|
||||||
|
public readonly List<LatheRecipePrototype> _recipes = new();
|
||||||
private readonly List<LatheRecipePrototype> _recipes = new();
|
|
||||||
|
|
||||||
void ISerializationHooks.BeforeSerialization()
|
void ISerializationHooks.BeforeSerialization()
|
||||||
{
|
{
|
||||||
|
|||||||
1
Resources/Locale/en-US/lathe/lathesystem.ftl
Normal file
1
Resources/Locale/en-US/lathe/lathesystem.ftl
Normal file
@@ -0,0 +1 @@
|
|||||||
|
lathe-popup-material-not-used = This material is not used in this lathe.
|
||||||
Reference in New Issue
Block a user