Migrate Lathe Material Ejection Code to MaterialStorage (#23199)
* SS14-23184 Migrate Lathe Material Ejection Code to MaterialStorage The lathe material ejection code acts as a do-nothing man-in-the-middle system that does work that would be reasonable for any MaterialStorage-using machine to use. This has been fixed by migrating the ejection code to MaterialStorage, allowing anything that uses the system to eject mats it is storing. * Fix some YAML references. Science!!
This commit is contained in:
committed by
GitHub
parent
ec82a05df9
commit
f850047341
@@ -30,6 +30,8 @@ public sealed class MaterialStorageSystem : SharedMaterialStorageSystem
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<MaterialStorageComponent, MachineDeconstructedEvent>(OnDeconstructed);
|
||||
|
||||
SubscribeLocalEvent<MaterialStorageComponent, EjectMaterialMessage>(OnEjectMessage);
|
||||
}
|
||||
|
||||
private void OnDeconstructed(EntityUid uid, MaterialStorageComponent component, MachineDeconstructedEvent args)
|
||||
@@ -43,6 +45,34 @@ public sealed class MaterialStorageSystem : SharedMaterialStorageSystem
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user