}
}
- public override bool TryInsertMaterialEntity(EntityUid user, EntityUid toInsert, EntityUid receiver, MaterialStorageComponent? component = null)
+ public override bool TryInsertMaterialEntity(EntityUid user,
+ EntityUid toInsert,
+ EntityUid receiver,
+ MaterialStorageComponent? storage = null,
+ MaterialComponent? material = null,
+ PhysicalCompositionComponent? composition = null)
{
- if (!base.TryInsertMaterialEntity(user, toInsert, receiver, component))
+ if (!base.TryInsertMaterialEntity(user, toInsert, receiver, storage, material, composition))
return false;
_transform.DetachParentToNull(toInsert, Transform(toInsert));
return true;
var stackProto = protoManager.Index<StackPrototype>(materialStep.MaterialPrototypeId);
var spawnProto = protoManager.Index<EntityPrototype>(stackProto.Spawn);
- if (!spawnProto.Components.TryGetValue(materialName, out var matreg))
+ if (!spawnProto.Components.ContainsKey(materialName) ||
+ !spawnProto.Components.TryGetValue(compositionName, out var compositionReg))
continue;
- var mat = (MaterialComponent) matreg.Component;
- foreach (var (matId, amount) in mat.Materials)
+ var mat = (PhysicalCompositionComponent) compositionReg.Component;
+ foreach (var (matId, amount) in mat.MaterialComposition)
{
materials[matId] = materialStep.Amount * amount + materials.GetValueOrDefault(matId);
}
var spawnProto = protoManager.Index<EntityPrototype>(key);
// get the amount of each material included in the entity
- if (!spawnProto.Components.TryGetValue(materialName, out var matreg))
+
+ if (!spawnProto.Components.ContainsKey(materialName) ||
+ !spawnProto.Components.TryGetValue(compositionName, out var compositionReg))
continue;
- var mat = (MaterialComponent) matreg.Component;
- foreach (var (matId, amount) in mat.Materials)
+ var mat = (PhysicalCompositionComponent) compositionReg.Component;
+ foreach (var (matId, amount) in mat.MaterialComposition)
{
spawnedMats[matId] = value.Max * amount + spawnedMats.GetValueOrDefault(matId);
}
var spawnProto = protoManager.Index<EntityPrototype>(spawnCompletion.Prototype);
- if (!spawnProto.Components.TryGetValue(materialName, out var matreg))
+ if (!spawnProto.Components.ContainsKey(materialName) ||
+ !spawnProto.Components.TryGetValue(compositionName, out var compositionReg))
continue;
- var mat = (MaterialComponent) matreg.Component;
- foreach (var (matId, amount) in mat.Materials)
+ var mat = (PhysicalCompositionComponent) compositionReg.Component;
+ foreach (var (matId, amount) in mat.MaterialComposition)
{
materials[matId] = spawnCompletion.Amount * amount + materials.GetValueOrDefault(matId);
}
return price;
}
- private double GetMaterialPrice(MaterialComponent component)
+ private double GetMaterialPrice(PhysicalCompositionComponent component)
{
double price = 0;
- foreach (var (id, quantity) in component.Materials)
+ foreach (var (id, quantity) in component.MaterialComposition)
{
price += _prototypeManager.Index<MaterialPrototype>(id).Price * quantity;
}
{
double price = 0;
- if (TryComp<MaterialComponent>(uid, out var material))
+ if (HasComp<MaterialComponent>(uid) &&
+ TryComp<PhysicalCompositionComponent>(uid, out var composition))
{
- var matPrice = GetMaterialPrice(material);
+ var matPrice = GetMaterialPrice(composition);
if (TryComp<StackComponent>(uid, out var stack))
matPrice *= stack.Count;
{
double price = 0;
- if (prototype.Components.TryGetValue(_factory.GetComponentName(typeof(MaterialComponent)), out var materials))
+ if (prototype.Components.ContainsKey(_factory.GetComponentName(typeof(MaterialComponent))) &&
+ prototype.Components.TryGetValue(_factory.GetComponentName(typeof(PhysicalCompositionComponent)), out var composition))
{
- var materialsComp = (MaterialComponent) materials.Component;
- var matPrice = GetMaterialPrice(materialsComp);
+ var compositionComp = (PhysicalCompositionComponent) composition.Component;
+ var matPrice = GetMaterialPrice(compositionComp);
if (prototype.Components.TryGetValue(_factory.GetComponentName(typeof(StackComponent)), out var stackProto))
{
}
}
- public override bool TryInsertMaterialEntity(EntityUid user, EntityUid toInsert, EntityUid receiver, MaterialStorageComponent? component = null)
+ public override bool TryInsertMaterialEntity(EntityUid user,
+ EntityUid toInsert,
+ EntityUid receiver,
+ MaterialStorageComponent? storage = null,
+ MaterialComponent? material = null,
+ PhysicalCompositionComponent? composition = null)
{
- if (!Resolve(receiver, ref component))
+ if (!Resolve(receiver, ref storage) || !Resolve(toInsert, ref material, ref composition, false))
return false;
if (TryComp<ApcPowerReceiverComponent>(receiver, out var power) && !power.Powered)
return false;
- if (!base.TryInsertMaterialEntity(user, toInsert, receiver, component))
+ if (!base.TryInsertMaterialEntity(user, toInsert, receiver, storage, material, composition))
return false;
- _audio.PlayPvs(component.InsertingSound, receiver);
+ _audio.PlayPvs(storage.InsertingSound, receiver);
_popup.PopupEntity(Loc.GetString("machine-insert-item", ("user", user), ("machine", receiver),
("item", toInsert)), receiver);
QueueDel(toInsert);
return new List<EntityUid>();
var entProto = _prototypeManager.Index<EntityPrototype>(materialProto.StackEntity);
- if (!entProto.TryGetComponent<MaterialComponent>(out var material))
+ if (!entProto.TryGetComponent<PhysicalCompositionComponent>(out var composition))
return new List<EntityUid>();
- var materialPerStack = material.Materials[materialProto.ID];
+ var materialPerStack = composition.MaterialComposition[materialProto.ID];
var amountToSpawn = amount / materialPerStack;
overflowMaterial = amount - amountToSpawn * materialPerStack;
return _stackSystem.SpawnMultiple(materialProto.StackEntity, amountToSpawn, coordinates);
using Robust.Shared.GameStates;
-using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
-namespace Content.Shared.Materials
+namespace Content.Shared.Materials;
+/// <summary>
+/// Empty component that marks an entity as a "raw" material.
+/// The material amounts themselves are in <see cref="PhysicalCompositionComponent"/>
+/// </summary>
+[RegisterComponent, NetworkedComponent]
+public sealed class MaterialComponent : Component
{
- /// <summary>
- /// Component to store data such as "this object is made out of steel".
- /// This is not a storage system for say smelteries.
- /// </summary>
- [RegisterComponent, NetworkedComponent]
- public sealed class MaterialComponent : Component
- {
- [DataField("materials", customTypeSerializer:typeof(PrototypeIdDictionarySerializer<int, MaterialPrototype>))]
- public readonly Dictionary<string, int> Materials = new();
- }
+
}
+
public override void Update(float frameTime)
{
base.Update(frameTime);
- foreach (var inserting in EntityQuery<InsertingMaterialStorageComponent>())
+ var query = EntityQueryEnumerator<InsertingMaterialStorageComponent>();
+ while (query.MoveNext(out var uid, out var inserting))
{
if (_timing.CurTime < inserting.EndTime)
continue;
- _appearance.SetData(inserting.Owner, MaterialStorageVisuals.Inserting, false);
- RemComp(inserting.Owner, inserting);
+ _appearance.SetData(uid, MaterialStorageVisuals.Inserting, false);
+ RemComp(uid, inserting);
}
}
/// <summary>
/// Tries to insert an entity into the material storage.
/// </summary>
- /// <param name="user"></param>
- /// <param name="toInsert"></param>
- /// <param name="receiver"></param>
- /// <param name="component"></param>
- /// <returns>If it was successful</returns>
- public virtual bool TryInsertMaterialEntity(EntityUid user, EntityUid toInsert, EntityUid receiver, MaterialStorageComponent? component = null)
+ public virtual bool TryInsertMaterialEntity(EntityUid user,
+ EntityUid toInsert,
+ EntityUid receiver,
+ MaterialStorageComponent? storage = null,
+ MaterialComponent? material = null,
+ PhysicalCompositionComponent? composition = null)
{
- if (!Resolve(receiver, ref component))
+ if (!Resolve(receiver, ref storage))
return false;
- if (!TryComp<MaterialComponent>(toInsert, out var material))
+ if (!Resolve(toInsert, ref material, ref composition, false))
return false;
- if (component.EntityWhitelist?.IsValid(toInsert) == false)
+ if (storage.EntityWhitelist?.IsValid(toInsert) == false)
return false;
// Material Whitelist checked implicitly by CanChangeMaterialAmount();
var multiplier = TryComp<StackComponent>(toInsert, out var stackComponent) ? stackComponent.Count : 1;
var totalVolume = 0;
- foreach (var (mat, vol) in material.Materials)
+ foreach (var (mat, vol) in composition.MaterialComposition)
{
- if (!CanChangeMaterialAmount(receiver, mat, vol * multiplier, component))
+ if (!CanChangeMaterialAmount(receiver, mat, vol * multiplier, storage))
return false;
totalVolume += vol * multiplier;
}
- if (!CanTakeVolume(receiver, totalVolume, component))
+ if (!CanTakeVolume(receiver, totalVolume, storage))
return false;
- foreach (var (mat, vol) in material.Materials)
+ foreach (var (mat, vol) in composition.MaterialComposition)
{
- TryChangeMaterialAmount(receiver, mat, vol * multiplier, component);
+ TryChangeMaterialAmount(receiver, mat, vol * multiplier, storage);
}
var insertingComp = EnsureComp<InsertingMaterialStorageComponent>(receiver);
- insertingComp.EndTime = _timing.CurTime + component.InsertionTime;
- if (!component.IgnoreColor)
+ insertingComp.EndTime = _timing.CurTime + storage.InsertionTime;
+ if (!storage.IgnoreColor)
{
- _prototype.TryIndex<MaterialPrototype>(material.Materials.Keys.Last(), out var lastMat);
+ _prototype.TryIndex<MaterialPrototype>(composition.MaterialComposition.Keys.First(), out var lastMat);
insertingComp.MaterialColor = lastMat?.Color;
}
_appearance.SetData(receiver, MaterialStorageVisuals.Inserting, true);
Dirty(insertingComp);
var ev = new MaterialEntityInsertedEvent(material);
- RaiseLocalEvent(component.Owner, ref ev);
+ RaiseLocalEvent(receiver, ref ev);
return true;
}
suffix: Full
components:
- type: Material
- materials:
+ - type: PhysicalComposition
+ materialComposition:
Glass: 100
- type: Stack
stackType: Glass
suffix: Full
components:
- type: Material
- materials:
+ - type: PhysicalComposition
+ materialComposition:
ReinforcedGlass: 100
- type: Stack
stackType: ReinforcedGlass
suffix: Full
components:
- type: Material
- materials:
+ - type: PhysicalComposition
+ materialComposition:
PlasmaGlass: 100
- type: Stack
stackType: PlasmaGlass
suffix: Full
components:
- type: Material
- materials:
+ - type: PhysicalComposition
+ materialComposition:
ReinforcedPlasmaGlass: 100
- type: Stack
stackType: ReinforcedPlasmaGlass
suffix: Full
components:
- type: Material
- materials:
+ - type: PhysicalComposition
+ materialComposition:
Steel: 100
- type: Stack
stackType: Steel
suffix: Full
components:
- type: Material
- materials:
+ - type: PhysicalComposition
+ materialComposition:
Plasteel: 100
- type: Stack
stackType: Plasteel
suffix: Full
components:
- type: Material
- materials:
+ - type: PhysicalComposition
+ materialComposition:
Plasma: 100
- type: Stack
stackType: Plasma
- Sheet
- DroneUsable
- type: Material
- materials:
+ - type: PhysicalComposition
+ materialComposition:
Plastic: 100
- type: Stack
stackType: Plastic
suffix: Full
components:
- type: Material
- materials:
+ - type: PhysicalComposition
+ materialComposition:
Uranium: 100
- type: Stack
stackType: Uranium
suffix: Full
components:
- type: Material
- materials:
+ - type: PhysicalComposition
+ materialComposition:
Gold: 100
- type: Stack
stackType: Gold
suffix: Full
components:
- type: Material
- materials:
+ - type: PhysicalComposition
+ materialComposition:
Silver: 100
- type: Stack
stackType: Silver
suffix: Full
components:
- type: Material
- materials:
+ - type: PhysicalComposition
+ materialComposition:
Cardboard: 100
- type: Stack
stackType: Cardboard
- type: Stack
stackType: Cloth
- type: Material
- materials:
+ - type: PhysicalComposition
+ materialComposition:
Cloth: 100
- type: Extractable
juiceSolution:
- type: Stack
stackType: Durathread
- type: Material
- materials:
+ - type: PhysicalComposition
+ materialComposition:
Durathread: 100
- type: Sprite
state: durathread_3
suffix: Full
components:
- type: Material
- materials:
+ - type: PhysicalComposition
+ materialComposition:
Wood: 100
- type: Stack
stackType: WoodPlank
suffix: Full
components:
- type: Material
- materials:
+ - type: PhysicalComposition
+ materialComposition:
Biomass: 1
- type: Stack
stackType: Biomass
- type: Sprite
state: gold
- type: Material
- materials:
+ - type: PhysicalComposition
+ materialComposition:
Gold: 500
- type: entity
- type: Sprite
state: iron
- type: Material
- materials:
+ - type: PhysicalComposition
+ materialComposition:
Steel: 500
- type: entity
- type: Sprite
state: plasma
- type: Material
- materials:
+ - type: PhysicalComposition
+ materialComposition:
Plasma: 500
- type: entity
- type: Sprite
state: silver
- type: Material
- materials:
+ - type: PhysicalComposition
+ materialComposition:
Silver: 500
- type: entity
- type: Sprite
state: spacequartz
- type: Material
- materials:
+ - type: PhysicalComposition
+ materialComposition:
Glass: 500
- type: entity
- type: Sprite
state: uranium
- type: Material
- materials:
+ - type: PhysicalComposition
+ materialComposition:
Uranium: 500
- type: entity
description: You gotta have money.
components:
- type: Material
- materials:
+ - type: PhysicalComposition
+ materialComposition:
Credit: 1
- type: StaticPrice
price: 0