diff --git a/Content.Server/Lathe/Components/LatheComponent.cs b/Content.Server/Lathe/Components/LatheComponent.cs index d0fd8fa7d3..49fc2a1135 100644 --- a/Content.Server/Lathe/Components/LatheComponent.cs +++ b/Content.Server/Lathe/Components/LatheComponent.cs @@ -3,6 +3,9 @@ using Content.Shared.Research.Prototypes; using Robust.Server.GameObjects; using Content.Shared.Sound; 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 { @@ -16,6 +19,13 @@ namespace Content.Server.Lathe.Components [DataField("whitelist")] public EntityWhitelist? LatheWhitelist; + /// + /// Whitelist generated on runtime for what items are specifically used for the lathe's recipes. + /// + [ViewVariables] + [DataField("materialWhiteList", customTypeSerializer: typeof(PrototypeIdListSerializer))] + public List MaterialWhiteList = new(); + /// /// The lathe's construction queue /// @@ -60,4 +70,4 @@ namespace Content.Server.Lathe.Components /// [ViewVariables] public BoundUserInterface? UserInterface; } -} \ No newline at end of file +} diff --git a/Content.Server/Lathe/LatheSystem.cs b/Content.Server/Lathe/LatheSystem.cs index 87e642c94f..d765c02fc7 100644 --- a/Content.Server/Lathe/LatheSystem.cs +++ b/Content.Server/Lathe/LatheSystem.cs @@ -17,6 +17,7 @@ using Robust.Shared.Prototypes; using Robust.Shared.Player; using Robust.Shared.Audio; using JetBrains.Annotations; +using System.Linq; namespace Content.Server.Lathe { @@ -93,10 +94,26 @@ namespace Content.Server.Lathe component.UserInterface.OnReceiveMessage += msg => UserInterfaceOnOnReceiveMessage(uid, component, msg); } - if (!TryComp(uid, out var appearance)) + if (TryComp(uid, out var appearance)) + { + appearance.SetData(LatheVisuals.IsInserting, false); + appearance.SetData(LatheVisuals.IsRunning, false); + } + + //Fix this awful shit once Lathes get ECS'd. + List? recipes = null; + if (TryComp(uid, out var database)) + recipes = database.ProtolatheRecipes.ToList(); + else if (TryComp(uid, out var database2)) + recipes = database2._recipes; + + if (recipes == null) 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); } /// @@ -110,6 +127,17 @@ namespace Content.Server.Lathe || component.LatheWhitelist?.IsValid(args.Used) == false) 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; if (TryComp(args.Used, out var stack)) diff --git a/Content.Shared/Lathe/SharedLatheDatabaseComponent.cs b/Content.Shared/Lathe/SharedLatheDatabaseComponent.cs index 739a3de7e7..65a77d178a 100644 --- a/Content.Shared/Lathe/SharedLatheDatabaseComponent.cs +++ b/Content.Shared/Lathe/SharedLatheDatabaseComponent.cs @@ -11,8 +11,7 @@ namespace Content.Shared.Lathe public abstract class SharedLatheDatabaseComponent : Component, IEnumerable, ISerializationHooks { [DataField("recipes", customTypeSerializer: typeof(PrototypeIdListSerializer))] private List _recipeIds = new(); - - private readonly List _recipes = new(); + public readonly List _recipes = new(); void ISerializationHooks.BeforeSerialization() { diff --git a/Resources/Locale/en-US/lathe/lathesystem.ftl b/Resources/Locale/en-US/lathe/lathesystem.ftl new file mode 100644 index 0000000000..0b5e538d2c --- /dev/null +++ b/Resources/Locale/en-US/lathe/lathesystem.ftl @@ -0,0 +1 @@ +lathe-popup-material-not-used = This material is not used in this lathe. \ No newline at end of file