int energyRequired = Math.min(getEnergyStoredMax() - getEnergyStored(), getMaxEnergyPerTick());
if (energyRequired > 0)
{
IPowerProvider pp = getPowerProvider();
bcpower: if(pp != null)
{
int mjRequired = energyRequired / energyPerMJ;
if (mjRequired <= 0) break bcpower;
pp.update(this);
if(pp.useEnergy(0, mjRequired, false) > 0)
{
int mjGained = (int)(pp.useEnergy(0, mjRequired, true) * energyPerMJ);
_energyStored += mjGained;
energyRequired -= mjGained;
}
}