Make the material ejection control completely generic (#23308)
* Finish decoupling material ejection from lathes * commented
This commit is contained in:
@@ -105,13 +105,15 @@ public record struct GetMaterialWhitelistEvent(EntityUid Storage)
|
||||
/// Message sent to try and eject a material from a storage
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class EjectMaterialMessage : BoundUserInterfaceMessage
|
||||
public sealed class EjectMaterialMessage : EntityEventArgs
|
||||
{
|
||||
public NetEntity Entity;
|
||||
public string Material;
|
||||
public int SheetsToExtract;
|
||||
|
||||
public EjectMaterialMessage(string material, int sheetsToExtract)
|
||||
public EjectMaterialMessage(NetEntity entity, string material, int sheetsToExtract)
|
||||
{
|
||||
Entity = entity;
|
||||
Material = material;
|
||||
SheetsToExtract = sheetsToExtract;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,11 @@ public abstract class SharedMaterialStorageSystem : EntitySystem
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototype = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Default volume for a sheet if the material's entity prototype has no material composition.
|
||||
/// </summary>
|
||||
private const int DefaultSheetVolume = 100;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -249,4 +254,17 @@ public abstract class SharedMaterialStorageSystem : EntitySystem
|
||||
return;
|
||||
args.Handled = TryInsertMaterialEntity(args.User, args.Used, uid, component);
|
||||
}
|
||||
|
||||
public int GetSheetVolume(MaterialPrototype material)
|
||||
{
|
||||
if (material.StackEntity == null)
|
||||
return DefaultSheetVolume;
|
||||
|
||||
var proto = _prototype.Index<EntityPrototype>(material.StackEntity);
|
||||
|
||||
if (!proto.TryGetComponent<PhysicalCompositionComponent>(out var composition))
|
||||
return DefaultSheetVolume;
|
||||
|
||||
return composition.MaterialComposition.FirstOrDefault(kvp => kvp.Key == material.ID).Value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user