using Content.Shared.Lathe;
+using Content.Shared.Materials;
using Content.Shared.Research.Components;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
_menu.OnEjectPressed += (material, sheetsToExtract) =>
{
- SendMessage(new LatheEjectMaterialMessage(material, sheetsToExtract));
+ SendMessage(new EjectMaterialMessage(material, sheetsToExtract));
};
_menu.OpenCentered();
SubscribeLocalEvent<TechnologyDatabaseComponent, LatheGetRecipesEvent>(OnGetRecipes);
SubscribeLocalEvent<EmagLatheRecipesComponent, LatheGetRecipesEvent>(GetEmagLatheRecipes);
SubscribeLocalEvent<LatheHeatProducingComponent, LatheStartPrintingEvent>(OnHeatStartPrinting);
-
- SubscribeLocalEvent<LatheComponent, LatheEjectMaterialMessage>(OnLatheEjectMessage);
- }
-
- private void OnLatheEjectMessage(EntityUid uid, LatheComponent lathe, LatheEjectMaterialMessage message)
- {
- if (!lathe.CanEjectStoredMaterials)
- return;
-
- if (!_proto.TryIndex<MaterialPrototype>(message.Material, out var material))
- return;
-
- var volume = 0;
-
- if (material.StackEntity != null)
- {
- var entProto = _proto.Index<EntityPrototype>(material.StackEntity);
- if (!entProto.TryGetComponent<PhysicalCompositionComponent>(out var composition))
- return;
-
- var volumePerSheet = composition.MaterialComposition.FirstOrDefault(kvp => kvp.Key == message.Material).Value;
- var sheetsToExtract = Math.Min(message.SheetsToExtract, _stack.GetMaxCount(material.StackEntity));
-
- volume = sheetsToExtract * volumePerSheet;
- }
-
- if (volume > 0 && _materialStorage.TryChangeMaterialAmount(uid, message.Material, -volume))
- {
- var mats = _materialStorage.SpawnMultipleFromMaterial(volume, material, Transform(uid).Coordinates, out _);
- foreach (var mat in mats)
- {
- if (TerminatingOrDeleted(mat))
- continue;
- _stack.TryMergeToContacts(mat);
- }
- }
}
public override void Update(float frameTime)
continue;
heatComp.NextSecond += TimeSpan.FromSeconds(1);
- var position = _transform.GetGridTilePositionOrDefault((uid,xform));
+ var position = _transform.GetGridTilePositionOrDefault((uid, xform));
_environments.Clear();
if (_atmosphere.GetTileMixture(xform.GridUid, xform.MapUid, position, true) is { } tileMix)
{
base.Initialize();
SubscribeLocalEvent<MaterialStorageComponent, MachineDeconstructedEvent>(OnDeconstructed);
+
+ SubscribeLocalEvent<MaterialStorageComponent, EjectMaterialMessage>(OnEjectMessage);
}
private void OnDeconstructed(EntityUid uid, MaterialStorageComponent component, MachineDeconstructedEvent args)
}
}
+ private void OnEjectMessage(EntityUid uid, MaterialStorageComponent component, EjectMaterialMessage message)
+ {
+ if (!component.CanEjectStoredMaterials || !_prototypeManager.TryIndex<MaterialPrototype>(message.Material, out var material))
+ return;
+
+ var volume = 0;
+
+ if (material.StackEntity != null)
+ {
+ if (!_prototypeManager.Index<EntityPrototype>(material.StackEntity).TryGetComponent<PhysicalCompositionComponent>(out var composition))
+ return;
+
+ var volumePerSheet = composition.MaterialComposition.FirstOrDefault(kvp => kvp.Key == message.Material).Value;
+ var sheetsToExtract = Math.Min(message.SheetsToExtract, _stackSystem.GetMaxCount(material.StackEntity));
+
+ volume = sheetsToExtract * volumePerSheet;
+ }
+
+ if (volume <= 0 || !TryChangeMaterialAmount(uid, message.Material, -volume))
+ return;
+
+ var mats = SpawnMultipleFromMaterial(volume, material, Transform(uid).Coordinates, out _);
+ foreach (var mat in mats.Where(mat => !TerminatingOrDeleted(mat)))
+ {
+ _stackSystem.TryMergeToContacts(mat);
+ }
+ }
+
public override bool TryInsertMaterialEntity(EntityUid user,
EntityUid toInsert,
EntityUid receiver,
[ViewVariables]
public LatheRecipePrototype? CurrentRecipe;
- /// <summary>
- /// Whether the lathe can eject the materials stored within it
- /// </summary>
- [DataField]
- public bool CanEjectStoredMaterials = true;
-
#region MachineUpgrading
/// <summary>
/// A modifier that changes how long it takes to print a recipe
+++ /dev/null
-using Robust.Shared.Serialization;
-
-namespace Content.Shared.Lathe;
-
-[Serializable, NetSerializable]
-public sealed class LatheEjectMaterialMessage : BoundUserInterfaceMessage
-{
- public string Material;
- public int SheetsToExtract;
-
- public LatheEjectMaterialMessage(string material, int sheetsToExtract)
- {
- Material = material;
- SheetsToExtract = sheetsToExtract;
- }
-}
/// </summary>
[DataField]
public TimeSpan InsertionTime = TimeSpan.FromSeconds(0.79f); // 0.01 off for animation timing
+
+ /// <summary>
+ /// Whether the storage can eject the materials stored within it
+ /// </summary>
+ [DataField]
+ public bool CanEjectStoredMaterials = true;
}
[Serializable, NetSerializable]
public List<ProtoId<MaterialPrototype>> Whitelist = new();
}
+
+/// <summary>
+/// Message sent to try and eject a material from a storage
+/// </summary>
+[Serializable, NetSerializable]
+public sealed class EjectMaterialMessage : BoundUserInterfaceMessage
+{
+ public string Material;
+ public int SheetsToExtract;
+
+ public EjectMaterialMessage(string material, int sheetsToExtract)
+ {
+ Material = material;
+ SheetsToExtract = sheetsToExtract;
+ }
+}
+
- type: MaterialStorage
dropOnDeconstruct: false #should drop ores instead of ingots/sheets
ignoreColor: true
+ canEjectStoredMaterials: false
whitelist:
tags:
- Ore
- type: Lathe
idleState: icon
runningState: building
- canEjectStoredMaterials: false
staticRecipes:
- SheetSteel30
- SheetGlass30
- type: MaterialStorage
dropOnDeconstruct: false #should drop ores instead of ingots/sheets
ignoreColor: true
+ canEjectStoredMaterials: false
whitelist:
tags:
- Raw
- type: Lathe
idleState: base_machine
runningState: base_machine_processing
- canEjectStoredMaterials: false
staticRecipes:
- MaterialSheetMeat
- SheetPaper