public ChemMix TakeMix(float mass) { ChemMix res = new ChemMix(plant); if (Mass == 0) { return(res); } float[] weights = new float[Fractions.Count]; int index = 0; foreach (ChemFraction f in Fractions.Values) { weights[index] = f.Mass / Mass; index++; } float deltaH = Heat * mass / massCache; plant.MaxDeltaH = Mathf.Max(plant.MaxDeltaH, deltaH); index = 0; List <string> toRemove = new List <string>(); foreach (ChemFraction f in Fractions.Values) { ChemFraction target = new ChemFraction(f.Element); TakeFraction(target, mass * weights[index], toRemove); index++; res.AddFraction(target); } foreach (string name in toRemove) { Fractions.Remove(name); } if (!Infinite) { Heat -= Mathf.Min(deltaH, Heat); } res.Heat += deltaH; return(res); }